Skip to content

Commit

Permalink
[WebAssembly] Add type checking for 'throw' (llvm#108641)
Browse files Browse the repository at this point in the history
This was previously missing.
  • Loading branch information
aheejin authored Sep 14, 2024
1 parent 52b3c36 commit d6d4a48
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions llvm/test/MC/WebAssembly/eh-assembly.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d6d4a48

Please sign in to comment.