summaryrefslogtreecommitdiff
path: root/src/ir/struct-utils.h
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-08-18 09:14:25 -0700
committerGitHub <noreply@github.com>2022-08-18 09:14:25 -0700
commit68bf5e3790c8ca95f52c5c5758775a592e708d77 (patch)
tree11269c53340c60cf261e1ff2debf1929060ea9d8 /src/ir/struct-utils.h
parent0c9ffd618ba69128caa61583a7cd9a831fef1d98 (diff)
downloadbinaryen-68bf5e3790c8ca95f52c5c5758775a592e708d77.tar.gz
binaryen-68bf5e3790c8ca95f52c5c5758775a592e708d77.tar.bz2
binaryen-68bf5e3790c8ca95f52c5c5758775a592e708d77.zip
[Wasm GC] Fix TypeRefining on fallthrough values via tee (#4900)
A rather tricky corner case: we normally look at fallthrough values for copies of fields, so when we try to refine a field, we ignore stuff like this: a.x = b.x; That copies the same field on the same type to itself, so refining is not limited by it. But if we have something else in the middle, and that thing cannot change type, then it is a problem, like this: (struct.set (..ref..) (local.tee $temp (struct.get))) tee has the type of the local, which does not change in this pass. So we can't look at just the fallthrough here and skip the tee: after refining the field, the tee's old type might not fit in the field's new type. We could perhaps add casts to fix things up, but those may have too big a cost. For now, just ignore the fallthrough.
Diffstat (limited to 'src/ir/struct-utils.h')
-rw-r--r--src/ir/struct-utils.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/ir/struct-utils.h b/src/ir/struct-utils.h
index ba5617de6..9d02bb779 100644
--- a/src/ir/struct-utils.h
+++ b/src/ir/struct-utils.h
@@ -191,7 +191,10 @@ struct StructScanner
// (otherwise, we'd need to consider both the type actually written and the
// type of the fallthrough, somehow).
auto* fallthrough = Properties::getFallthrough(
- expr, this->getPassOptions(), *this->getModule());
+ expr,
+ this->getPassOptions(),
+ *this->getModule(),
+ static_cast<SubType*>(this)->getFallthroughBehavior());
if (fallthrough->type == expr->type) {
expr = fallthrough;
}
@@ -205,6 +208,11 @@ struct StructScanner
static_cast<SubType*>(this)->noteExpression(expr, type, index, info);
}
+ Properties::FallthroughBehavior getFallthroughBehavior() {
+ // By default, look at and use tee&br_if fallthrough values.
+ return Properties::FallthroughBehavior::AllowTeeBrIf;
+ }
+
FunctionStructValuesMap<T>& functionNewInfos;
FunctionStructValuesMap<T>& functionSetGetInfos;
};