summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2018-01-03 17:55:30 -0800
committerGitHub <noreply@github.com>2018-01-03 17:55:30 -0800
commitbbcb50de8d60158067913e27908f43593c8c23c4 (patch)
tree2fe4d1900521fed19dc702c9e92ecc52dde5cd17 /src
parent5aee9479ca2839f5d3baf4dc34f0b6f1dec19fe3 (diff)
downloadbinaryen-bbcb50de8d60158067913e27908f43593c8c23c4.tar.gz
binaryen-bbcb50de8d60158067913e27908f43593c8c23c4.tar.bz2
binaryen-bbcb50de8d60158067913e27908f43593c8c23c4.zip
Validation fixes for #1317 (#1347)
* add get_global/set_global validation * validate get_local index * update builds * fix tests
Diffstat (limited to 'src')
-rw-r--r--src/wasm/wasm-validator.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index df88a5f32..26b8c66b6 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -228,6 +228,8 @@ public:
void visitCallIndirect(CallIndirect *curr);
void visitGetLocal(GetLocal* curr);
void visitSetLocal(SetLocal *curr);
+ void visitGetGlobal(GetGlobal* curr);
+ void visitSetGlobal(SetGlobal *curr);
void visitLoad(Load *curr);
void visitStore(Store *curr);
void visitAtomicRMW(AtomicRMW *curr);
@@ -470,6 +472,7 @@ void FunctionValidator::visitCallIndirect(CallIndirect *curr) {
}
void FunctionValidator::visitGetLocal(GetLocal* curr) {
+ shouldBeTrue(curr->index < getFunction()->getNumLocals(), curr, "get_local index must be small enough");
shouldBeTrue(isConcreteWasmType(curr->type), curr, "get_local must have a valid type - check what you provided when you constructed the node");
}
@@ -483,6 +486,19 @@ void FunctionValidator::visitSetLocal(SetLocal *curr) {
}
}
+void FunctionValidator::visitGetGlobal(GetGlobal* curr) {
+ if (!info.validateGlobally) return;
+ shouldBeTrue(getModule()->getGlobalOrNull(curr->name) || getModule()->getImportOrNull(curr->name), curr, "get_global name must be valid");
+}
+
+void FunctionValidator::visitSetGlobal(SetGlobal *curr) {
+ if (!info.validateGlobally) return;
+ auto* global = getModule()->getGlobalOrNull(curr->name);
+ shouldBeTrue(global, curr, "set_global name must be valid (and not an import; imports can't be modified)");
+ shouldBeTrue(global->mutable_, curr, "set_global global must be mutable");
+ shouldBeEqualOrFirstIsUnreachable(curr->value->type, global->type, curr, "set_global value must have right type");
+}
+
void FunctionValidator::visitLoad(Load *curr) {
if (curr->isAtomic) shouldBeTrue(info.features & Feature::Atomics, curr, "Atomic operation (atomics are disabled)");
shouldBeFalse(curr->isAtomic && !getModule()->memory.shared, curr, "Atomic operation with non-shared memory");