cl: isVargs support defer/go

This commit is contained in:
xushiwei
2024-06-11 10:35:27 +08:00
parent 1ecd9af2e1
commit 5e5d149ca5
6 changed files with 213 additions and 8 deletions

View File

@@ -21,11 +21,42 @@ import (
"go/constant"
"go/types"
"testing"
"unsafe"
llssa "github.com/goplus/llgo/ssa"
"golang.org/x/tools/go/ssa"
)
func TestIsVargs(t *testing.T) {
if isVargs(nil, ssaAlloc(&ssa.Return{})) {
t.Fatal("isVargs?")
}
if isVargs(nil, ssaAlloc(ssaSlice(&ssa.Go{}))) {
t.Fatal("isVargs?")
}
if isVargs(nil, ssaAlloc(ssaSlice(&ssa.Return{}))) {
t.Fatal("isVargs?")
}
}
func ssaSlice(refs ...ssa.Instruction) *ssa.Slice {
a := &ssa.Slice{}
setRefs(unsafe.Pointer(a), refs...)
return a
}
func ssaAlloc(refs ...ssa.Instruction) *ssa.Alloc {
a := &ssa.Alloc{}
setRefs(unsafe.Pointer(a), refs...)
return a
}
func setRefs(v unsafe.Pointer, refs ...ssa.Instruction) {
off := unsafe.Offsetof(ssa.Alloc{}.Comment) - unsafe.Sizeof([]int(nil))
ptr := uintptr(v) + off
*(*[]ssa.Instruction)(unsafe.Pointer(ptr)) = refs
}
func TestRecvTypeName(t *testing.T) {
if ret := recvTypeName(&ast.IndexExpr{
X: &ast.Ident{Name: "Pointer"},