Skip to content

[WebAssembly] Add type checking for 'throw' #108641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2024
Merged

Conversation

aheejin
Copy link
Member

@aheejin aheejin commented Sep 13, 2024

This was previously missing.

This was previously missing.
@llvmbot llvmbot added backend:WebAssembly mc Machine (object) code labels Sep 13, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 13, 2024

@llvm/pr-subscribers-mc

@llvm/pr-subscribers-backend-webassembly

Author: Heejin Ahn (aheejin)

Changes

This was previously missing.


Full diff: https://github.com/llvm/llvm-project/pull/108641.diff

2 Files Affected:

  • (modified) llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp (+7)
  • (modified) llvm/test/MC/WebAssembly/eh-assembly.s (+2)
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

@aheejin aheejin merged commit d6d4a48 into llvm:main Sep 14, 2024
11 checks passed
@aheejin aheejin deleted the throw_typecheck branch September 14, 2024 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:WebAssembly mc Machine (object) code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants