Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Commit a21888d

Browse files
authored
[test] Add tests for validating constant expressions (#1281)
1 parent 397bb53 commit a21888d

File tree

3 files changed

+146
-0
lines changed

3 files changed

+146
-0
lines changed

test/core/data.wast

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,40 @@
359359
"type mismatch"
360360
)
361361

362+
(assert_invalid
363+
(module
364+
(memory 1)
365+
(data (offset (;empty instruction sequence;)))
366+
)
367+
"type mismatch"
368+
)
369+
370+
(assert_invalid
371+
(module
372+
(memory 1)
373+
(data (offset (i32.const 0) (i32.const 0)))
374+
)
375+
"type mismatch"
376+
)
377+
378+
(assert_invalid
379+
(module
380+
(global (import "test" "global-i32") i32)
381+
(memory 1)
382+
(data (offset (global.get 0) (global.get 0)))
383+
)
384+
"type mismatch"
385+
)
386+
387+
(assert_invalid
388+
(module
389+
(global (import "test" "global-i32") i32)
390+
(memory 1)
391+
(data (offset (global.get 0) (i32.const 0)))
392+
)
393+
"type mismatch"
394+
)
395+
362396
(assert_invalid
363397
(module
364398
(memory 1)
@@ -396,3 +430,29 @@
396430
;; (module (memory 1) (data (global.get $g)) (global $g (mut i32) (i32.const 0)))
397431
;; "constant expression required"
398432
;; )
433+
434+
(assert_invalid
435+
(module
436+
(memory 1)
437+
(data (global.get 0))
438+
)
439+
"unknown global 0"
440+
)
441+
442+
(assert_invalid
443+
(module
444+
(global (import "test" "global-i32") i32)
445+
(memory 1)
446+
(data (global.get 1))
447+
)
448+
"unknown global 1"
449+
)
450+
451+
(assert_invalid
452+
(module
453+
(global (import "test" "global-mut-i32") (mut i32))
454+
(memory 1)
455+
(data (global.get 0))
456+
)
457+
"constant expression required"
458+
)

test/core/elem.wast

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,41 @@
262262
"type mismatch"
263263
)
264264

265+
(assert_invalid
266+
(module
267+
(table 1 funcref)
268+
(elem (offset (;empty instruction sequence;)))
269+
)
270+
"type mismatch"
271+
)
272+
273+
(assert_invalid
274+
(module
275+
(table 1 funcref)
276+
(elem (offset (i32.const 0) (i32.const 0)))
277+
)
278+
"type mismatch"
279+
)
280+
281+
(assert_invalid
282+
(module
283+
(global (import "test" "global-i32") i32)
284+
(table 1 funcref)
285+
(elem (offset (global.get 0) (global.get 0)))
286+
)
287+
"type mismatch"
288+
)
289+
290+
(assert_invalid
291+
(module
292+
(global (import "test" "global-i32") i32)
293+
(table 1 funcref)
294+
(elem (offset (global.get 0) (i32.const 0)))
295+
)
296+
"type mismatch"
297+
)
298+
299+
265300
(assert_invalid
266301
(module
267302
(table 1 funcref)
@@ -300,6 +335,32 @@
300335
;; "constant expression required"
301336
;; )
302337

338+
(assert_invalid
339+
(module
340+
(table 1 funcref)
341+
(elem (global.get 0))
342+
)
343+
"unknown global 0"
344+
)
345+
346+
(assert_invalid
347+
(module
348+
(global (import "test" "global-i32") i32)
349+
(table 1 funcref)
350+
(elem (global.get 1))
351+
)
352+
"unknown global 1"
353+
)
354+
355+
(assert_invalid
356+
(module
357+
(global (import "test" "global-mut-i32") (mut i32))
358+
(table 1 funcref)
359+
(elem (global.get 0))
360+
)
361+
"constant expression required"
362+
)
363+
303364
;; Two elements target the same slot
304365

305366
(module

test/core/global.wast

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@
273273
"constant expression required"
274274
)
275275

276+
(assert_invalid
277+
(module (global i32 (i32.ctz (i32.const 0))))
278+
"constant expression required"
279+
)
280+
276281
(assert_invalid
277282
(module (global i32 (nop)))
278283
"constant expression required"
@@ -293,6 +298,16 @@
293298
"type mismatch"
294299
)
295300

301+
(assert_invalid
302+
(module (global (import "test" "global-i32") i32) (global i32 (global.get 0) (global.get 0)))
303+
"type mismatch"
304+
)
305+
306+
(assert_invalid
307+
(module (global (import "test" "global-i32") i32) (global i32 (i32.const 0) (global.get 0)))
308+
"type mismatch"
309+
)
310+
296311
(assert_invalid
297312
(module (global i32 (global.get 0)))
298313
"unknown global"
@@ -303,6 +318,16 @@
303318
"unknown global"
304319
)
305320

321+
(assert_invalid
322+
(module (global (import "test" "global-i32") i32) (global i32 (global.get 2)))
323+
"unknown global"
324+
)
325+
326+
(assert_invalid
327+
(module (global (import "test" "global-mut-i32") (mut i32)) (global i32 (global.get 0)))
328+
"constant expression required"
329+
)
330+
306331
(module
307332
(import "spectest" "global_i32" (global i32))
308333
)

0 commit comments

Comments
 (0)