@@ -58,6 +58,69 @@ TEST(execute_call, call_with_arguments)
5858 EXPECT_THAT (execute (parse (wasm), 1 , {}), Result (4 ));
5959}
6060
61+ TEST (execute_call, call_void_with_zero_arguments)
62+ {
63+ /* wat2wasm
64+ (module
65+ (global $z (mut i32) (i32.const -1))
66+ (func $set
67+ (global.set $z (i32.const 1))
68+ )
69+ (func (result i32)
70+ call $set
71+ global.get $z
72+ )
73+ )
74+ */
75+ const auto wasm = from_hex (
76+ " 0061736d010000000108026000006000017f03030200010606017f01417f0b0a0f020600410124000b06001000"
77+ " 23000b" );
78+
79+ EXPECT_THAT (execute (parse (wasm), 1 , {}), Result (1 ));
80+ }
81+
82+ TEST (execute_call, call_void_with_one_argument)
83+ {
84+ /* wat2wasm
85+ (module
86+ (global $z (mut i32) (i32.const -1))
87+ (func $set (param $a i32)
88+ (global.set $z (local.get $a))
89+ )
90+ (func (result i32)
91+ (call $set (i32.const 1))
92+ global.get $z
93+ )
94+ )
95+ */
96+ const auto wasm = from_hex (
97+ " 0061736d0100000001090260017f006000017f03030200010606017f01417f0b0a11020600200024000b080041"
98+ " 01100023000b" );
99+
100+ EXPECT_THAT (execute (parse (wasm), 1 , {}), Result (1 ));
101+ }
102+
103+ TEST (execute_call, call_void_with_two_arguments)
104+ {
105+ /* wat2wasm
106+ (module
107+ (global $z (mut i32) (i32.const -1))
108+ (func $set (param $a i32) (param $b i32)
109+ (global.set $z (i32.add (local.get $a) (local.get $b)))
110+ )
111+ (func (result i32)
112+ (call $set (i32.const 2) (i32.const 3))
113+ global.get $z
114+ )
115+ )
116+ */
117+ const auto wasm = from_hex (
118+ " 0061736d01000000010a0260027f7f006000017f03030200010606017f01417f0b0a16020900200020016a2400"
119+ " 0b0a0041024103100023000b" );
120+
121+ EXPECT_THAT (execute (parse (wasm), 1 , {}), Result (2 + 3 ));
122+ }
123+
61124TEST (execute_call, call_shared_stack_space)
62125{
63126 /* wat2wasm
@@ -285,6 +348,31 @@ TEST(execute_call, imported_function_call)
285348 EXPECT_THAT (execute (*instance, 1 , {}), Result (42 ));
286349}
287350
351+ TEST (execute_call, imported_function_call_void)
352+ {
353+ /* wat2wasm
354+ (func (import "m" "foo"))
355+ (func
356+ call 0
357+ )
358+ */
359+ const auto wasm =
360+ from_hex (" 0061736d01000000010401600000020901016d03666f6f0000030201000a0601040010000b" );
361+
362+ const auto module = parse (wasm);
363+
364+ bool called = false ;
365+ const auto host_foo = [&called](Instance&, const Value*, int ) {
366+ called = true ;
367+ return Void;
368+ };
369+ const auto host_foo_type = module ->typesec [0 ];
370+
371+ auto instance = instantiate (*module , {{host_foo, host_foo_type}});
372+ execute (*instance, 1 , {});
373+ EXPECT_TRUE (called);
374+ }
375+
288376TEST (execute_call, imported_function_call_with_arguments)
289377{
290378 /* wat2wasm
0 commit comments