summaryrefslogtreecommitdiff
path: root/test/lit
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-08-24 16:22:31 -0700
committerGitHub <noreply@github.com>2022-08-24 16:22:31 -0700
commit5c035932d7b98b69113a37bbdd90932c818f660f (patch)
treee17c831dc8c590e7fe8fc0aa649c6e8a68530af4 /test/lit
parentd5e17e7bbe0901606b0892dfe3fca88d84bf6f82 (diff)
downloadbinaryen-5c035932d7b98b69113a37bbdd90932c818f660f.tar.gz
binaryen-5c035932d7b98b69113a37bbdd90932c818f660f.tar.bz2
binaryen-5c035932d7b98b69113a37bbdd90932c818f660f.zip
[NFC] Add a test for inlining a function that traps (#4966)
I don't see an existing test for this, and it's useful behavior since such inlining will propagate the trap to the caller, possibly helping DCE and other things there, so it's good to have a test to guarantee we never break it.
Diffstat (limited to 'test/lit')
-rw-r--r--test/lit/passes/inlining-unreachable.wast68
1 files changed, 68 insertions, 0 deletions
diff --git a/test/lit/passes/inlining-unreachable.wast b/test/lit/passes/inlining-unreachable.wast
new file mode 100644
index 000000000..4cec297e4
--- /dev/null
+++ b/test/lit/passes/inlining-unreachable.wast
@@ -0,0 +1,68 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
+
+;; RUN: foreach %s %t wasm-opt --inlining -S -o - | filecheck %s
+
+;; Test that we inline functions with unreachable bodies. This is important to
+;; propagate the trap to the caller (where it might lead to DCE).
+
+(module
+ (func $trap
+ (unreachable)
+ )
+ ;; CHECK: (type $none_=>_none (func))
+
+ ;; CHECK: (type $none_=>_i32 (func (result i32)))
+
+ ;; CHECK: (func $call-trap
+ ;; CHECK-NEXT: (block $__inlined_func$trap
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: (br $__inlined_func$trap)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $call-trap
+ ;; In this case the call had type none, but the inlined code is unreachable,
+ ;; so we'll add a br to the new block to keep the type as none (the br is
+ ;; not actually reached, and other opts will remove it).
+ (call $trap)
+ )
+
+ (func $trap-result (result i32)
+ ;; As above, but now there is a declared result.
+ (unreachable)
+ )
+
+ ;; CHECK: (func $call-trap-result (result i32)
+ ;; CHECK-NEXT: (block $__inlined_func$trap-result (result i32)
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $call-trap-result (result i32)
+ (call $trap-result)
+ )
+
+ (func $contents-then-trap
+ ;; Add some contents in addition to the trap.
+ (nop)
+ (drop
+ (i32.const 1337)
+ )
+ (nop)
+ (unreachable)
+ )
+ ;; CHECK: (func $call-contents-then-trap
+ ;; CHECK-NEXT: (block $__inlined_func$contents-then-trap
+ ;; CHECK-NEXT: (block
+ ;; CHECK-NEXT: (nop)
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (i32.const 1337)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (nop)
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (br $__inlined_func$contents-then-trap)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $call-contents-then-trap
+ (call $contents-then-trap)
+ )
+)