summaryrefslogtreecommitdiff
path: root/src/ir/LocalStructuralDominance.cpp
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-08-30 16:17:34 -0500
committerGitHub <noreply@github.com>2023-08-30 14:17:34 -0700
commit2cdc61f04ef33c5f2055f54d88dee68110a42850 (patch)
tree3e603b973abb3526a9888eb417ffbf91d3330066 /src/ir/LocalStructuralDominance.cpp
parentaceaa3582c8a4d6d6084e1087a79ae0bc488f8b7 (diff)
downloadbinaryen-2cdc61f04ef33c5f2055f54d88dee68110a42850.tar.gz
binaryen-2cdc61f04ef33c5f2055f54d88dee68110a42850.tar.bz2
binaryen-2cdc61f04ef33c5f2055f54d88dee68110a42850.zip
Validate and fix up tuples with non-nullable elements (#5909)
The code validating and fixing up non-nullable locals previously did not correctly handle tuples that contained non-nullable elements, which could have resulted in invalid modules going undetected. Update the code to handle tuples and add tests.
Diffstat (limited to 'src/ir/LocalStructuralDominance.cpp')
-rw-r--r--src/ir/LocalStructuralDominance.cpp30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/ir/LocalStructuralDominance.cpp b/src/ir/LocalStructuralDominance.cpp
index cfb75e006..183ca7b3f 100644
--- a/src/ir/LocalStructuralDominance.cpp
+++ b/src/ir/LocalStructuralDominance.cpp
@@ -30,9 +30,11 @@ LocalStructuralDominance::LocalStructuralDominance(Function* func,
bool hasRefVar = false;
for (auto var : func->vars) {
- if (var.isRef()) {
- hasRefVar = true;
- break;
+ for (auto type : var) {
+ if (type.isRef()) {
+ hasRefVar = true;
+ break;
+ }
}
}
if (!hasRefVar) {
@@ -42,10 +44,13 @@ LocalStructuralDominance::LocalStructuralDominance(Function* func,
if (mode == NonNullableOnly) {
bool hasNonNullableVar = false;
for (auto var : func->vars) {
- // Check if we have any non-nullable vars at all.
- if (var.isNonNullable()) {
- hasNonNullableVar = true;
- break;
+ for (auto type : var) {
+ // Check if we have any non-nullable vars (or tuple vars with
+ // non-nullable elements) at all.
+ if (type.isNonNullable()) {
+ hasNonNullableVar = true;
+ break;
+ }
}
}
if (!hasNonNullableVar) {
@@ -70,10 +75,17 @@ LocalStructuralDominance::LocalStructuralDominance(Function* func,
}
for (Index i = func->getNumParams(); i < func->getNumLocals(); i++) {
- auto type = func->getLocalType(i);
+ auto localType = func->getLocalType(i);
+ bool interesting = false;
+ for (auto type : localType) {
+ if (type.isRef() && (mode == All || type.isNonNullable())) {
+ interesting = true;
+ break;
+ }
+ }
// Mark locals we don't need to care about as "set". We never do any
// work for such a local.
- if (!type.isRef() || (mode == NonNullableOnly && type.isNullable())) {
+ if (!interesting) {
localsSet[i] = true;
}
}