Skip to content

Commit 09db7ea

Browse files
aykevldeadprogram
authored andcommitted
cgo: better error message when using an undefined CGo function pointer
1 parent 21a4c14 commit 09db7ea

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

compiler/compiler.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,6 +2576,9 @@ func (c *Compiler) parseUnOp(frame *Frame, unop *ssa.UnOp) (llvm.Value, error) {
25762576
global := c.ir.GetGlobal(unop.X.(*ssa.Global))
25772577
name := global.LinkName()[:len(global.LinkName())-len("$funcaddr")]
25782578
fn := c.mod.NamedFunction(name)
2579+
if fn.IsNil() {
2580+
return llvm.Value{}, c.makeError(unop.Pos(), "cgo function not found: "+name)
2581+
}
25792582
return c.builder.CreateBitCast(fn, c.i8ptrType, ""), nil
25802583
} else {
25812584
c.emitNilCheck(frame, x, "deref")

0 commit comments

Comments
 (0)