diff --git a/cl/_testlibc/sqlite/in.go b/cl/_testlibc/sqlite/in.go new file mode 100644 index 00000000..b9db5a37 --- /dev/null +++ b/cl/_testlibc/sqlite/in.go @@ -0,0 +1,20 @@ +package main + +import ( + "github.com/goplus/llgo/c" + "github.com/goplus/llgo/x/sqlite" +) + +func main() { + db, err := sqlite.OpenV2(c.Str(":memory:"), sqlite.OpenReadWrite|sqlite.OpenMemory, nil) + check(err) + + db.Close() +} + +func check(err sqlite.Errno) { + if err != sqlite.OK { + c.Printf(c.Str("==> Error: (%d) %s\n"), err, err.Errstr()) + c.Exit(1) + } +} diff --git a/cl/_testlibc/sqlite/out.ll b/cl/_testlibc/sqlite/out.ll new file mode 100644 index 00000000..339ca048 --- /dev/null +++ b/cl/_testlibc/sqlite/out.ll @@ -0,0 +1,62 @@ +; ModuleID = 'main' +source_filename = "main" + +@"main.init$guard" = global ptr null +@0 = private unnamed_addr constant [20 x i8] c"==> Error: (%d) %s\0A\00", align 1 +@__llgo_argc = global ptr null +@__llgo_argv = global ptr null +@1 = private unnamed_addr constant [9 x i8] c":memory:\00", align 1 + +define void @main.check(i32 %0) { +_llgo_0: + %1 = icmp ne i32 %0, 0 + br i1 %1, label %_llgo_1, label %_llgo_2 + +_llgo_1: ; preds = %_llgo_0 + %2 = call ptr @sqlite3_errstr() + %3 = call i32 (ptr, ...) @printf(ptr @0, i32 %0, ptr %2) + call void @exit(i32 1) + br label %_llgo_2 + +_llgo_2: ; preds = %_llgo_1, %_llgo_0 + ret void +} + +define void @main.init() { +_llgo_0: + %0 = load i1, ptr @"main.init$guard", align 1 + br i1 %0, label %_llgo_2, label %_llgo_1 + +_llgo_1: ; preds = %_llgo_0 + store i1 true, ptr @"main.init$guard", align 1 + br label %_llgo_2 + +_llgo_2: ; preds = %_llgo_1, %_llgo_0 + ret void +} + +define void @main(i32 %0, ptr %1) { +_llgo_0: + store i32 %0, ptr @__llgo_argc, align 4 + store ptr %1, ptr @__llgo_argv, align 8 + call void @"github.com/goplus/llgo/internal/runtime.init"() + call void @main.init() + %2 = call { ptr, i32 } @"github.com/goplus/llgo/x/sqlite.OpenV2"(ptr @1, i32 130, ptr null) + %3 = extractvalue { ptr, i32 } %2, 0 + %4 = extractvalue { ptr, i32 } %2, 1 + call void @main.check(i32 %4) + %5 = call i32 @sqlite3_close() + ret void +} + +declare ptr @sqlite3_errstr() + +declare i32 @printf(ptr, ...) + +declare void @exit(i32) + +declare void @"github.com/goplus/llgo/internal/runtime.init"() + +declare { ptr, i32 } @"github.com/goplus/llgo/x/sqlite.OpenV2"(ptr, i32, ptr) + +declare i32 @sqlite3_close() diff --git a/cl/builtin_test.go b/cl/builtin_test.go index 9c38f97c..8d26552f 100644 --- a/cl/builtin_test.go +++ b/cl/builtin_test.go @@ -17,6 +17,7 @@ package cl import ( + "go/ast" "go/constant" "go/types" "testing" @@ -25,6 +26,27 @@ import ( "golang.org/x/tools/go/ssa" ) +func TestRecvTypeName(t *testing.T) { + if ret := recvTypeName(&ast.IndexExpr{ + X: &ast.Ident{Name: "Pointer"}, + Index: &ast.Ident{Name: "T"}, + }); ret != "Pointer" { + t.Fatal("recvTypeName IndexExpr:", ret) + } + if ret := recvTypeName(&ast.IndexListExpr{ + X: &ast.Ident{Name: "Pointer"}, + Indices: []ast.Expr{&ast.Ident{Name: "T"}}, + }); ret != "Pointer" { + t.Fatal("recvTypeName IndexListExpr:", ret) + } + defer func() { + if r := recover(); r == nil { + t.Fatal("recvTypeName: no error?") + } + }() + recvTypeName(&ast.BadExpr{}) +} + /* func TestErrCompileValue(t *testing.T) { defer func() { diff --git a/cl/import.go b/cl/import.go index b264c542..299e553c 100644 --- a/cl/import.go +++ b/cl/import.go @@ -172,10 +172,7 @@ func (p *context) initLinknameByDoc(doc *ast.CommentGroup, fullName, inPkgName s if n := len(doc.List); n > 0 { line := doc.List[n-1].Text p.initLinkname(line, func(name string) (_ string, _, ok bool) { - if name == inPkgName { - return fullName, isVar, true - } - return + return fullName, isVar, name == inPkgName }) } }