diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/passes/optimize-instructions-gc.wast | 44 | ||||
-rw-r--r-- | test/spec/ref_cast.wast | 33 |
2 files changed, 47 insertions, 30 deletions
diff --git a/test/lit/passes/optimize-instructions-gc.wast b/test/lit/passes/optimize-instructions-gc.wast index 1bf72ae04..fe18c015b 100644 --- a/test/lit/passes/optimize-instructions-gc.wast +++ b/test/lit/passes/optimize-instructions-gc.wast @@ -1791,59 +1791,57 @@ ;; CHECK: (func $incompatible-cast-of-null (type $void) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (block (result nullref) + ;; CHECK-NEXT: (block (result (ref $array)) ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (ref.null none) ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (ref.null none) + ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (ref.as_non_null - ;; CHECK-NEXT: (block (result nullref) - ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (ref.as_non_null - ;; CHECK-NEXT: (ref.null none) - ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (block (result (ref $array)) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (ref.as_non_null + ;; CHECK-NEXT: (ref.null none) ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (ref.null none) ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; NOMNL: (func $incompatible-cast-of-null (type $void) ;; NOMNL-NEXT: (drop - ;; NOMNL-NEXT: (block (result nullref) + ;; NOMNL-NEXT: (block (result (ref $array)) ;; NOMNL-NEXT: (drop ;; NOMNL-NEXT: (ref.null none) ;; NOMNL-NEXT: ) - ;; NOMNL-NEXT: (ref.null none) + ;; NOMNL-NEXT: (unreachable) ;; NOMNL-NEXT: ) ;; NOMNL-NEXT: ) ;; NOMNL-NEXT: (drop - ;; NOMNL-NEXT: (ref.as_non_null - ;; NOMNL-NEXT: (block (result nullref) - ;; NOMNL-NEXT: (drop - ;; NOMNL-NEXT: (ref.as_non_null - ;; NOMNL-NEXT: (ref.null none) - ;; NOMNL-NEXT: ) + ;; NOMNL-NEXT: (block (result (ref $array)) + ;; NOMNL-NEXT: (drop + ;; NOMNL-NEXT: (ref.as_non_null + ;; NOMNL-NEXT: (ref.null none) ;; NOMNL-NEXT: ) - ;; NOMNL-NEXT: (ref.null none) ;; NOMNL-NEXT: ) + ;; NOMNL-NEXT: (unreachable) ;; NOMNL-NEXT: ) ;; NOMNL-NEXT: ) ;; NOMNL-NEXT: ) (func $incompatible-cast-of-null (drop - (ref.cast null $array - (ref.null $struct) + (ref.cast $array + ;; The child is null, so the cast will trap. Replace it with an + ;; unreachable. + (ref.null none) ) ) (drop (ref.cast $array - ;; The fallthrough is null, but the node's child's type is non-nullable, - ;; so we must add a ref.as_non_null on the outside to keep the type - ;; identical. + ;; Even though the child type is non-null, it is still valid to do this + ;; transformation. In practice this code will trap before getting to our + ;; new unreachable. (ref.as_non_null (ref.null $struct) ) diff --git a/test/spec/ref_cast.wast b/test/spec/ref_cast.wast index 658f20c23..704063ec6 100644 --- a/test/spec/ref_cast.wast +++ b/test/spec/ref_cast.wast @@ -30,23 +30,34 @@ (call $init) (drop (ref.cast null $t0 (ref.null data))) + (drop (ref.cast null $t0 (struct.new_default $t0))) (drop (ref.cast null $t0 (global.get $tab.0))) (drop (ref.cast null $t0 (global.get $tab.1))) (drop (ref.cast null $t0 (global.get $tab.2))) (drop (ref.cast null $t0 (global.get $tab.3))) (drop (ref.cast null $t0 (global.get $tab.4))) - - (drop (ref.cast null $t0 (ref.null data))) + (drop (ref.cast $t0 (global.get $tab.0))) + (drop (ref.cast $t0 (global.get $tab.1))) + (drop (ref.cast $t0 (global.get $tab.2))) + (drop (ref.cast $t0 (global.get $tab.3))) + (drop (ref.cast $t0 (global.get $tab.4))) + + (drop (ref.cast null $t1 (ref.null data))) + (drop (ref.cast null $t1 (struct.new_default $t1))) (drop (ref.cast null $t1 (global.get $tab.1))) (drop (ref.cast null $t1 (global.get $tab.2))) + (drop (ref.cast $t1 (global.get $tab.1))) + (drop (ref.cast $t1 (global.get $tab.2))) - (drop (ref.cast null $t0 (ref.null data))) + (drop (ref.cast null $t2 (ref.null data))) + (drop (ref.cast null $t2 (struct.new_default $t2))) (drop (ref.cast null $t2 (global.get $tab.2))) + (drop (ref.cast $t2 (global.get $tab.2))) - (drop (ref.cast null $t0 (ref.null data))) + (drop (ref.cast null $t3 (ref.null data))) + (drop (ref.cast null $t3 (struct.new_default $t3))) (drop (ref.cast null $t3 (global.get $tab.3))) - - (drop (ref.cast null $t0 (ref.null data))) + (drop (ref.cast $t3 (global.get $tab.3))) ) (func (export "test-canon") @@ -103,8 +114,15 @@ ) (i32.const 1) ) -) + (func (export "test-trap-null") + (drop + (ref.cast $t0 + (ref.null $t0) + ) + ) + ) +) (invoke "test-sub") (invoke "test-canon") @@ -114,6 +132,7 @@ (assert_return (invoke "test-ref-cast-struct")) (assert_return (invoke "test-br-on-cast-struct") (i32.const 1)) (assert_return (invoke "test-br-on-cast-fail-struct") (i32.const 0)) +(assert_trap (invoke "test-trap-null")) (assert_invalid (module |