diff options
Diffstat (limited to 'test/lit')
-rw-r--r-- | test/lit/binary/heap-types.wast | 150 | ||||
-rw-r--r-- | test/lit/passes/heap2local.wast | 25 | ||||
-rw-r--r-- | test/lit/passes/precompute-gc.wast | 20 |
3 files changed, 194 insertions, 1 deletions
diff --git a/test/lit/binary/heap-types.wast b/test/lit/binary/heap-types.wast new file mode 100644 index 000000000..f455d7376 --- /dev/null +++ b/test/lit/binary/heap-types.wast @@ -0,0 +1,150 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. + +;; Check that heap types are emitted properly in the binary format. This file +;; contains small modules that each use a single instruction with a heap type. +;; If we forgot to update collectHeapTypes then we would not write out their +;; type, and hit an error during --roundtrip. + +;; RUN: foreach %s %t wasm-opt -all --roundtrip -S -o - | filecheck %s +;; RUN: foreach %s %t wasm-opt -all --roundtrip -S --nominal -o - | filecheck %s --check-prefix NOMNL + +(module + ;; CHECK: (type $struct.A (struct (field i32))) + ;; NOMNL: (type $struct.A (struct (field i32))) + (type $struct.A (struct i32)) + ;; NOMNL: (type $struct.B (struct (field i32))) + (type $struct.B (struct i32)) + ;; CHECK: (func $test + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (ref.test_static $struct.A + ;; CHECK-NEXT: (ref.null $struct.A) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; NOMNL: (func $test + ;; NOMNL-NEXT: (drop + ;; NOMNL-NEXT: (ref.test_static $struct.B + ;; NOMNL-NEXT: (ref.null $struct.A) + ;; NOMNL-NEXT: ) + ;; NOMNL-NEXT: ) + ;; NOMNL-NEXT: ) + (func $test + (drop + (ref.test_static $struct.B (ref.null $struct.A)) + ) + ) +) + +(module + ;; CHECK: (type $struct.A (struct (field i32))) + ;; NOMNL: (type $struct.A (struct (field i32))) + (type $struct.A (struct i32)) + ;; NOMNL: (type $struct.B (struct (field i32))) + (type $struct.B (struct i32)) + ;; CHECK: (func $test + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (ref.cast_static $struct.A + ;; CHECK-NEXT: (ref.null $struct.A) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; NOMNL: (func $test + ;; NOMNL-NEXT: (drop + ;; NOMNL-NEXT: (ref.cast_static $struct.B + ;; NOMNL-NEXT: (ref.null $struct.A) + ;; NOMNL-NEXT: ) + ;; NOMNL-NEXT: ) + ;; NOMNL-NEXT: ) + (func $test + (drop + (ref.cast_static $struct.B (ref.null $struct.A)) + ) + ) +) + +(module + ;; CHECK: (type $struct.A (struct (field i32))) + ;; NOMNL: (type $struct.A (struct (field i32))) + (type $struct.A (struct i32)) + ;; CHECK: (func $test + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (struct.new_default $struct.A) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; NOMNL: (func $test + ;; NOMNL-NEXT: (drop + ;; NOMNL-NEXT: (struct.new_default $struct.A) + ;; NOMNL-NEXT: ) + ;; NOMNL-NEXT: ) + (func $test + (drop + (struct.new_default $struct.A) + ) + ) +) + +(module + ;; CHECK: (type $vector (array (mut f64))) + ;; NOMNL: (type $vector (array (mut f64))) + (type $vector (array (mut f64))) + ;; CHECK: (func $test + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (array.new $vector + ;; CHECK-NEXT: (f64.const 3.14159) + ;; CHECK-NEXT: (i32.const 3) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; NOMNL: (func $test + ;; NOMNL-NEXT: (drop + ;; NOMNL-NEXT: (array.new $vector + ;; NOMNL-NEXT: (f64.const 3.14159) + ;; NOMNL-NEXT: (i32.const 3) + ;; NOMNL-NEXT: ) + ;; NOMNL-NEXT: ) + ;; NOMNL-NEXT: ) + (func $test + (drop + (array.new $vector + (f64.const 3.14159) + (i32.const 3) + ) + ) + ) +) + +(module + ;; CHECK: (type $vector (array (mut f64))) + ;; NOMNL: (type $vector (array (mut f64))) + (type $vector (array (mut f64))) + ;; CHECK: (func $test + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (array.init_static $vector + ;; CHECK-NEXT: (f64.const 1) + ;; CHECK-NEXT: (f64.const 2) + ;; CHECK-NEXT: (f64.const 4) + ;; CHECK-NEXT: (f64.const 8) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; NOMNL: (func $test + ;; NOMNL-NEXT: (drop + ;; NOMNL-NEXT: (array.init_static $vector + ;; NOMNL-NEXT: (f64.const 1) + ;; NOMNL-NEXT: (f64.const 2) + ;; NOMNL-NEXT: (f64.const 4) + ;; NOMNL-NEXT: (f64.const 8) + ;; NOMNL-NEXT: ) + ;; NOMNL-NEXT: ) + ;; NOMNL-NEXT: ) + (func $test + (drop + (array.init_static $vector + (f64.const 1) + (f64.const 2) + (f64.const 4) + (f64.const 8) + ) + ) + ) +) diff --git a/test/lit/passes/heap2local.wast b/test/lit/passes/heap2local.wast index d49836b99..90ac8a418 100644 --- a/test/lit/passes/heap2local.wast +++ b/test/lit/passes/heap2local.wast @@ -254,7 +254,7 @@ ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (block ;; (replaces something unreachable we can't emit) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (struct.new_with_rtt $struct.A + ;; CHECK-NEXT: (block ;; CHECK-NEXT: (i32.const 2) ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: (rtt.canon $struct.A) @@ -1937,4 +1937,27 @@ ) ) ) + + ;; CHECK: (func $simple-no-rtt + ;; CHECK-NEXT: (local $0 i32) + ;; CHECK-NEXT: (local $1 f64) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block (result (ref null $struct.A)) + ;; CHECK-NEXT: (local.set $0 + ;; CHECK-NEXT: (i32.const 0) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.set $1 + ;; CHECK-NEXT: (f64.const 0) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (ref.null $struct.A) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $simple-no-rtt + (drop + ;; This allocation has no rtt, so we have nothing to drop from it when + ;; we optimize. + (struct.new_default $struct.A) + ) + ) ) diff --git a/test/lit/passes/precompute-gc.wast b/test/lit/passes/precompute-gc.wast index 0a08c02c0..44eff1c5f 100644 --- a/test/lit/passes/precompute-gc.wast +++ b/test/lit/passes/precompute-gc.wast @@ -510,4 +510,24 @@ ) ) ) + + ;; CHECK: (func $new_block_unreachable (result anyref) + ;; CHECK-NEXT: (block + ;; CHECK-NEXT: (block + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (rtt.canon $struct) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $new_block_unreachable (result anyref) + (struct.new_with_rtt $struct + ;; The value is a block with an unreachable. precompute will get rid of the + ;; block, after which fuzz-exec should not crash - this is a regression test + ;; for us being careful in how we execute an unreachable struct.new + (block $label$1 (result i32) + (unreachable) + ) + (rtt.canon $struct) + ) + ) ) |