diff options
author | Alon Zakai <azakai@google.com> | 2019-07-01 19:22:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-01 19:22:08 -0700 |
commit | c3e45d4e5272486fae1ffb353c56e4d117fe4a21 (patch) | |
tree | a05826cdb1b587d1df7ec67cbc8c075635e064ac /src/passes/Precompute.cpp | |
parent | be3135ca8db88ed7445dc2dd12ea78f55d963c7d (diff) | |
download | binaryen-c3e45d4e5272486fae1ffb353c56e4d117fe4a21.tar.gz binaryen-c3e45d4e5272486fae1ffb353c56e4d117fe4a21.tar.bz2 binaryen-c3e45d4e5272486fae1ffb353c56e4d117fe4a21.zip |
Limit interpreter depth in precompute, but not when running whole modules (#2191)
Keep limiting in precompute as before: that is useful since that pass is run as part of normal compilation, and we want to avoid native stack limits on all platforms. Also that pass is not likely to find any pattern of size 50 of higher that it can't precompute as a sum of smaller pieces.
Restore the 250 limit from before for interpreting entire modules, as without that the fuzzer will sometimes hit the limit and cause a false positive.
Diffstat (limited to 'src/passes/Precompute.cpp')
-rw-r--r-- | src/passes/Precompute.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/passes/Precompute.cpp b/src/passes/Precompute.cpp index 2e8c8fe31..a7edb54c9 100644 --- a/src/passes/Precompute.cpp +++ b/src/passes/Precompute.cpp @@ -41,6 +41,12 @@ namespace wasm { static const Name NOTPRECOMPUTABLE_FLOW("Binaryen|notprecomputable"); +// Limit evaluation depth for 2 reasons: first, it is highly unlikely +// that we can do anything useful to precompute a hugely nested expression +// (we should succed at smaller parts of it first). Second, a low limit is +// helpful to avoid platform differences in native stack sizes. +static const Index MAX_DEPTH = 50; + typedef std::unordered_map<LocalGet*, Literal> GetValues; // Precomputes an expression. Errors if we hit anything that can't be @@ -63,8 +69,8 @@ public: PrecomputingExpressionRunner(Module* module, GetValues& getValues, bool replaceExpression) - : module(module), getValues(getValues), - replaceExpression(replaceExpression) {} + : ExpressionRunner<PrecomputingExpressionRunner>(MAX_DEPTH), module(module), + getValues(getValues), replaceExpression(replaceExpression) {} struct NonstandaloneException { }; // TODO: use a flow with a special name, as this is likely very slow |