Skip to content

Commit f44e6e5

Browse files
committed
Fix global checking when it is for constant expressions
1 parent a274e83 commit f44e6e5

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

core/iwasm/interpreter/wasm_loader.c

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -810,14 +810,15 @@ load_init_expr(WASMModule *module, const uint8 **p_buf, const uint8 *buf_end,
810810
read_leb_uint32(p, p_end, cur_value.global_index);
811811
global_idx = cur_value.global_index;
812812

813-
#if WASM_ENABLE_GC == 0
813+
/*
814+
* Currently, constant expressions occurring as initializers
815+
* of globals are further constrained in that contained
816+
* global.get instructions are
817+
* only allowed to refer to imported globals.
818+
*
819+
* https://webassembly.github.io/spec/core/valid/instructions.html#constant-expressions
820+
*/
814821
if (global_idx >= module->import_global_count) {
815-
/**
816-
* Currently, constant expressions occurring as initializers
817-
* of globals are further constrained in that contained
818-
* global.get instructions are
819-
* only allowed to refer to imported globals.
820-
*/
821822
set_error_buf_v(error_buf, error_buf_size,
822823
"unknown global %u", global_idx);
823824
goto fail;
@@ -827,20 +828,6 @@ load_init_expr(WASMModule *module, const uint8 **p_buf, const uint8 *buf_end,
827828
"constant expression required");
828829
goto fail;
829830
}
830-
#else
831-
if (global_idx
832-
>= module->import_global_count + module->global_count) {
833-
set_error_buf_v(error_buf, error_buf_size,
834-
"unknown global %u", global_idx);
835-
goto fail;
836-
}
837-
if (global_idx < module->import_global_count
838-
&& module->import_globals[global_idx].u.global.is_mutable) {
839-
set_error_buf_v(error_buf, error_buf_size,
840-
"constant expression required");
841-
goto fail;
842-
}
843-
#endif
844831

845832
if (global_idx < module->import_global_count) {
846833
global_type =

0 commit comments

Comments
 (0)