[llvm] [WebAssembly] Allow try_table to target loops in AsmTypeCheck (PR #111432)
Heejin Ahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 7 13:29:14 PDT 2024
================
@@ -371,13 +371,23 @@ bool WebAssemblyAsmTypeCheck::checkTryTable(SMLoc ErrorLoc,
if (Level < BlockInfoStack.size()) {
const auto &DestBlockInfo =
BlockInfoStack[BlockInfoStack.size() - Level - 1];
- if (compareTypes(SentTypes, DestBlockInfo.Sig.Returns)) {
- std::string ErrorMsg =
- ErrorMsgBase + "type mismatch, catch tag type is " +
- getTypesString(SentTypes) + ", but destination's type is " +
- getTypesString(DestBlockInfo.Sig.Returns);
- Error |= typeError(ErrorLoc, ErrorMsg);
- }
+ if (DestBlockInfo.IsLoop) {
+ if (compareTypes(SentTypes, DestBlockInfo.Sig.Params)) {
+ std::string ErrorMsg =
+ ErrorMsgBase + "type mismatch, catch tag type is " +
+ getTypesString(SentTypes) + ", but destination's type is " +
+ getTypesString(DestBlockInfo.Sig.Params);
+ Error |= typeError(ErrorLoc, ErrorMsg);
+ }
+ } else {
+ if (compareTypes(SentTypes, DestBlockInfo.Sig.Returns)) {
+ std::string ErrorMsg =
+ ErrorMsgBase + "type mismatch, catch tag type is " +
+ getTypesString(SentTypes) + ", but destination's type is " +
+ getTypesString(DestBlockInfo.Sig.Returns);
+ Error |= typeError(ErrorLoc, ErrorMsg);
+ }
+ }
----------------
aheejin wrote:
This is kind of repetitive. I wanted something like
```cpp
ArrayRef DestTypes = DestBlockInfo.IsLoop ? DestBlockInfo.Sig.Params : DestBlockInfo.Sig.Returns;
if (compares(SentTypes, DestTypes)) {
...
}
```
But this was not possible because the types of `WasmSignature::Params` and `WasmSignature::Returns` are different:
https://github.com/llvm/llvm-project/blob/a98466ad8967f9ad9cd79157a7aed8ade5d65a7a/llvm/include/llvm/BinaryFormat/Wasm.h#L496-L497
https://github.com/llvm/llvm-project/pull/111432
More information about the llvm-commits
mailing list