aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-04-09 14:46:19 +0200
committerRon Evans <[email protected]>2021-04-12 08:11:28 +0200
commit2fd8f103ab61b8306025b91a8892c7608330b9e0 (patch)
tree6ab74b6adc804cb31b31d218d1daabdc4f07b1ed
parent33f76d1c2e914bd477bb19060670ae5c3608cf41 (diff)
downloadtinygo-2fd8f103ab61b8306025b91a8892c7608330b9e0.tar.gz
tinygo-2fd8f103ab61b8306025b91a8892c7608330b9e0.zip
transform: fix func lowering assertion failure
The func-lowering pass has started to fail in the dev branch, probably as a result of replacing the ConstPropagation pass with the IPSCCP pass. This commit makes the code a bit more robust and should be able to handle all possible cases (not just ptrtoint).
-rw-r--r--transform/func-lowering.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/transform/func-lowering.go b/transform/func-lowering.go
index 89c9f6928..02341a83b 100644
--- a/transform/func-lowering.go
+++ b/transform/func-lowering.go
@@ -118,12 +118,18 @@ func LowerFuncValues(mod llvm.Module) {
continue
}
for _, funcValueWithSignatureGlobal := range getUses(funcValueWithSignatureConstant) {
+ id := llvm.ConstInt(uintptrType, uint64(fn.id), false)
for _, use := range getUses(funcValueWithSignatureGlobal) {
- if ptrtoint.IsAConstantExpr().IsNil() || ptrtoint.Opcode() != llvm.PtrToInt {
- panic("expected const ptrtoint")
+ // Try to replace uses directly: most will be
+ // ptrtoint instructions.
+ if !use.IsAConstantExpr().IsNil() && use.Opcode() == llvm.PtrToInt {
+ use.ReplaceAllUsesWith(id)
}
- use.ReplaceAllUsesWith(llvm.ConstInt(uintptrType, uint64(fn.id), false))
}
+ // Remaining uses can be replaced using a ptrtoint.
+ // In my quick testing, this doesn't really happen in
+ // practice.
+ funcValueWithSignatureGlobal.ReplaceAllUsesWith(llvm.ConstIntToPtr(id, funcValueWithSignatureGlobal.Type()))
}
}
}