|
| 1 | +;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. |
| 2 | + |
| 3 | +;; Check that we don't refine in ways that might require invalid exact casts |
| 4 | +;; when custom descriptors is disabled. |
| 5 | + |
| 6 | +;; RUN: wasm-opt %s -all --closed-world --preserve-type-order \ |
| 7 | +;; RUN: --type-refining -S -o - | filecheck %s |
| 8 | + |
| 9 | +;; RUN: wasm-opt %s -all --disable-custom-descriptors --closed-world --preserve-type-order \ |
| 10 | +;; RUN: --type-refining -S -o - | filecheck %s --check-prefix=NO_CD |
| 11 | + |
| 12 | +(module |
| 13 | + ;; CHECK: (rec |
| 14 | + ;; CHECK-NEXT: (type $foo (struct)) |
| 15 | + ;; NO_CD: (rec |
| 16 | + ;; NO_CD-NEXT: (type $foo (struct)) |
| 17 | + (type $foo (struct)) |
| 18 | + ;; CHECK: (type $bar (struct (field (mut (ref (exact $foo)))))) |
| 19 | + ;; NO_CD: (type $bar (struct (field (mut (ref $foo))))) |
| 20 | + (type $bar (struct (field (mut (ref null $foo))))) |
| 21 | + |
| 22 | + ;; CHECK: (type $already-exact (struct (field (ref (exact $foo))))) |
| 23 | + ;; NO_CD: (type $already-exact (struct (field (ref (exact $foo))))) |
| 24 | + (type $already-exact (struct (field (ref (exact $foo))))) |
| 25 | + |
| 26 | + ;; CHECK: (tag $e (type $3)) |
| 27 | + ;; NO_CD: (tag $e (type $3)) |
| 28 | + (tag $e) |
| 29 | + |
| 30 | + ;; CHECK: (func $struct.new (type $4) (param $inexact (ref null $foo)) (param $exact (ref (exact $foo))) (result anyref) |
| 31 | + ;; CHECK-NEXT: (struct.new $bar |
| 32 | + ;; CHECK-NEXT: (ref.cast (ref (exact $foo)) |
| 33 | + ;; CHECK-NEXT: (try (result (ref null $foo)) |
| 34 | + ;; CHECK-NEXT: (do |
| 35 | + ;; CHECK-NEXT: (struct.get $bar 0 |
| 36 | + ;; CHECK-NEXT: (struct.new $bar |
| 37 | + ;; CHECK-NEXT: (local.get $exact) |
| 38 | + ;; CHECK-NEXT: ) |
| 39 | + ;; CHECK-NEXT: ) |
| 40 | + ;; CHECK-NEXT: ) |
| 41 | + ;; CHECK-NEXT: (catch $e |
| 42 | + ;; CHECK-NEXT: (local.get $inexact) |
| 43 | + ;; CHECK-NEXT: ) |
| 44 | + ;; CHECK-NEXT: ) |
| 45 | + ;; CHECK-NEXT: ) |
| 46 | + ;; CHECK-NEXT: ) |
| 47 | + ;; CHECK-NEXT: ) |
| 48 | + ;; NO_CD: (func $struct.new (type $4) (param $inexact (ref null $foo)) (param $exact (ref (exact $foo))) (result anyref) |
| 49 | + ;; NO_CD-NEXT: (struct.new $bar |
| 50 | + ;; NO_CD-NEXT: (ref.cast (ref $foo) |
| 51 | + ;; NO_CD-NEXT: (try (result (ref null $foo)) |
| 52 | + ;; NO_CD-NEXT: (do |
| 53 | + ;; NO_CD-NEXT: (struct.get $bar 0 |
| 54 | + ;; NO_CD-NEXT: (struct.new $bar |
| 55 | + ;; NO_CD-NEXT: (local.get $exact) |
| 56 | + ;; NO_CD-NEXT: ) |
| 57 | + ;; NO_CD-NEXT: ) |
| 58 | + ;; NO_CD-NEXT: ) |
| 59 | + ;; NO_CD-NEXT: (catch $e |
| 60 | + ;; NO_CD-NEXT: (local.get $inexact) |
| 61 | + ;; NO_CD-NEXT: ) |
| 62 | + ;; NO_CD-NEXT: ) |
| 63 | + ;; NO_CD-NEXT: ) |
| 64 | + ;; NO_CD-NEXT: ) |
| 65 | + ;; NO_CD-NEXT: ) |
| 66 | + (func $struct.new (param $inexact (ref null $foo)) (param $exact (ref (exact $foo))) (result anyref) |
| 67 | + (struct.new $bar |
| 68 | + (try (result (ref null $foo)) |
| 69 | + (do |
| 70 | + (struct.get $bar 0 |
| 71 | + (struct.new $bar |
| 72 | + (local.get $exact) |
| 73 | + ) |
| 74 | + ) |
| 75 | + ) |
| 76 | + (catch $e |
| 77 | + (local.get $inexact) |
| 78 | + ) |
| 79 | + ) |
| 80 | + ) |
| 81 | + ) |
| 82 | + |
| 83 | + ;; CHECK: (func $make-already-exact (type $5) (param $0 (ref (exact $foo))) (result (ref (exact $foo))) |
| 84 | + ;; CHECK-NEXT: (struct.get $already-exact 0 |
| 85 | + ;; CHECK-NEXT: (struct.new $already-exact |
| 86 | + ;; CHECK-NEXT: (local.get $0) |
| 87 | + ;; CHECK-NEXT: ) |
| 88 | + ;; CHECK-NEXT: ) |
| 89 | + ;; CHECK-NEXT: ) |
| 90 | + ;; NO_CD: (func $make-already-exact (type $5) (param $0 (ref (exact $foo))) (result (ref (exact $foo))) |
| 91 | + ;; NO_CD-NEXT: (struct.get $already-exact 0 |
| 92 | + ;; NO_CD-NEXT: (struct.new $already-exact |
| 93 | + ;; NO_CD-NEXT: (local.get $0) |
| 94 | + ;; NO_CD-NEXT: ) |
| 95 | + ;; NO_CD-NEXT: ) |
| 96 | + ;; NO_CD-NEXT: ) |
| 97 | + (func $make-already-exact (param (ref (exact $foo))) (result (ref (exact $foo))) |
| 98 | + ;; We should not accidentally remove exactness from a field that is already exact. |
| 99 | + (struct.get $already-exact 0 |
| 100 | + (struct.new $already-exact |
| 101 | + (local.get 0) |
| 102 | + ) |
| 103 | + ) |
| 104 | + ) |
| 105 | +) |
0 commit comments