summaryrefslogtreecommitdiff
path: root/test/lit/parse-double-unreachable.wast
diff options
context:
space:
mode:
Diffstat (limited to 'test/lit/parse-double-unreachable.wast')
-rw-r--r--test/lit/parse-double-unreachable.wast43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/lit/parse-double-unreachable.wast b/test/lit/parse-double-unreachable.wast
new file mode 100644
index 000000000..0dd657a62
--- /dev/null
+++ b/test/lit/parse-double-unreachable.wast
@@ -0,0 +1,43 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
+
+;; RUN: wasm-opt %s -all --nominal --roundtrip -S -o - | filecheck %s
+
+;; Regression test for a bug in which we could pop the expression stack past an
+;; unreachable if we were already in unreachable parsing mode.
+
+(module
+
+ ;; CHECK: (type $array (array_subtype i8 data))
+ (type $array (array i8))
+ (type $func (func (result i32)))
+
+ ;; CHECK: (func $double-unreachable (type $ref|$array|_=>_i32) (param $x (ref $array)) (result i32)
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (ref.null nofunc)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ (func $double-unreachable (param $x (ref $array)) (result i32)
+
+ (drop
+ ;; This gets emitted as an unreachable, but it doesn't have type
+ ;; unreachable, so we continue emitting instructions afterward. When
+ ;; parsing, this will put us into unreachable mode.
+ (call_ref $func
+ (ref.null nofunc)
+ )
+ )
+
+ (array.get_u $array
+ (local.get $x)
+
+ ;; Since this call_ref will be emitted as an unreachable, it does not consume
+ ;; the ref.null when parsing. Due to the bug, the ref.null would remain on
+ ;; the stack and would be incorrectly consumed as the index to the
+ ;; array.get_u, producing a type error.
+ (call_ref $func
+ (ref.null nofunc)
+ )
+ )
+ )
+)