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

Heejin Ahn via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 13 13:15:59 PDT 2024


https://github.com/aheejin created https://github.com/llvm/llvm-project/pull/108641

This was previously missing.

>From d91ba476e05e267faa28212e6b3fc268e23f07c1 Mon Sep 17 00:00:00 2001
From: Heejin Ahn <aheejin at gmail.com>
Date: Fri, 13 Sep 2024 19:47:24 +0000
Subject: [PATCH] [WebAssembly] Add type checking for 'throw'

This was previously missing.
---
 .../WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp      | 7 +++++++
 llvm/test/MC/WebAssembly/eh-assembly.s                     | 2 ++
 2 files changed, 9 insertions(+)

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