Skip to content

Commit 35e435a

Browse files
authored
[test] Test elem offsets with extended const exprs (#18)
1 parent 45598f0 commit 35e435a

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

test/core/elem.wast

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,3 +699,60 @@
699699
)
700700

701701
(assert_return (invoke "call_imported_elem") (i32.const 42))
702+
703+
;; Extended contant expressions
704+
705+
(module
706+
(table 10 funcref)
707+
(func (result i32) (i32.const 42))
708+
(func (export "call_in_table") (param i32) (result i32)
709+
(call_indirect (type 0) (local.get 0)))
710+
(elem (table 0) (offset (i32.add (i32.const 1) (i32.const 2))) funcref (ref.func 0))
711+
)
712+
713+
(assert_return (invoke "call_in_table" (i32.const 3)) (i32.const 42))
714+
(assert_trap (invoke "call_in_table" (i32.const 0)) "uninitialized element")
715+
716+
(module
717+
(table 10 funcref)
718+
(func (result i32) (i32.const 42))
719+
(func (export "call_in_table") (param i32) (result i32)
720+
(call_indirect (type 0) (local.get 0)))
721+
(elem (table 0) (offset (i32.sub (i32.const 2) (i32.const 1))) funcref (ref.func 0))
722+
)
723+
724+
(assert_return (invoke "call_in_table" (i32.const 1)) (i32.const 42))
725+
(assert_trap (invoke "call_in_table" (i32.const 0)) "uninitialized element")
726+
727+
(module
728+
(table 10 funcref)
729+
(func (result i32) (i32.const 42))
730+
(func (export "call_in_table") (param i32) (result i32)
731+
(call_indirect (type 0) (local.get 0)))
732+
(elem (table 0) (offset (i32.mul (i32.const 2) (i32.const 2))) funcref (ref.func 0))
733+
)
734+
735+
(assert_return (invoke "call_in_table" (i32.const 4)) (i32.const 42))
736+
(assert_trap (invoke "call_in_table" (i32.const 0)) "uninitialized element")
737+
738+
;; Combining add, sub, mul and global.get
739+
740+
(module
741+
(global (import "spectest" "global_i32") i32)
742+
(table 10 funcref)
743+
(func (result i32) (i32.const 42))
744+
(func (export "call_in_table") (param i32) (result i32)
745+
(call_indirect (type 0) (local.get 0)))
746+
(elem (table 0)
747+
(offset
748+
(i32.mul
749+
(i32.const 2)
750+
(i32.add
751+
(i32.sub (global.get 0) (i32.const 665))
752+
(i32.const 2))))
753+
funcref
754+
(ref.func 0))
755+
)
756+
757+
(assert_return (invoke "call_in_table" (i32.const 6)) (i32.const 42))
758+
(assert_trap (invoke "call_in_table" (i32.const 0)) "uninitialized element")

0 commit comments

Comments
 (0)