[llvm] d6d4a48 - [WebAssembly] Add type checking for 'throw' (#108641)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 13 18:15:13 PDT 2024


Author: Heejin Ahn
Date: 2024-09-13T18:15:10-07:00
New Revision: d6d4a48e0e12f2d5b671c60437e7f55e2c5a506f

URL: https://github.com/llvm/llvm-project/commit/d6d4a48e0e12f2d5b671c60437e7f55e2c5a506f
DIFF: https://github.com/llvm/llvm-project/commit/d6d4a48e0e12f2d5b671c60437e7f55e2c5a506f.diff

LOG: [WebAssembly] Add type checking for 'throw' (#108641)

This was previously missing.

Added: 
    

Modified: 
    llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
    llvm/test/MC/WebAssembly/eh-assembly.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
index ec3d51d4e0e843..9f8f78a5b6adb7 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
@@ -420,6 +420,13 @@ bool WebAssemblyAsmTypeCheck::typeCheck(SMLoc ErrorLoc, const MCInst &Inst,
     if (popRefType(ErrorLoc))
       return true;
     Stack.push_back(wasm::ValType::I32);
+  } else if (Name == "throw") {
+    const wasm::WasmSignature *Sig = nullptr;
+    if (getSignature(Operands[1]->getStartLoc(), Inst.getOperand(0),
+                     wasm::WASM_SYMBOL_TYPE_TAG, Sig))
+      return true;
+    if (checkSig(ErrorLoc, *Sig))
+      return true;
   } else {
     // The current instruction is a stack instruction which doesn't have
     // explicit operands that indicate push/pop types, so we get those from

diff  --git a/llvm/test/MC/WebAssembly/eh-assembly.s b/llvm/test/MC/WebAssembly/eh-assembly.s
index c84a65e55605cc..8c4ae3bb3e4e49 100644
--- a/llvm/test/MC/WebAssembly/eh-assembly.s
+++ b/llvm/test/MC/WebAssembly/eh-assembly.s
@@ -10,6 +10,7 @@
 eh_legacy_test:
   # try-catch with catch, catch_all, throw, and rethrow
   try
+    i32.const 3
     throw     __cpp_exception
   catch       __cpp_exception
     drop
@@ -40,6 +41,7 @@ eh_legacy_test:
 
 # CHECK-LABEL: eh_legacy_test:
 # CHECK-NEXT:    try
+# CHECK-NEXT:    i32.const       3
 # CHECK-NEXT:    throw           __cpp_exception
 # CHECK-NEXT:    catch           __cpp_exception
 # CHECK-NEXT:    drop


        


More information about the llvm-commits mailing list