[llvm] [WebAssembly] Allow try_table to target loops in AsmTypeCheck (PR #111432)

Derek Schuff via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 7 14:11:22 PDT 2024


================
@@ -371,12 +371,22 @@ bool WebAssemblyAsmTypeCheck::checkTryTable(SMLoc ErrorLoc,
     if (Level < BlockInfoStack.size()) {
       const auto &DestBlockInfo =
           BlockInfoStack[BlockInfoStack.size() - Level - 1];
-      if (compareTypes(SentTypes, DestBlockInfo.Sig.Returns)) {
-        std::string ErrorMsg =
-            ErrorMsgBase + "type mismatch, catch tag type is " +
-            getTypesString(SentTypes) + ", but destination's type is " +
-            getTypesString(DestBlockInfo.Sig.Returns);
-        Error |= typeError(ErrorLoc, ErrorMsg);
+      if (DestBlockInfo.IsLoop) {
+        if (compareTypes(SentTypes, DestBlockInfo.Sig.Params)) {
+          std::string ErrorMsg =
+              ErrorMsgBase + "type mismatch, catch tag type is " +
+              getTypesString(SentTypes) + ", but destination's type is " +
+              getTypesString(DestBlockInfo.Sig.Params);
+          Error |= typeError(ErrorLoc, ErrorMsg);
+        }
+      } else {
+        if (compareTypes(SentTypes, DestBlockInfo.Sig.Returns)) {
+          std::string ErrorMsg =
+              ErrorMsgBase + "type mismatch, catch tag type is " +
+              getTypesString(SentTypes) + ", but destination's type is " +
+              getTypesString(DestBlockInfo.Sig.Returns);
+          Error |= typeError(ErrorLoc, ErrorMsg);
+        }
----------------
dschuff wrote:

Got it. I wonder if you could upcast both sides of the `:` in the ternary to SmallVectorImpl... but that doesn't really seem any better than what you have here.

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


More information about the llvm-commits mailing list