[llvm] [WebAssembly] Add type checking for 'throw' (PR #108641)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 13 13:16:31 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mc
@llvm/pr-subscribers-backend-webassembly
Author: Heejin Ahn (aheejin)
<details>
<summary>Changes</summary>
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
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/108641
More information about the llvm-commits
mailing list