[llvm] [WebAssembly] Fix rethrow's index calculation (PR #114693)

Derek Schuff via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 4 17:04:09 PST 2024


================
@@ -251,15 +251,40 @@ bool WebAssemblyLateEHPrepare::replaceFuncletReturns(MachineFunction &MF) {
       Changed = true;
       break;
     }
+    case WebAssembly::RETHROW:
+      // These RETHROWs here were lowered from llvm.wasm.rethrow() intrinsics,
+      // generated in Clang for when an exception is not caught by the given
+      // type (e.g. catch (int)).
+      //
+      // RETHROW's BB argument is the EH pad the exception to rethrow has been
+      // caught. (Until this point, RETHROW has just a '0' as a placeholder
+      // argument.) For these llvm.wasm.rethrow()s, we can safely assume the
+      // exception comes from the nearest dominating EH pad, because catch.start
+      // EH pad is structured like this:
+      //
+      // catch.start:
+      //   catchpad ...
+      //   %matches = compare ehselector with typeid
+      //   br i1 %matches, label %catch, label %rethrow
+      //
+      // rethrow:
+      //   ;; rethrows the exception caught in 'catch.start'
+      //   call @llvm.wasm.rethrow()
+      while (TI->getNumOperands() > 0)
----------------
dschuff wrote:

do we expect there to be more than one operand on the end here?

https://github.com/llvm/llvm-project/pull/114693


More information about the llvm-commits mailing list