Skip to content

Commit 24100f0

Browse files
tlivelyaheejin
authored andcommitted
[WebAssembly] Fix landingpad-only case in Emscripten EH (#30)
Summary: Previously we didn't set `Changed` to true when there are only landing pads but not invokes. This fixes it and we set `Changed` to true whenever we have landing pads. (There can't be invokes without landing pads, so that case is covered too) The test case for this has to be a separate file because this pass is a `ModulePass` and `Changed` is computed based on the whole module. Reviewers: tlively Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72308 Co-authored-by: Heejin Ahn <[email protected]>
1 parent 9330ec5 commit 24100f0

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,6 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runEHOnFunction(Function &F) {
755755
auto *II = dyn_cast<InvokeInst>(BB.getTerminator());
756756
if (!II)
757757
continue;
758-
Changed = true;
759758
LandingPads.insert(II->getLandingPadInst());
760759
IRB.SetInsertPoint(II);
761760

@@ -835,6 +834,7 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runEHOnFunction(Function &F) {
835834
if (auto *LPI = dyn_cast<LandingPadInst>(I))
836835
LandingPads.insert(LPI);
837836
}
837+
Changed = !LandingPads.empty();
838838

839839
// Handle all the landingpad for this function together, as multiple invokes
840840
// may share a single lp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; RUN: opt < %s -wasm-lower-em-ehsjlj -S | FileCheck %s
2+
3+
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
4+
target triple = "wasm32-unknown-unknown"
5+
6+
@_ZTIi = external constant i8*
7+
8+
; Checks if a module that only contains a landingpad (and resume) but not an
9+
; invoke works correctly and does not crash.
10+
; CHECK-LABEL: @landingpad_only
11+
define void @landingpad_only() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
12+
entry:
13+
br label %cont
14+
15+
lpad: ; preds = %entry
16+
%0 = landingpad { i8*, i32 }
17+
catch i8* bitcast (i8** @_ZTIi to i8*)
18+
catch i8* null
19+
resume { i8*, i32 } %0
20+
21+
cont:
22+
ret void
23+
}
24+
25+
declare i32 @__gxx_personality_v0(...)

0 commit comments

Comments
 (0)