[llvm] r354844 - [WebAssembly] Fix a bug deleting instruction in a ranged for loop
Heejin Ahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 25 20:08:49 PST 2019
Author: aheejin
Date: Mon Feb 25 20:08:49 2019
New Revision: 354844
URL: http://llvm.org/viewvc/llvm-project?rev=354844&view=rev
Log:
[WebAssembly] Fix a bug deleting instruction in a ranged for loop
Summary: We shouldn't delete elements while iterating a ranged for loop.
Reviewers: dschuff
Subscribers: sbc100, jgravelle-google, sunfish, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58519
Modified:
llvm/trunk/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
llvm/trunk/test/CodeGen/WebAssembly/exception.ll
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp?rev=354844&r1=354843&r2=354844&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp Mon Feb 25 20:08:49 2019
@@ -222,18 +222,22 @@ bool WebAssemblyLateEHPrepare::addExcept
const auto &TII = *MF.getSubtarget<WebAssemblySubtarget>().getInstrInfo();
auto *EHInfo = MF.getWasmEHFuncInfo();
SmallVector<MachineInstr *, 16> ExtractInstrs;
+ SmallVector<MachineInstr *, 8> ToDelete;
for (auto &MBB : MF) {
for (auto &MI : MBB) {
if (MI.getOpcode() == WebAssembly::EXTRACT_EXCEPTION_I32) {
if (MI.getOperand(0).isDead())
- MI.eraseFromParent();
+ ToDelete.push_back(&MI);
else
ExtractInstrs.push_back(&MI);
}
}
}
+ bool Changed = !ToDelete.empty() || !ExtractInstrs.empty();
+ for (auto *MI : ToDelete)
+ MI->eraseFromParent();
if (ExtractInstrs.empty())
- return false;
+ return Changed;
// Find terminate pads.
SmallSet<MachineBasicBlock *, 8> TerminatePads;
Modified: llvm/trunk/test/CodeGen/WebAssembly/exception.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/exception.ll?rev=354844&r1=354843&r2=354844&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/exception.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/exception.ll Mon Feb 25 20:08:49 2019
@@ -340,6 +340,26 @@ try.cont:
ret void
}
+; When the result of @llvm.wasm.get.exception is not used. This is created to
+; fix a bug in LateEHPrepare and this should not crash.
+define void @test_get_exception_wo_use() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
+entry:
+ invoke void @foo()
+ to label %try.cont unwind label %catch.dispatch
+
+catch.dispatch: ; preds = %entry
+ %0 = catchswitch within none [label %catch.start] unwind to caller
+
+catch.start: ; preds = %catch.dispatch
+ %1 = catchpad within %0 [i8* null]
+ %2 = call i8* @llvm.wasm.get.exception(token %1)
+ %3 = call i32 @llvm.wasm.get.ehselector(token %1)
+ catchret from %1 to label %try.cont
+
+try.cont: ; preds = %entry, %catch.start
+ ret void
+}
+
declare void @foo()
declare void @bar(i32*)
declare i32 @__gxx_wasm_personality_v0(...)
More information about the llvm-commits
mailing list