diff --git a/compiler/optimizer.go b/compiler/optimizer.go index b194e388..b1b81d39 100644 --- a/compiler/optimizer.go +++ b/compiler/optimizer.go @@ -219,6 +219,16 @@ func (c *Compiler) doesEscape(value llvm.Value) bool { // Call only escapes when the (pointer) parameter is not marked // "nocapture". This flag means that the parameter does not escape // the give function. + if use.CalledValue().IsAFunction() != nilValue { + if use.CalledValue().IsDeclaration() { + // Kind of dirty: assume external functions don't let + // pointers escape. + // TODO: introduce //go:noescape that sets the 'nocapture' + // flag on each input parameter. + println("declaration:", use.CalledValue().Name()) + continue + } + } if !c.hasFlag(use, value, "nocapture") { return true }