|
| 1 | +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. |
| 2 | +;; RUN: foreach %s %t wasm-opt --memory-packing -all --zero-filled-memory -S -o - | filecheck %s |
| 3 | +;; RUN: foreach %s %t wasm-opt --memory-packing -all --zero-filled-memory -tnh -S -o - | filecheck %s --check-prefix=TNH__ |
| 4 | + |
| 5 | +;; Test that memory-packing correctly handles memory64 data segment offsets |
| 6 | +;; with the high bit set (>= 0x80000000). These must be treated as unsigned |
| 7 | +;; values, not sign-extended to 64 bits. |
| 8 | + |
| 9 | +(module |
| 10 | + ;; An active data segment at offset 0x80000000 on a memory64 with only 2 |
| 11 | + ;; pages. The offset far exceeds the memory size, so this should trap and the |
| 12 | + ;; segment must be preserved. |
| 13 | + ;; CHECK: (memory $memory i64 2 2) |
| 14 | + ;; TNH__: (memory $memory i64 2 2) |
| 15 | + (memory $memory i64 2 2) |
| 16 | + ;; CHECK: (data $data (i64.const 2147483648) "\00") |
| 17 | + (data $data (i64.const 0x80000000) "\00") |
| 18 | +) |
| 19 | + |
| 20 | +(module |
| 21 | + ;; Similar to above but with a multi-byte segment that should be shortened to |
| 22 | + ;; a single byte at the highest address to preserve the trap. |
| 23 | + ;; CHECK: (memory $memory i64 2 2) |
| 24 | + ;; TNH__: (memory $memory i64 2 2) |
| 25 | + (memory $memory i64 2 2) |
| 26 | + ;; CHECK: (data $data (i64.const 2147483650) "\00") |
| 27 | + (data $data (i64.const 0x80000000) "\00\00\00") |
| 28 | +) |
| 29 | + |
| 30 | +(module |
| 31 | + ;; Offset 0xFFFFFFFF (4GB - 1) on memory64. This is a valid i64 offset that |
| 32 | + ;; must not be confused with -1 in i32. The segment should trap. |
| 33 | + ;; CHECK: (memory $memory i64 2 2) |
| 34 | + ;; TNH__: (memory $memory i64 2 2) |
| 35 | + (memory $memory i64 2 2) |
| 36 | + ;; CHECK: (data $data (i64.const 4294967295) "\00") |
| 37 | + (data $data (i64.const 0xFFFFFFFF) "\00") |
| 38 | +) |
| 39 | + |
| 40 | +(module |
| 41 | + ;; A memory64 with enough pages that offset 0x80000000 is in bounds (0x80000000 |
| 42 | + ;; = 2GB, which is 32768 pages). The segment should be removable since it's all |
| 43 | + ;; zeroes and in bounds. |
| 44 | + ;; CHECK: (memory $memory i64 32769 32769) |
| 45 | + ;; TNH__: (memory $memory i64 32769 32769) |
| 46 | + (memory $memory i64 32769 32769) |
| 47 | + (data $data (i64.const 0x80000000) "\00") |
| 48 | +) |
| 49 | + |
| 50 | +(module |
| 51 | + ;; A passive segment used with memory.init. The memory.init offset into the |
| 52 | + ;; segment is 0x80000000 (as i32), which exceeds the segment data size and |
| 53 | + ;; should cause a trap. Ensure the i32 offset is treated as unsigned (2147483648) |
| 54 | + ;; not sign-extended to a negative value. |
| 55 | + ;; CHECK: (type $0 (func)) |
| 56 | + |
| 57 | + ;; CHECK: (memory $memory i64 2 2) |
| 58 | + ;; TNH__: (type $0 (func)) |
| 59 | + |
| 60 | + ;; TNH__: (memory $memory i64 2 2) |
| 61 | + (memory $memory i64 2 2) |
| 62 | + (data $data "hello") |
| 63 | + ;; CHECK: (func $test (type $0) |
| 64 | + ;; CHECK-NEXT: (drop |
| 65 | + ;; CHECK-NEXT: (i64.const 0) |
| 66 | + ;; CHECK-NEXT: ) |
| 67 | + ;; CHECK-NEXT: (drop |
| 68 | + ;; CHECK-NEXT: (i32.const -2147483648) |
| 69 | + ;; CHECK-NEXT: ) |
| 70 | + ;; CHECK-NEXT: (drop |
| 71 | + ;; CHECK-NEXT: (i32.const 1) |
| 72 | + ;; CHECK-NEXT: ) |
| 73 | + ;; CHECK-NEXT: (unreachable) |
| 74 | + ;; CHECK-NEXT: ) |
| 75 | + ;; TNH__: (func $test (type $0) |
| 76 | + ;; TNH__-NEXT: (drop |
| 77 | + ;; TNH__-NEXT: (i64.const 0) |
| 78 | + ;; TNH__-NEXT: ) |
| 79 | + ;; TNH__-NEXT: (drop |
| 80 | + ;; TNH__-NEXT: (i32.const -2147483648) |
| 81 | + ;; TNH__-NEXT: ) |
| 82 | + ;; TNH__-NEXT: (drop |
| 83 | + ;; TNH__-NEXT: (i32.const 1) |
| 84 | + ;; TNH__-NEXT: ) |
| 85 | + ;; TNH__-NEXT: (unreachable) |
| 86 | + ;; TNH__-NEXT: ) |
| 87 | + (func $test |
| 88 | + (memory.init $data |
| 89 | + (i64.const 0) |
| 90 | + (i32.const 0x80000000) |
| 91 | + (i32.const 1) |
| 92 | + ) |
| 93 | + ) |
| 94 | +) |
| 95 | + |
| 96 | +(module |
| 97 | + ;; A passive segment where memory.init size has the high bit set. |
| 98 | + ;; Size 0x80000000 (2147483648) exceeds the segment data size (5) and should |
| 99 | + ;; trap. Ensure the i32 size is treated as unsigned. |
| 100 | + ;; CHECK: (type $0 (func)) |
| 101 | + |
| 102 | + ;; CHECK: (memory $memory i64 2 2) |
| 103 | + ;; TNH__: (type $0 (func)) |
| 104 | + |
| 105 | + ;; TNH__: (memory $memory i64 2 2) |
| 106 | + (memory $memory i64 2 2) |
| 107 | + (data $data "hello") |
| 108 | + ;; CHECK: (func $test (type $0) |
| 109 | + ;; CHECK-NEXT: (drop |
| 110 | + ;; CHECK-NEXT: (i64.const 0) |
| 111 | + ;; CHECK-NEXT: ) |
| 112 | + ;; CHECK-NEXT: (drop |
| 113 | + ;; CHECK-NEXT: (i32.const 0) |
| 114 | + ;; CHECK-NEXT: ) |
| 115 | + ;; CHECK-NEXT: (drop |
| 116 | + ;; CHECK-NEXT: (i32.const -2147483648) |
| 117 | + ;; CHECK-NEXT: ) |
| 118 | + ;; CHECK-NEXT: (unreachable) |
| 119 | + ;; CHECK-NEXT: ) |
| 120 | + ;; TNH__: (func $test (type $0) |
| 121 | + ;; TNH__-NEXT: (drop |
| 122 | + ;; TNH__-NEXT: (i64.const 0) |
| 123 | + ;; TNH__-NEXT: ) |
| 124 | + ;; TNH__-NEXT: (drop |
| 125 | + ;; TNH__-NEXT: (i32.const 0) |
| 126 | + ;; TNH__-NEXT: ) |
| 127 | + ;; TNH__-NEXT: (drop |
| 128 | + ;; TNH__-NEXT: (i32.const -2147483648) |
| 129 | + ;; TNH__-NEXT: ) |
| 130 | + ;; TNH__-NEXT: (unreachable) |
| 131 | + ;; TNH__-NEXT: ) |
| 132 | + (func $test |
| 133 | + (memory.init $data |
| 134 | + (i64.const 0) |
| 135 | + (i32.const 0) |
| 136 | + (i32.const 0x80000000) |
| 137 | + ) |
| 138 | + ) |
| 139 | +) |
0 commit comments