mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-11 14:33:41 +00:00
transform: do not lower zero-sized alloc to alloca
The LLVM CoroFrame pass appears to be tripping over this zero-sized alloca. Therefore, do what the runtime would do: return a pointer to runtime.zeroSizedAlloc. Or just don't deal with this case. But don't emit a zero sized alloca to avoid this LLVM bug. More information: https://bugs.llvm.org/show_bug.cgi?id=49916
This commit is contained in:
committed by
Ron Evans
parent
2fd8f103ab
commit
e7a05b6e74
@@ -43,6 +43,18 @@ func OptimizeAllocs(mod llvm.Module) {
|
||||
continue
|
||||
}
|
||||
|
||||
if size == 0 {
|
||||
// If the size is 0, the pointer is allowed to alias other
|
||||
// zero-sized pointers. Use the pointer to the global that would
|
||||
// also be returned by runtime.alloc.
|
||||
zeroSizedAlloc := mod.NamedGlobal("runtime.zeroSizedAlloc")
|
||||
if !zeroSizedAlloc.IsNil() {
|
||||
heapalloc.ReplaceAllUsesWith(zeroSizedAlloc)
|
||||
heapalloc.EraseFromParentAsInstruction()
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// In general the pattern is:
|
||||
// %0 = call i8* @runtime.alloc(i32 %size)
|
||||
// %1 = bitcast i8* %0 to type*
|
||||
|
||||
Reference in New Issue
Block a user