summaryrefslogtreecommitdiff
path: root/test/lit/exec/memory-fill.wat
blob: c63dcef0c92fd62341ce2c9b6b762e35a87c8a9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
;; NOTE: Assertions have been generated by update_lit_checks.py --output=fuzz-exec and should not be edited.

;; RUN: wasm-opt %s --enable-bulk-memory --llvm-memory-copy-fill-lowering --fuzz-exec -q -o /dev/null 2>&1 | filecheck %s

;; Tests derived from bulk-memory.wast spec tests

;; memory.fill
(module
  (import "fuzzing-support" "log-i32" (func $log-i32 (param i32)))
  (memory 1)


  (func $assert_load (param i32 i32)
    (if (i32.ne (local.get 1) (i32.load8_u (local.get 0)))
    (then (unreachable)))
  )

  (func $print_memory (param i32 i32)
    (loop $loop
      (call $log-i32 (local.get 0))
      (call $log-i32 (i32.load8_u (local.get 0)))
      (local.set 0 (i32.add (local.get 0) (i32.const 1)))
      (br_if $loop (i32.ne (local.get 0) (local.get 1)))
    )
  )
  ;; basic fill test
  ;; CHECK:      [fuzz-exec] calling test1
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 1]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 2]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 3]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 4]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 1]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 255]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 2]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 255]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 3]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 255]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 4]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  (func $test1 (export "test1")
    (call $print_memory (i32.const 0) (i32.const 5))
    (memory.fill (i32.const 1) (i32.const 0xff) (i32.const 3))
    (call $print_memory (i32.const 0) (i32.const 5))
    (call $assert_load (i32.const 0) (i32.const 0))
    (call $assert_load (i32.const 1) (i32.const 0xff))
    (call $assert_load (i32.const 2) (i32.const 0xff))
    (call $assert_load (i32.const 3) (i32.const 0xff))
    (call $assert_load (i32.const 4) (i32.const 0x0))
  )
  ;; Fill value is stored as a byte
  ;; CHECK:      [fuzz-exec] calling test2
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 170]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 1]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 170]
  (func $test2 (export "test2")
    (memory.fill (i32.const 0) (i32.const 0xbbaa) (i32.const 2))
    (call $print_memory (i32.const 0) (i32.const 2))
    (call $assert_load (i32.const 0) (i32.const 0xaa))
    (call $assert_load (i32.const 1) (i32.const 0xaa))
  )
  ;; Fill all of memory
  ;; CHECK:      [fuzz-exec] calling test3
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 1]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 2]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 3]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 4]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 5]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  (func $test3 (export "test3")
    (memory.fill (i32.const 0) (i32.const 0) (i32.const 0x10000))
    ;; let's not print all of memory; just beyond what we filled before
    (call $print_memory (i32.const 0) (i32.const 6))
  )
  ;; Succeed when writing 0 bytes at the end of the region
  ;; CHECK:      [fuzz-exec] calling test4
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 1]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 2]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 3]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 4]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 5]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 6]
  ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
  (func $test4 (export "test4")
    (memory.fill (i32.const 0x10000) (i32.const 0) (i32.const 0))
    ;; let's not print all of memory; just beyond what we filled before
    (call $print_memory (i32.const 0) (i32.const 7))
  )
  ;; Writing 0 bytes outside of memory is not allowed
  ;; CHECK:      [fuzz-exec] calling test5
  ;; CHECK-NEXT: [trap out of bounds memory access in memory.fill]
  (func $test5 (export "test5")
    (memory.fill (i32.const 0x10001) (i32.const 0) (i32.const 0))
    ;; should not be reached
    (call $print_memory (i32.const 0) (i32.const 6))
  )
  ;; again we do not test negative/overflowing addresses as the spec test does.
)
;; CHECK:      [fuzz-exec] calling test1
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 1]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 2]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 3]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 4]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 1]
;; CHECK-NEXT: [LoggingExternalInterface logging 255]
;; CHECK-NEXT: [LoggingExternalInterface logging 2]
;; CHECK-NEXT: [LoggingExternalInterface logging 255]
;; CHECK-NEXT: [LoggingExternalInterface logging 3]
;; CHECK-NEXT: [LoggingExternalInterface logging 255]
;; CHECK-NEXT: [LoggingExternalInterface logging 4]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]

;; CHECK:      [fuzz-exec] calling test2
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 170]
;; CHECK-NEXT: [LoggingExternalInterface logging 1]
;; CHECK-NEXT: [LoggingExternalInterface logging 170]

;; CHECK:      [fuzz-exec] calling test3
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 1]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 2]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 3]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 4]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 5]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]

;; CHECK:      [fuzz-exec] calling test4
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 1]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 2]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 3]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 4]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 5]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 6]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]

;; CHECK:      [fuzz-exec] calling test5
;; CHECK-NEXT: [trap unreachable]
;; CHECK-NEXT: [fuzz-exec] comparing test1
;; CHECK-NEXT: [fuzz-exec] comparing test2
;; CHECK-NEXT: [fuzz-exec] comparing test3
;; CHECK-NEXT: [fuzz-exec] comparing test4
;; CHECK-NEXT: [fuzz-exec] comparing test5