tinygo/0015-transform-fix-memory-corruption-issues.patch
2022-10-24 05:50:05 -04:00

31 lines
1.2 KiB
Diff

From 6bf7aa1623b6d7d9a269df876453af22b1c54c2d Mon Sep 17 00:00:00 2001
From: Ayke van Laethem <aykevanlaethem@gmail.com>
Date: Wed, 12 Oct 2022 21:46:50 +0200
Subject: [PATCH 15/18] transform: fix memory corruption issues
There was a bug in the wasm ABI lowering pass (found using
AddressSanitizer on LLVM 15) that resulted in a rather subtle memory
corruption. This commit fixes this issues.
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
transform/wasm-abi.go | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/transform/wasm-abi.go b/transform/wasm-abi.go
index 83a16d85..08122a3e 100644
--- a/transform/wasm-abi.go
+++ b/transform/wasm-abi.go
@@ -88,8 +88,7 @@ func ExternalInt64AsPtr(mod llvm.Module, config *compileopts.Config) error {
// Update all users to call the external function.
// The old $i64wrapper function could be removed, but it may as well
// be left in place.
- for use := fn.FirstUse(); !use.IsNil(); use = use.NextUse() {
- call := use.User()
+ for _, call := range getUses(fn) {
entryBlockBuilder.SetInsertPointBefore(call.InstructionParent().Parent().EntryBasicBlock().FirstInstruction())
builder.SetInsertPointBefore(call)
callParams := []llvm.Value{}
--
2.36.1