From 09db7ead50ad86c2738f4006735a0dab9b97fbb8 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 20 Apr 2019 02:42:13 +0200 Subject: [PATCH] cgo: better error message when using an undefined CGo function pointer --- compiler/compiler.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/compiler.go b/compiler/compiler.go index e863508d..4c686556 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -2576,6 +2576,9 @@ func (c *Compiler) parseUnOp(frame *Frame, unop *ssa.UnOp) (llvm.Value, error) { global := c.ir.GetGlobal(unop.X.(*ssa.Global)) name := global.LinkName()[:len(global.LinkName())-len("$funcaddr")] fn := c.mod.NamedFunction(name) + if fn.IsNil() { + return llvm.Value{}, c.makeError(unop.Pos(), "cgo function not found: "+name) + } return c.builder.CreateBitCast(fn, c.i8ptrType, ""), nil } else { c.emitNilCheck(frame, x, "deref")