mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-08 04:53:42 +00:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user