diff --git a/cl/_testrt/intgen/out.ll b/cl/_testrt/intgen/out.ll index 8be54dfd..54f38550 100644 --- a/cl/_testrt/intgen/out.ll +++ b/cl/_testrt/intgen/out.ll @@ -50,7 +50,7 @@ _llgo_0: call void @main.init() %0 = alloca { ptr, ptr }, align 8 %1 = getelementptr inbounds { ptr, ptr }, ptr %0, i32 0, i32 0 - store ptr @main.Rand, ptr %1, align 8 + store ptr @rand, ptr %1, align 8 %2 = getelementptr inbounds { ptr, ptr }, ptr %0, i32 0, i32 1 store ptr null, ptr %2, align 8 %3 = load { ptr, ptr }, ptr %0, align 8 @@ -85,6 +85,6 @@ declare ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/go declare void @"github.com/goplus/llgo/internal/runtime.init"() -declare i32 @main.Rand() +declare i32 @rand() declare i32 @printf(ptr, ...) diff --git a/cl/builtin_test.go b/cl/builtin_test.go index 4eb7ded8..e09aab97 100644 --- a/cl/builtin_test.go +++ b/cl/builtin_test.go @@ -25,6 +25,25 @@ import ( "golang.org/x/tools/go/ssa" ) +func TestErrCompileValue(t *testing.T) { + defer func() { + if r := recover(); r != "can't use llgo instruction as a value" { + t.Fatal("TestErrCompileValue:", r) + } + }() + pkg := types.NewPackage("foo", "foo") + ctx := &context{ + goTyps: pkg, + link: map[string]string{ + "foo.": "llgo.unreachable", + }, + } + ctx.compileValue(nil, &ssa.Function{ + Pkg: &ssa.Package{Pkg: pkg}, + Signature: types.NewSignatureType(nil, nil, nil, nil, nil, false), + }) +} + func TestErrCompileInstrOrValue(t *testing.T) { defer func() { if r := recover(); r == nil { diff --git a/cl/compile.go b/cl/compile.go index 95dcb029..26f55ebd 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -602,15 +602,15 @@ func (p *context) compileValue(b llssa.Builder, v ssa.Value) llssa.Expr { } } case *ssa.Function: - fn := p.compileFunc(p.pkg, p.goTyps, v, true) - return fn.Expr - /* - fn, ftype := p.funcOf(v) - if ftype >= llgoInstrBase { - panic("can't use llgo instruction as a value") - } + if v.Blocks != nil { + fn := p.compileFunc(p.pkg, p.goTyps, v, true) return fn.Expr - */ + } + fn, ftype := p.funcOf(v) + if ftype >= llgoInstrBase { + panic("can't use llgo instruction as a value") + } + return fn.Expr case *ssa.Global: g := p.varOf(v) return g.Expr