[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:57:25 PDT 2024
================
@@ -371,12 +371,22 @@ 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:
Neither of
```cpp
ArrayRef<wasm::ValType> DestTypes = DestBlockInfo.IsLoop ? DestBlockInfo.Sig.Params : DestBlockInfo.Sig.Returns;
```
and
```cpp
SmallVectorImpl<wasm::ValType> DestTypes = DestBlockInfo.IsLoop ? DestBlockInfo.Sig.Params : DestBlockInfo.Sig.Returns;
```
works, saying things like
```console
.../llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp:375:32: error: incompatible operand types ('const SmallVector<[...], 4>' and 'const SmallVector<[...], 1>')
375 | DestBlockInfo.IsLoop ? DestBlockInfo.Sig.Params
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~
376 | : DestBlockInfo.Sig.Returns;
| ~~~~~~~~~~~~~~~~~~~~~~~~~
```
But this seems to work:
```cpp
ArrayRef<wasm::ValType> DestTypes;
if (DestBlockInfo.IsLoop)
DestTypes = DestBlockInfo.Sig.Params;
else
DestTypes = DestBlockInfo.Sig.Returns;
if (compareTypes(SentTypes, DestTypes)) {
...
```
Replacing `ArrayRef` with `SmallVectorImpl` here doesn't work because `SmallVectorImpl` doesn't seem to have its own default constructor.
https://github.com/llvm/llvm-project/pull/111432
More information about the llvm-commits
mailing list