fix miscompile of static goroutine calls to closures

This commit is contained in:
Jaden Weiss
2019-10-18 19:19:46 -04:00
committed by Ayke
parent 923a6f5873
commit 86ab03c999
5 changed files with 42 additions and 14 deletions
+9 -1
View File
@@ -98,6 +98,10 @@ func (c *Compiler) LowerFuncValues() {
continue
}
for _, funcValueWithSignatureConstant := range getUses(ptrtoint) {
if !funcValueWithSignatureConstant.IsACallInst().IsNil() && funcValueWithSignatureConstant.CalledValue().Name() == "runtime.makeGoroutine" {
// makeGoroutine calls are handled seperately
continue
}
for _, funcValueWithSignatureGlobal := range getUses(funcValueWithSignatureConstant) {
for _, use := range getUses(funcValueWithSignatureGlobal) {
if ptrtoint.IsAConstantExpr().IsNil() || ptrtoint.Opcode() != llvm.PtrToInt {
@@ -182,7 +186,11 @@ func (c *Compiler) LowerFuncValues() {
panic("expected a inttoptr")
}
for _, use := range getUses(inttoptr) {
c.addFuncLoweringSwitch(funcID, use, c.emitStartGoroutine, functions)
c.addFuncLoweringSwitch(funcID, use, func(funcPtr llvm.Value, params []llvm.Value) llvm.Value {
// The function lowering switch code passes in a parent handle value.
// Strip the parent handle off here because it is irrelevant to goroutine starts.
return c.emitStartGoroutine(funcPtr, params[:len(params)-1])
}, functions)
use.EraseFromParentAsInstruction()
}
inttoptr.EraseFromParentAsInstruction()