cl: function fix freevars cache

This commit is contained in:
visualfc
2024-09-06 15:45:49 +08:00
parent 32f41a04ac
commit d2ffbd0395
3 changed files with 139 additions and 1 deletions

View File

@@ -257,7 +257,14 @@ func (p Function) closureCtx(b Builder) Expr {
panic("ssa: function has no free variables")
}
ptr := Expr{p.impl.Param(0), p.params[0]}
p.freeVars = b.Load(ptr)
if b.blk.Index() != 0 {
blk := b.impl.GetInsertBlock()
b.SetBlockEx(p.blks[0], AtStart, false)
p.freeVars = b.Load(ptr)
b.impl.SetInsertPointAtEnd(blk)
} else {
p.freeVars = b.Load(ptr)
}
}
return p.freeVars
}