[WebAssembly] Handle block-like structures consistently in type checker
authorHeejin Ahn <aheejin@gmail.com>
Sat, 8 Apr 2023 14:11:43 +0000 (07:11 -0700)
committerHeejin Ahn <aheejin@gmail.com>
Tue, 11 Apr 2023 09:07:00 +0000 (02:07 -0700)
commit3e9881b92b090577ac1e8964d0504a455a306ca9
treefa52c558b7c3ed864539329c97e10b1e1833b639
parent8c0798f368356e50f59a2598b28e7cac8770ea4c
[WebAssembly] Handle block-like structures consistently in type checker

We disable type check in unreachable code, but when the unreachable code
is enclosed within a block-like structure, the block as a whole has a
valid type and we should continue type checking after the block. But it
looks we currently only do that for blocks and not other block-like
structures (`loop`s, `try`s, and `if`s). Also unreachable code within
`if`'s true body shouldn't disable type checking in `else` body, and
that in `try` body shouldn't disable type checking in `catch/catch_all`
body.

This also causes the values/types on the stack to be correctly checked
when encounterint `catch`, `catch_all`, and `delegate`.

Reviewed By: dschuff

Differential Revision: https://reviews.llvm.org/D147852
llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
llvm/test/MC/WebAssembly/type-checker-errors.s
llvm/test/MC/WebAssembly/type-checker-return.s