diff options
author | Ben Smith <binjimin@gmail.com> | 2018-08-15 14:26:00 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-15 14:26:00 -0700 |
commit | 33f758c6b43f52ea5d74cc9579c63e62de4ec33d (patch) | |
tree | 27ef60511ba675f1dfc8f58874903f1df29458b1 /src/validator.cc | |
parent | 0d683b182258b1e04cbbcfb319f0107b6790df36 (diff) | |
download | wabt-33f758c6b43f52ea5d74cc9579c63e62de4ec33d.tar.gz wabt-33f758c6b43f52ea5d74cc9579c63e62de4ec33d.tar.bz2 wabt-33f758c6b43f52ea5d74cc9579c63e62de4ec33d.zip |
Fix: set_global on immutable global is invalid (#895)
There is a spec test for this, but spectest-interp only runs the
validator in `binary-reader-interp.cc`, which is different than the
validator in `validator.cc`. This is necessarily so, since some
checks only make sense when the module is linked or instantiated.
This fixes issue #894.
Diffstat (limited to 'src/validator.cc')
-rw-r--r-- | src/validator.cc | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/validator.cc b/src/validator.cc index d63e6a3c..d1f8cf26 100644 --- a/src/validator.cc +++ b/src/validator.cc @@ -728,7 +728,18 @@ Result Validator::OnSelectExpr(SelectExpr* expr) { Result Validator::OnSetGlobalExpr(SetGlobalExpr* expr) { expr_loc_ = &expr->loc; - typechecker_.OnSetGlobal(GetGlobalVarTypeOrAny(&expr->var)); + Type type = Type::Any; + const Global* global; + Index global_index; + if (Succeeded(CheckGlobalVar(&expr->var, &global, &global_index))) { + if (!global->mutable_) { + PrintError(&expr->loc, + "can't set_global on immutable global at index %" PRIindex ".", + global_index); + } + type = global->type; + } + typechecker_.OnSetGlobal(type); return Result::Ok; } |