[all-commits] [llvm/llvm-project] a268bd: [WebAssembly] Handle block and polymorphic stack i...

Heejin Ahn via All-commits all-commits at lists.llvm.org
Wed Oct 2 16:48:42 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a268bda0dafd8ffa048e6892c5501313d01d4a40
      https://github.com/llvm/llvm-project/commit/a268bda0dafd8ffa048e6892c5501313d01d4a40
  Author: Heejin Ahn <aheejin at gmail.com>
  Date:   2024-10-02 (Wed, 02 Oct 2024)

  Changed paths:
    M llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
    M llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
    M llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.h
    M llvm/test/MC/WebAssembly/basic-assembly.s
    A llvm/test/MC/WebAssembly/block-assembly.s
    M llvm/test/MC/WebAssembly/reference-types.s
    M llvm/test/MC/WebAssembly/type-checker-errors.s

  Log Message:
  -----------
  [WebAssembly] Handle block and polymorphic stack in AsmTypeCheck (#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 #107524.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list