Skip to content

Commit 580d783

Browse files
committed
[WebAssembly] Fix resume-only case in Emscripten EH
Summary: D72308 incorrectly assumed `resume` cannot exist without a `landingpad`, which is not true. This sets `Changed` to true whenever we make changes to a function, including creating a call to `__resumeException` within a function without a landing pad. Reviewers: tlively Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D73308
1 parent 838a28e commit 580d783

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runEHOnFunction(Function &F) {
751751
auto *II = dyn_cast<InvokeInst>(BB.getTerminator());
752752
if (!II)
753753
continue;
754+
Changed = true;
754755
LandingPads.insert(II->getLandingPadInst());
755756
IRB.SetInsertPoint(II);
756757

@@ -791,6 +792,7 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runEHOnFunction(Function &F) {
791792
auto *RI = dyn_cast<ResumeInst>(&I);
792793
if (!RI)
793794
continue;
795+
Changed = true;
794796

795797
// Split the input into legal values
796798
Value *Input = RI->getValue();
@@ -815,6 +817,7 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runEHOnFunction(Function &F) {
815817
continue;
816818
if (Callee->getIntrinsicID() != Intrinsic::eh_typeid_for)
817819
continue;
820+
Changed = true;
818821

819822
IRB.SetInsertPoint(CI);
820823
CallInst *NewCI =
@@ -830,7 +833,7 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runEHOnFunction(Function &F) {
830833
if (auto *LPI = dyn_cast<LandingPadInst>(I))
831834
LandingPads.insert(LPI);
832835
}
833-
Changed = !LandingPads.empty();
836+
Changed |= !LandingPads.empty();
834837

835838
// Handle all the landingpad for this function together, as multiple invokes
836839
// may share a single lp

llvm/test/CodeGen/WebAssembly/lower-em-exceptions-lpad-only.ll

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
; Checks if a module that only contains a resume but not an invoke works
7+
; correctly and does not crash.
8+
; CHECK-LABEL: @resume_only
9+
; CHECK: call void @__resumeException
10+
define void @resume_only() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
11+
entry:
12+
%val0 = insertvalue { i8*, i32 } undef, i8* null, 0
13+
%val1 = insertvalue { i8*, i32} %val0, i32 0, 1
14+
resume { i8*, i32 } %val1
15+
}
16+
17+
declare i32 @__gxx_personality_v0(...)

0 commit comments

Comments
 (0)