summaryrefslogtreecommitdiff
path: root/src/ir/possible-contents.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-08-08 11:38:00 -0700
committerGitHub <noreply@github.com>2022-08-08 11:38:00 -0700
commitec7af8390fb19fff06f2c5a385285370455d810a (patch)
treeb7a8926358677398203df9aadb863afae1c69d64 /src/ir/possible-contents.cpp
parent708bc424fcf6398c700dd6d209c6c55ff6f9e2e9 (diff)
downloadbinaryen-ec7af8390fb19fff06f2c5a385285370455d810a.tar.gz
binaryen-ec7af8390fb19fff06f2c5a385285370455d810a.tar.bz2
binaryen-ec7af8390fb19fff06f2c5a385285370455d810a.zip
[GUFA] Fix readFromData on a function literal (#4883)
A function literal (ref.func) should never reach a struct or array get, but if there is a cast then it can look like they might arrive. We filter in ref.cast which avoids that (since casting a function to a data type will trap), but there is also br_on_cast which is not yet optimized. This PR adds code to avoid an assert in readFromData in that case.
Diffstat (limited to 'src/ir/possible-contents.cpp')
-rw-r--r--src/ir/possible-contents.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/ir/possible-contents.cpp b/src/ir/possible-contents.cpp
index 48a632576..7079a9446 100644
--- a/src/ir/possible-contents.cpp
+++ b/src/ir/possible-contents.cpp
@@ -1564,6 +1564,15 @@ void Flower::readFromData(HeapType declaredHeapType,
return;
}
+ if (refContents.isLiteral()) {
+ // The only reference literals we have are nulls (handled above) and
+ // ref.func. ref.func will trap in struct|array.get, so nothing will be read
+ // here (when we finish optimizing all instructions like BrOn then
+ // ref.funcs should get filtered out before arriving here TODO).
+ assert(refContents.getType().isFunction());
+ return;
+ }
+
#if defined(POSSIBLE_CONTENTS_DEBUG) && POSSIBLE_CONTENTS_DEBUG >= 2
std::cout << " add special reads\n";
#endif
@@ -1586,12 +1595,6 @@ void Flower::readFromData(HeapType declaredHeapType,
// represent them as ExactType).
// See the test TODO with text "We optimize some of this, but stop at
// reading from the immutable global"
- // Note that this cannot be a Literal, since this is a reference, and the
- // only reference literals we have are nulls (handled above) and ref.func.
- // ref.func is not valid in struct|array.get, so the code would trap at
- // runtime, and also it would never reach here as because of wasm validation
- // it would be cast to a struct/array type, and our special ref.cast code
- // would filter it out.
assert(refContents.isMany() || refContents.isGlobal());
// We create a ConeReadLocation for the canonical cone of this type, to