transform: improve GC stack slot pass to work around a bug

Bug 1790 ("musttail call must precede a ret with an optional bitcast")
is caused by the GC stack slot pass inserting a store instruction
between a musttail call and a return instruction. This is not allowed in
LLVM IR.

One solution would be to remove the musttail. That would probably work,
but 1) the go-llvm API doesn't support this and 2) this might have
unforeseen consequences. What I've done in this commit is to move the
store instruction to a position earlier in the basic block, just after
the last access to the GC stack slot alloca.

Thanks to @fgsch for a very small repro, which I've used as a regression
test.
This commit is contained in:
Ayke van Laethem
2021-07-31 19:17:07 +02:00
committed by Ron Evans
parent 98e70c9b19
commit ab47cea055
4 changed files with 61 additions and 3 deletions
+12
View File
@@ -76,6 +76,8 @@ func main() {
testGoOnBuiltins()
testCond()
testIssue1790()
}
func acquire(m *sync.Mutex) {
@@ -198,3 +200,13 @@ func testCond() {
panic("missing queued notification")
}
}
var once sync.Once
// This tests a fix for issue 1790:
// https://github.com/tinygo-org/tinygo/issues/1790
func testIssue1790() *int {
once.Do(func() {})
i := 0
return &i
}