[PATCH] D73308: [WebAssembly] Fix resume-only case in Emscripten EH

Heejin Ahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 23 16:49:42 PST 2020


aheejin created this revision.
aheejin added a reviewer: tlively.
Herald added subscribers: llvm-commits, sunfish, hiraditya, jgravelle-google, sbc100, dschuff.
Herald added a project: LLVM.

D72308 <https://reviews.llvm.org/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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73308

Files:
  llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
  llvm/test/CodeGen/WebAssembly/lower-em-exceptions-lpad-only.ll
  llvm/test/CodeGen/WebAssembly/lower-em-exceptions-resume-only.ll


Index: llvm/test/CodeGen/WebAssembly/lower-em-exceptions-resume-only.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/lower-em-exceptions-resume-only.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -wasm-lower-em-ehsjlj -S | FileCheck %s
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+; Checks if a module that only contains a resume but not an invoke works
+; correctly and does not crash.
+; CHECK-LABEL: @resume_only
+; CHECK: call void @__resumeException
+define void @resume_only() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
+entry:
+  %val0 = insertvalue { i8*, i32 } undef, i8* null, 0
+  %val1 = insertvalue { i8*, i32} %val0, i32 0, 1
+  resume { i8*, i32 } %val1
+}
+
+declare i32 @__gxx_personality_v0(...)
Index: llvm/test/CodeGen/WebAssembly/lower-em-exceptions-lpad-only.ll
===================================================================
--- llvm/test/CodeGen/WebAssembly/lower-em-exceptions-lpad-only.ll
+++ /dev/null
@@ -1,25 +0,0 @@
-; RUN: opt < %s -wasm-lower-em-ehsjlj -S | FileCheck %s
-
-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
-target triple = "wasm32-unknown-unknown"
-
- at _ZTIi = external constant i8*
-
-; Checks if a module that only contains a landingpad (and resume) but not an
-; invoke works correctly and does not crash.
-; CHECK-LABEL: @landingpad_only
-define void @landingpad_only() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
-entry:
-  br label %cont
-
-lpad:                                             ; preds = %entry
-  %0 = landingpad { i8*, i32 }
-          catch i8* bitcast (i8** @_ZTIi to i8*)
-          catch i8* null
-  resume { i8*, i32 } %0
-
-cont:
-  ret void
-}
-
-declare i32 @__gxx_personality_v0(...)
Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
@@ -751,6 +751,7 @@
     auto *II = dyn_cast<InvokeInst>(BB.getTerminator());
     if (!II)
       continue;
+    Changed = true;
     LandingPads.insert(II->getLandingPadInst());
     IRB.SetInsertPoint(II);
 
@@ -791,6 +792,7 @@
       auto *RI = dyn_cast<ResumeInst>(&I);
       if (!RI)
         continue;
+      Changed = true;
 
       // Split the input into legal values
       Value *Input = RI->getValue();
@@ -815,6 +817,7 @@
         continue;
       if (Callee->getIntrinsicID() != Intrinsic::eh_typeid_for)
         continue;
+      Changed = true;
 
       IRB.SetInsertPoint(CI);
       CallInst *NewCI =
@@ -830,7 +833,7 @@
     if (auto *LPI = dyn_cast<LandingPadInst>(I))
       LandingPads.insert(LPI);
   }
-  Changed = !LandingPads.empty();
+  Changed |= !LandingPads.empty();
 
   // Handle all the landingpad for this function together, as multiple invokes
   // may share a single lp


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73308.240051.patch
Type: text/x-patch
Size: 3027 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200124/2434f4a8/attachment.bin>


More information about the llvm-commits mailing list