summaryrefslogtreecommitdiff
path: root/src/passes/Precompute.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-10-24 14:37:52 -0700
committerGitHub <noreply@github.com>2023-10-24 14:37:52 -0700
commitec8220f4aa556ce39145db13eddd84855b11f76c (patch)
treed994013922dcd35e59f043df83899e6325f36102 /src/passes/Precompute.cpp
parentba04e395508fc3414b952287d7e918d20361087e (diff)
downloadbinaryen-ec8220f4aa556ce39145db13eddd84855b11f76c.tar.gz
binaryen-ec8220f4aa556ce39145db13eddd84855b11f76c.tar.bz2
binaryen-ec8220f4aa556ce39145db13eddd84855b11f76c.zip
Fix unreachable code in LocalGraph by making it imprecise there (#6048)
Followup to #6046 - the fuzzer found we missed handling the case of the entry itself being unreachable, or of an unreachable loop later. Properly identifying unreachable code requires a flow analysis, unfortunately, so this PR gives up on that and instead allows LocalGraph to be imprecise in unreachable code. That avoids adding any overhead, but does mean the IR may be slightly confusing when debugging. It does not have any optimization downsides, however, as it only affects unreachable code. Also add a dump() impl in that file which helps debugging.
Diffstat (limited to 'src/passes/Precompute.cpp')
-rw-r--r--src/passes/Precompute.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/passes/Precompute.cpp b/src/passes/Precompute.cpp
index cddf8785f..a08848810 100644
--- a/src/passes/Precompute.cpp
+++ b/src/passes/Precompute.cpp
@@ -442,10 +442,18 @@ private:
if (getFunction()->isVar(get->index)) {
auto localType = getFunction()->getLocalType(get->index);
if (localType.isNonNullable()) {
- Fatal() << "Non-nullable local accessing the default value in "
- << getFunction()->name << " (" << get->index << ')';
+ // This is a non-nullable local that seems to read the default
+ // value at the function entry. This is either an internal error
+ // or a case of unreachable code; the latter is possible as
+ // LocalGraph is not precise in unreachable code.
+ //
+ // We cannot set zeros here (as applying them, even in
+ // unreachable code, would not validate), so just mark this as
+ // a hopeless case to ignore.
+ values = {};
+ } else {
+ curr = Literal::makeZeros(localType);
}
- curr = Literal::makeZeros(localType);
} else {
// it's a param, so it's hopeless
values = {};