diff options
author | Alon Zakai <alonzakai@gmail.com> | 2018-11-07 10:41:05 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-07 10:41:05 -0800 |
commit | 30f0e0a6c9df43f3a70089629b6baa11688bfce4 (patch) | |
tree | c5ca79ea2ccd84df42efe19202b41aa6e6aa6213 /src | |
parent | b2070673bd4f6e4eb9eb7707bc0e64c76e9ecef7 (diff) | |
download | binaryen-30f0e0a6c9df43f3a70089629b6baa11688bfce4.tar.gz binaryen-30f0e0a6c9df43f3a70089629b6baa11688bfce4.tar.bz2 binaryen-30f0e0a6c9df43f3a70089629b6baa11688bfce4.zip |
Fix a DataFlowOpts bug (#1729)
We create some fake nodes for internal use, and were looking at one by mistake. This fixes that by
* Creating a non-ambiguous fake node, a call (which represents an unknown value properly, unlike a zero which we had before).
* Make DFO not rely on those values, if it knows a node is constant, apply those constant values.
Found by the fuzzer.
Diffstat (limited to 'src')
-rw-r--r-- | src/dataflow/graph.h | 8 | ||||
-rw-r--r-- | src/passes/DataFlowOpts.cpp | 10 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/dataflow/graph.h b/src/dataflow/graph.h index f81b4f989..57c03bb2e 100644 --- a/src/dataflow/graph.h +++ b/src/dataflow/graph.h @@ -739,13 +739,15 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { // i1 zexts are a no-op for wasm return makeUse(node->values[0]); } else if (node->isVar()) { - // Nothing valid for us to read here. - // FIXME should we have a local index to get? - return Builder(*module).makeConst(LiteralUtils::makeLiteralZero(node->wasmType)); + // Nothing valid for us to read here. Emit a call, representing an unknown + // variable value. + return Builder(*module).makeCall(FAKE_CALL, {}, node->wasmType); } else { WASM_UNREACHABLE(); // TODO } } + + const Name FAKE_CALL = "fake$dfo$call"; }; } // namespace DataFlow diff --git a/src/passes/DataFlowOpts.cpp b/src/passes/DataFlowOpts.cpp index 05e975049..e32fcb700 100644 --- a/src/passes/DataFlowOpts.cpp +++ b/src/passes/DataFlowOpts.cpp @@ -117,11 +117,11 @@ struct DataFlowOpts : public WalkerPass<PostWalker<DataFlowOpts>> { for (Index i = 0; i < node->values.size(); i++) { if (node->values[i]->isConst()) { auto* currp = getIndexPointer(expr, i); - if (!(*currp)->is<Const>()) { - // Directly represent it as a constant. - auto* c = node->values[i]->expr->dynCast<Const>(); - *currp = Builder(*getModule()).makeConst(c->value); - } + // Directly represent it as a constant. (Note that it may already be + // a constant, but for now to avoid corner cases just replace them + // all here.) + auto* c = node->values[i]->expr->dynCast<Const>(); + *currp = Builder(*getModule()).makeConst(c->value); } } // Now we know that all our DataFlow inputs are constant, and all |