@@ -228,6 +228,8 @@ struct FunctionValidator : public WalkerPass<PostWalker<FunctionValidator>> {
228228 void visitCallIndirect (CallIndirect *curr);
229229 void visitGetLocal (GetLocal* curr);
230230 void visitSetLocal (SetLocal *curr);
231+ void visitGetGlobal (GetGlobal* curr);
232+ void visitSetGlobal (SetGlobal *curr);
231233 void visitLoad (Load *curr);
232234 void visitStore (Store *curr);
233235 void visitAtomicRMW (AtomicRMW *curr);
@@ -470,6 +472,7 @@ void FunctionValidator::visitCallIndirect(CallIndirect *curr) {
470472}
471473
472474void FunctionValidator::visitGetLocal (GetLocal* curr) {
475+ shouldBeTrue (curr->index < getFunction ()->getNumLocals (), curr, " get_local index must be small enough" );
473476 shouldBeTrue (isConcreteWasmType (curr->type ), curr, " get_local must have a valid type - check what you provided when you constructed the node" );
474477}
475478
@@ -483,6 +486,19 @@ void FunctionValidator::visitSetLocal(SetLocal *curr) {
483486 }
484487}
485488
489+ void FunctionValidator::visitGetGlobal (GetGlobal* curr) {
490+ if (!info.validateGlobally ) return ;
491+ shouldBeTrue (getModule ()->getGlobalOrNull (curr->name ) || getModule ()->getImportOrNull (curr->name ), curr, " get_global name must be valid" );
492+ }
493+
494+ void FunctionValidator::visitSetGlobal (SetGlobal *curr) {
495+ if (!info.validateGlobally ) return ;
496+ auto * global = getModule ()->getGlobalOrNull (curr->name );
497+ shouldBeTrue (global, curr, " set_global name must be valid (and not an import; imports can't be modified)" );
498+ shouldBeTrue (global->mutable_ , curr, " set_global global must be mutable" );
499+ shouldBeEqualOrFirstIsUnreachable (curr->value ->type , global->type , curr, " set_global value must have right type" );
500+ }
501+
486502void FunctionValidator::visitLoad (Load *curr) {
487503 if (curr->isAtomic ) shouldBeTrue (info.features & Feature::Atomics, curr, " Atomic operation (atomics are disabled)" );
488504 shouldBeFalse (curr->isAtomic && !getModule ()->memory .shared , curr, " Atomic operation with non-shared memory" );
0 commit comments