mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
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:
committed by
Ron Evans
parent
98e70c9b19
commit
ab47cea055
Vendored
+8
@@ -20,6 +20,10 @@ define i8* @needsStackSlots() {
|
||||
; so tracking it is not really necessary.
|
||||
%ptr = call i8* @runtime.alloc(i32 4)
|
||||
call void @runtime.trackPointer(i8* %ptr)
|
||||
; Restoring the stack pointer can happen at this position, before the return.
|
||||
; This avoids issues with tail calls.
|
||||
call void @someArbitraryFunction()
|
||||
%val = load i8, i8* @someGlobal
|
||||
ret i8* %ptr
|
||||
}
|
||||
|
||||
@@ -95,3 +99,7 @@ define void @testGEPBitcast() {
|
||||
call void @runtime.trackPointer(i8* %other)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @someArbitraryFunction() {
|
||||
ret void
|
||||
}
|
||||
|
||||
+7
-1
@@ -26,6 +26,8 @@ define i8* @needsStackSlots() {
|
||||
%4 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 2
|
||||
store i8* %ptr, i8** %4
|
||||
store %runtime.stackChainObject* %1, %runtime.stackChainObject** @runtime.stackChainStart
|
||||
call void @someArbitraryFunction()
|
||||
%val = load i8, i8* @someGlobal
|
||||
ret i8* %ptr
|
||||
}
|
||||
|
||||
@@ -73,8 +75,8 @@ define i8* @fibNext(i8* %x, i8* %y) {
|
||||
%out.alloc = call i8* @runtime.alloc(i32 1)
|
||||
%4 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 2
|
||||
store i8* %out.alloc, i8** %4
|
||||
store i8 %out.val, i8* %out.alloc
|
||||
store %runtime.stackChainObject* %1, %runtime.stackChainObject** @runtime.stackChainStart
|
||||
store i8 %out.val, i8* %out.alloc
|
||||
ret i8* %out.alloc
|
||||
}
|
||||
|
||||
@@ -135,3 +137,7 @@ define void @testGEPBitcast() {
|
||||
store %runtime.stackChainObject* %1, %runtime.stackChainObject** @runtime.stackChainStart
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @someArbitraryFunction() {
|
||||
ret void
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user