diff options
Diffstat (limited to 'transform/allocs.go')
-rw-r--r-- | transform/allocs.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/transform/allocs.go b/transform/allocs.go index 4f006c3a9..f21dde123 100644 --- a/transform/allocs.go +++ b/transform/allocs.go @@ -69,8 +69,13 @@ func OptimizeAllocs(mod llvm.Module) { sizeInWords := (size + uint64(alignment) - 1) / uint64(alignment) allocaType := llvm.ArrayType(mod.Context().IntType(alignment*8), int(sizeInWords)) alloca := builder.CreateAlloca(allocaType, "stackalloc.alloca") + + // Zero the allocation inside the block where the value was originally allocated. zero := llvm.ConstNull(alloca.Type().ElementType()) + builder.SetInsertPointBefore(bitcast) builder.CreateStore(zero, alloca) + + // Replace heap alloc bitcast with stack alloc bitcast. stackalloc := builder.CreateBitCast(alloca, bitcast.Type(), "stackalloc") bitcast.ReplaceAllUsesWith(stackalloc) if heapalloc != bitcast { |