From d435fc868b9caef76b7a9b30a9c33adc3a79cab4 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Wed, 12 Oct 2022 21:46:50 +0200 Subject: [PATCH] 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. --- 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{}