Skip to content

Commit dcfec27

Browse files
committed
[WebAssembly] Handle empty cleanuppads when adding catch_all
In `LateEHPrepare::addCatchAlls`, the current code tries to get the iterator's debug info even when it is `MachineBasicBlock::end()`. This fixes the bug by adding empty debug info instead in that case. Reviewed By: tlively Differential Revision: https://reviews.llvm.org/D97679
1 parent 82289aa commit dcfec27

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ bool WebAssemblyLateEHPrepare::addCatchAlls(MachineFunction &MF) {
216216
if (InsertPos == MBB.end() ||
217217
!WebAssembly::isCatch(InsertPos->getOpcode())) {
218218
Changed = true;
219-
BuildMI(MBB, InsertPos, InsertPos->getDebugLoc(),
219+
BuildMI(MBB, InsertPos,
220+
InsertPos == MBB.end() ? DebugLoc() : InsertPos->getDebugLoc(),
220221
TII.get(WebAssembly::CATCH_ALL));
221222
}
222223
}

llvm/test/CodeGen/WebAssembly/exception.mir

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
define void @unreachable_ehpad_test() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
1313
ret void
1414
}
15+
define void @empty_cleanuppad_test() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
16+
ret void
17+
}
1518
...
1619

1720
---
@@ -81,3 +84,30 @@ body: |
8184
; predecessors: %bb.0, %bb.1
8285
RETURN implicit-def dead $arguments
8386
...
87+
88+
---
89+
# Regression test for a bug that LateEHPrepare::addCatchAll didn't handle empty
90+
# cleanup pads. (It tried to get debug info from end() iterator.)
91+
name: empty_cleanuppad_test
92+
liveins:
93+
- { reg: '$arguments' }
94+
body: |
95+
bb.0:
96+
successors: %bb.1, %bb.3
97+
EH_LABEL <mcsymbol .Ltmp0>
98+
CALL @foo, implicit-def dead $arguments, implicit $sp32, implicit $sp64
99+
EH_LABEL <mcsymbol .Ltmp1>
100+
BR %bb.3, implicit-def dead $arguments
101+
102+
;; Empty cleanuppad
103+
bb.1 (landing-pad):
104+
successors: %bb.2
105+
EH_LABEL <mcsymbol .Ltmp2>
106+
107+
bb.2:
108+
successors: %bb.3
109+
CLEANUPRET implicit-def dead $arguments
110+
111+
bb.3:
112+
RETURN implicit-def dead $arguments
113+
...

0 commit comments

Comments
 (0)