@@ -358,3 +358,67 @@ TEST(validation_stack_type, unreachable_local)
358358 from_hex (" 0061736d0100000001060160017f017f030201000a0901070000420022000b" );
359359 EXPECT_THROW_MESSAGE (parse (wasm_tee_invalid), validation_error, " type mismatch" );
360360}
361+
362+ TEST (validation_stack_type, global_type_mismatch)
363+ {
364+ /* wat2wasm --no-check
365+ (global i32 (i32.const 0))
366+ (func (result i32)
367+ global.get 0
368+ i64.const 0
369+ i64.add
370+ )
371+ */
372+ const auto wasm_get =
373+ from_hex (" 0061736d010000000105016000017f030201000606017f0041000b0a09010700230042007c0b" );
374+ EXPECT_THROW_MESSAGE (parse (wasm_get), validation_error, " type mismatch" );
375+
376+ /* wat2wasm --no-check
377+ (global (mut i32) (i32.const 0))
378+ (func
379+ i64.const 0
380+ global.set 0
381+ )
382+ */
383+ const auto wasm_set =
384+ from_hex (" 0061736d01000000010401600000030201000606017f0141000b0a08010600420024000b" );
385+ EXPECT_THROW_MESSAGE (parse (wasm_set), validation_error, " type mismatch" );
386+ }
387+
388+ TEST (validation_stack_type, unreachable_global)
389+ {
390+ /* wat2wasm
391+ (global (mut i32) (i32.const 0))
392+ (func
393+ unreachable
394+ global.set 0
395+ )
396+ */
397+ const auto wasm_set =
398+ from_hex (" 0061736d01000000010401600000030201000606017f0141000b0a070105000024000b" );
399+ EXPECT_NO_THROW (parse (wasm_set));
400+
401+ /* wat2wasm
402+ (global (mut i32) (i32.const 0))
403+ (func
404+ unreachable
405+ i32.const 0
406+ global.set 0
407+ )
408+ */
409+ const auto wasm_set2 =
410+ from_hex (" 0061736d01000000010401600000030201000606017f0141000b0a0901070000410024000b" );
411+ EXPECT_NO_THROW (parse (wasm_set2));
412+
413+ /* wat2wasm --no-check
414+ (global (mut i32) (i32.const 0))
415+ (func
416+ unreachable
417+ i64.const 0
418+ global.set 0
419+ )
420+ */
421+ const auto wasm_set_invalid =
422+ from_hex (" 0061736d01000000010401600000030201000606017f0141000b0a0901070000420024000b" );
423+ EXPECT_THROW_MESSAGE (parse (wasm_set_invalid), validation_error, " type mismatch" );
424+ }
0 commit comments