summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-08-23 13:56:54 -0500
committerGitHub <noreply@github.com>2023-08-23 11:56:54 -0700
commitf6867f9a485c125dcd2914f58e2636f01879db7b (patch)
tree07f976ce0d417dc2f7280e53e7a1623d6607bebb /test
parent1cd3cff4820222901eaa015fd2d7b0b4b5b7fc3e (diff)
downloadbinaryen-f6867f9a485c125dcd2914f58e2636f01879db7b.tar.gz
binaryen-f6867f9a485c125dcd2914f58e2636f01879db7b.tar.bz2
binaryen-f6867f9a485c125dcd2914f58e2636f01879db7b.zip
Fix assertion failure in RemoveUnusedBrs (#5895)
The improvements to RemoveUnusedBrs in #5887 also introduced a regression where the pass did not correctly handle unreachable fallthrough values and crashed with an assertion failure. Fix the problem by returning early when a fallthrough value is unreachable and add a regression test. Fixes #5892.
Diffstat (limited to 'test')
-rw-r--r--test/lit/passes/remove-unused-brs-gc.wast39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/lit/passes/remove-unused-brs-gc.wast b/test/lit/passes/remove-unused-brs-gc.wast
index 0d0a94cd8..6f7dd5819 100644
--- a/test/lit/passes/remove-unused-brs-gc.wast
+++ b/test/lit/passes/remove-unused-brs-gc.wast
@@ -595,6 +595,45 @@
)
)
+ ;; CHECK: (func $fallthrough-unreachable (type $i31ref_=>_anyref) (param $0 i31ref) (result anyref)
+ ;; CHECK-NEXT: (block $outer
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (block ;; (replaces something unreachable we can't emit)
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (block
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (ref.cast none
+ ;; CHECK-NEXT: (local.get $0)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $fallthrough-unreachable (param $0 i31ref) (result anyref)
+ (block $outer (result (ref none))
+ (drop
+ ;; This should not crash due to the new unreachable below.
+ (br_on_cast $outer (ref none) (ref none)
+ (ref.cast none
+ ;; This will be optimized to a drop + unreachable.
+ (br_on_cast $outer (ref none) (ref none)
+ (ref.cast none
+ (local.get $0)
+ )
+ )
+ )
+ )
+ )
+ (unreachable)
+ )
+ )
+
;; CHECK: (func $casts-are-costly (type $i32_=>_none) (param $x i32)
;; CHECK-NEXT: (local $struct (ref null $struct))
;; CHECK-NEXT: (drop