Skip to content

Commit a56b846

Browse files
tlivelyaheejin
authored andcommitted
[WebAssembly] Fix resume-only case in Emscripten EH (#36)
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 Co-authored-by: Heejin Ahn <aheejin@gmail.com>
1 parent a6f4c1b commit a56b846

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp

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

@@ -795,6 +796,7 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runEHOnFunction(Function &F) {
795796
auto *RI = dyn_cast<ResumeInst>(&I);
796797
if (!RI)
797798
continue;
799+
Changed = true;
798800

799801
// Split the input into legal values
800802
Value *Input = RI->getValue();
@@ -819,6 +821,7 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runEHOnFunction(Function &F) {
819821
continue;
820822
if (Callee->getIntrinsicID() != Intrinsic::eh_typeid_for)
821823
continue;
824+
Changed = true;
822825

823826
IRB.SetInsertPoint(CI);
824827
CallInst *NewCI =
@@ -834,7 +837,7 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runEHOnFunction(Function &F) {
834837
if (auto *LPI = dyn_cast<LandingPadInst>(I))
835838
LandingPads.insert(LPI);
836839
}
837-
Changed = !LandingPads.empty();
840+
Changed |= !LandingPads.empty();
838841

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

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

-25
This file was deleted.
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)