summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Wirtz <dcode@dcode.io>2020-09-25 10:10:56 +0200
committerGitHub <noreply@github.com>2020-09-25 10:10:56 +0200
commit46d2cbab48ebbc8c9aab3f285cc42b2544bb526a (patch)
treef34c609750bd2b041aaaefafe874eefcb84ab1ce /src
parentfadf01842175202f59340f8c7093a090962e2269 (diff)
downloadbinaryen-46d2cbab48ebbc8c9aab3f285cc42b2544bb526a.tar.gz
binaryen-46d2cbab48ebbc8c9aab3f285cc42b2544bb526a.tar.bz2
binaryen-46d2cbab48ebbc8c9aab3f285cc42b2544bb526a.zip
Fix missing feature validations (#3171)
Instructions `ref.null`, `ref.is_null`, `ref.func`, `try`, `throw`, `rethrow` and `br_on_exn` were previously missing explicit feature checks, and this change adds them. Note that some of these already didn't validate before for other reasons, like requiring the use of a type checked otherwise, but `ref.null` and `try` validated even in context of FeatureSet::MVP, so better to be sure.
Diffstat (limited to 'src')
-rw-r--r--src/wasm/wasm-validator.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index d55f60009..2a4c19732 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -328,6 +328,7 @@ public:
void visitReturn(Return* curr);
void visitMemorySize(MemorySize* curr);
void visitMemoryGrow(MemoryGrow* curr);
+ void visitRefNull(RefNull* curr);
void visitRefIsNull(RefIsNull* curr);
void visitRefFunc(RefFunc* curr);
void visitRefEq(RefEq* curr);
@@ -1948,7 +1949,16 @@ void FunctionValidator::visitMemoryGrow(MemoryGrow* curr) {
"memory.grow must match memory index type");
}
+void FunctionValidator::visitRefNull(RefNull* curr) {
+ shouldBeTrue(getModule()->features.hasReferenceTypes(),
+ curr,
+ "ref.null requires reference-types to be enabled");
+}
+
void FunctionValidator::visitRefIsNull(RefIsNull* curr) {
+ shouldBeTrue(getModule()->features.hasReferenceTypes(),
+ curr,
+ "ref.is_null requires reference-types to be enabled");
shouldBeTrue(curr->value->type == Type::unreachable ||
curr->value->type.isRef(),
curr->value,
@@ -1956,6 +1966,9 @@ void FunctionValidator::visitRefIsNull(RefIsNull* curr) {
}
void FunctionValidator::visitRefFunc(RefFunc* curr) {
+ shouldBeTrue(getModule()->features.hasReferenceTypes(),
+ curr,
+ "ref.func requires reference-types to be enabled");
auto* func = getModule()->getFunctionOrNull(curr->func);
shouldBeTrue(!!func, curr, "function argument of ref.func must exist");
}
@@ -1976,6 +1989,9 @@ void FunctionValidator::visitRefEq(RefEq* curr) {
}
void FunctionValidator::visitTry(Try* curr) {
+ shouldBeTrue(getModule()->features.hasExceptionHandling(),
+ curr,
+ "try requires exception-handling to be enabled");
if (curr->type != Type::unreachable) {
shouldBeSubTypeOrFirstIsUnreachable(
curr->body->type,
@@ -2000,6 +2016,9 @@ void FunctionValidator::visitTry(Try* curr) {
}
void FunctionValidator::visitThrow(Throw* curr) {
+ shouldBeTrue(getModule()->features.hasExceptionHandling(),
+ curr,
+ "throw requires exception-handling to be enabled");
if (!info.validateGlobally) {
return;
}
@@ -2030,6 +2049,9 @@ void FunctionValidator::visitThrow(Throw* curr) {
}
void FunctionValidator::visitRethrow(Rethrow* curr) {
+ shouldBeTrue(getModule()->features.hasExceptionHandling(),
+ curr,
+ "rethrow requires exception-handling to be enabled");
shouldBeEqual(curr->type,
Type(Type::unreachable),
curr,
@@ -2042,6 +2064,9 @@ void FunctionValidator::visitRethrow(Rethrow* curr) {
}
void FunctionValidator::visitBrOnExn(BrOnExn* curr) {
+ shouldBeTrue(getModule()->features.hasExceptionHandling(),
+ curr,
+ "br_on_exn requires exception-handling to be enabled");
Event* event = getModule()->getEventOrNull(curr->event);
shouldBeTrue(event != nullptr, curr, "br_on_exn's event must exist");
shouldBeTrue(event->sig.params == curr->sent,