Skip to content

Commit d6d4a48

Browse files
authored
[WebAssembly] Add type checking for 'throw' (#108641)
This was previously missing.
1 parent 52b3c36 commit d6d4a48

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,13 @@ bool WebAssemblyAsmTypeCheck::typeCheck(SMLoc ErrorLoc, const MCInst &Inst,
420420
if (popRefType(ErrorLoc))
421421
return true;
422422
Stack.push_back(wasm::ValType::I32);
423+
} else if (Name == "throw") {
424+
const wasm::WasmSignature *Sig = nullptr;
425+
if (getSignature(Operands[1]->getStartLoc(), Inst.getOperand(0),
426+
wasm::WASM_SYMBOL_TYPE_TAG, Sig))
427+
return true;
428+
if (checkSig(ErrorLoc, *Sig))
429+
return true;
423430
} else {
424431
// The current instruction is a stack instruction which doesn't have
425432
// explicit operands that indicate push/pop types, so we get those from

llvm/test/MC/WebAssembly/eh-assembly.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
eh_legacy_test:
1111
# try-catch with catch, catch_all, throw, and rethrow
1212
try
13+
i32.const 3
1314
throw __cpp_exception
1415
catch __cpp_exception
1516
drop
@@ -40,6 +41,7 @@ eh_legacy_test:
4041

4142
# CHECK-LABEL: eh_legacy_test:
4243
# CHECK-NEXT: try
44+
# CHECK-NEXT: i32.const 3
4345
# CHECK-NEXT: throw __cpp_exception
4446
# CHECK-NEXT: catch __cpp_exception
4547
# CHECK-NEXT: drop

0 commit comments

Comments
 (0)