summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-03-30 15:54:44 -0700
committerGitHub <noreply@github.com>2022-03-30 15:54:44 -0700
commite7c4f9da6d4a98f58b6320b5769f653a6bf26d3e (patch)
tree917176abd4f7913cb831ca0567d597ea817c377e /src/wasm
parent247f4c20a1eea63ebe77c64e1681081b5b5de302 (diff)
downloadbinaryen-e7c4f9da6d4a98f58b6320b5769f653a6bf26d3e.tar.gz
binaryen-e7c4f9da6d4a98f58b6320b5769f653a6bf26d3e.tar.bz2
binaryen-e7c4f9da6d4a98f58b6320b5769f653a6bf26d3e.zip
[Wasm GC] Fix non-nullable tuples (#4555)
Apply the same logic to tuple fields as we do for all other fields, when checking whether a non-nullable value is valid. Fixes #4554
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-type.cpp12
-rw-r--r--src/wasm/wasm-validator.cpp8
2 files changed, 16 insertions, 4 deletions
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp
index ea4e43efe..ce823aae0 100644
--- a/src/wasm/wasm-type.cpp
+++ b/src/wasm/wasm-type.cpp
@@ -1021,6 +1021,18 @@ bool Type::isDefaultable() const {
return isConcrete() && !isNonNullable() && !isRtt();
}
+bool Type::isDefaultableOrNonNullable() const {
+ if (isTuple()) {
+ for (auto t : *this) {
+ if (!t.isDefaultableOrNonNullable()) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return isConcrete() && !isRtt();
+}
+
Nullability Type::getNullability() const {
return isNullable() ? Nullable : NonNullable;
}
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index 86fc4811b..8d35543fc 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -2728,11 +2728,11 @@ void FunctionValidator::visitFunction(Function* curr) {
shouldBeTrue(result.isConcrete(), curr, "results must be concretely typed");
}
for (const auto& var : curr->vars) {
- if (var.isRef() && getModule()->features.hasGCNNLocals()) {
- continue;
- }
features |= var.getFeatures();
- shouldBeTrue(var.isDefaultable(), var, "vars must be defaultable");
+ bool valid = getModule()->features.hasGCNNLocals()
+ ? var.isDefaultableOrNonNullable()
+ : var.isDefaultable();
+ shouldBeTrue(valid, var, "vars must be defaultable");
}
shouldBeTrue(features <= getModule()->features,
curr->name,