compiler: disallow exporting functions that have their address taken

This simplifies the ABI a lot and makes future changes easier.
In the future, determining which functions need a context parameter
should be moved from IR generation into an optimization pass, avoiding
the need for recursively scanning the Go SSA.
This commit is contained in:
Ayke van Laethem
2018-12-01 17:31:36 +01:00
parent da0a02d128
commit e54a1c4dc0
2 changed files with 3 additions and 17 deletions
+3
View File
@@ -2280,6 +2280,9 @@ func (c *Compiler) parseExpr(frame *Frame, expr ssa.Value) (llvm.Value, error) {
return c.builder.CreateGEP(val, indices, ""), nil
case *ssa.Function:
fn := c.ir.GetFunction(expr)
if fn.IsExported() {
return llvm.Value{}, c.makeError(expr.Pos(), "cannot use an exported function as value")
}
ptr := fn.LLVMFn
if c.ir.FunctionNeedsContext(fn) {
// Create closure for function pointer.