aboutsummaryrefslogtreecommitdiffhomepage
path: root/transform/allocs.go
diff options
context:
space:
mode:
authorJaden Weiss <[email protected]>2019-11-13 10:05:01 -0500
committerAyke <[email protected]>2019-11-13 16:45:09 +0100
commit93961f9d411d28c7acae5f556ffdabc4b3b6871e (patch)
tree49dfc743a91463b32b7c38dc2ac8efb38e3dca9b /transform/allocs.go
parentacdaaa17d8232989d310292a512e70fccdb288a5 (diff)
downloadtinygo-93961f9d411d28c7acae5f556ffdabc4b3b6871e.tar.gz
tinygo-93961f9d411d28c7acae5f556ffdabc4b3b6871e.zip
fix incorrect starting value for optimized allocations in a loop
Diffstat (limited to 'transform/allocs.go')
-rw-r--r--transform/allocs.go5
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 {