-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WebAssembly] AsmTypeCheck does not handle block return values of unreachable block end #107524
Comments
@llvm/issue-subscribers-backend-webassembly Author: Heejin Ahn (aheejin)
`AsmTypeCheck` does not handle block/loop's concrete return values when their end is not reachable, for example,
```s
block i32
br 0
end
```
This is a valid wasm program but does not pass `AsmTypeCheck`.
Currently Wasm backend does not generate llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp Lines 1460 to 1520 in 093b8bf
An example program that would generate this case is ;; test.ll
target triple = "wasm32-unknown-unknown"
define i32 @<!-- -->loop_i32() {
entry:
br label %header
header:
br label %header
} which generates loop i32
br 0
end The reproducing commands: $ llc test.ll
$ llvm-mc -triple=wasm32-unknown-unknown test.s |
This makes the type checker handle blocks with input parameters and return types, branches, and polymorphic stacks correctly. We maintain the stack of "block info", which contains its input parameter type, return type, and whether it is a loop or not. And this is used when checking the validity of the value stack at the `end` marker and all branches targeting the block. `StackType` now supports a new variant `Polymorphic`, which indicates the stack is in the polymorphic state. `Polymorphic`s are not popped even when `popType` is executed; they are only popped when the current block ends. When popping from the value stack, we ensure we don't pop more than we are allowed to at the given block level and print appropriate error messages instead. Also after a block ends, the value stack is guaranteed to have the right types based on the block return type. For example, ```wast block i32 unreachable end_block ;; You can expect to have an i32 on the stack here ``` This also adds handling for `br_if`. Previously only `br`s were checked. `checkEnd` and `checkBr` were removed and their contents have been inlined to the main `typeCheck` function, because they are called only from a single callsite. This also fixes two existing bugs in AsmParser, which were required to make the tests passing. This modifies several existing invalid tests, those that passed (incorrectly) before but do not pass with the new type checker anymore. Fixes llvm#107524.
…m#110770) This makes the type checker handle blocks with input parameters and return types, branches, and polymorphic stacks correctly. We maintain the stack of "block info", which contains its input parameter type, return type, and whether it is a loop or not. And this is used when checking the validity of the value stack at the `end` marker and all branches targeting the block. `StackType` now supports a new variant `Polymorphic`, which indicates the stack is in the polymorphic state. `Polymorphic`s are not popped even when `popType` is executed; they are only popped when the current block ends. When popping from the value stack, we ensure we don't pop more than we are allowed to at the given block level and print appropriate error messages instead. Also after a block ends, the value stack is guaranteed to have the right types based on the block return type. For example, ```wast block i32 unreachable end_block ;; You can expect to have an i32 on the stack here ``` This also adds handling for `br_if`. Previously only `br`s were checked. `checkEnd` and `checkBr` were removed and their contents have been inlined to the main `typeCheck` function, because they are called only from a single callsite. This also fixes two existing bugs in AsmParser, which were required to make the tests passing. I added Github comments about them inline. This modifies several existing invalid tests, those that passed (incorrectly) before but do not pass with the new type checker anymore. Fixes llvm#107524.
AsmTypeCheck
does not handle block/loop's concrete return values when their end is not reachable, for example,This is a valid wasm program but does not pass
AsmTypeCheck
.Currently Wasm backend does not generate
block
/loop
return types, but one exception is, the ones generated byWebAssemblyCFGStackify::fixEndsAtEndOfFunction
:llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
Lines 1460 to 1520 in 093b8bf
An example program that would generate this case is
which generates
The reproducing commands:
The error will be
The text was updated successfully, but these errors were encountered: