diff options
author | Alon Zakai <azakai@google.com> | 2020-11-05 10:11:59 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-05 10:11:59 -0800 |
commit | efa6b497998dfcc2fe5b2e0f6d0904e51feb6812 (patch) | |
tree | c3fb68dbf4c348cb39e68e0adf1c3e8ae068984e | |
parent | 3e72b20c055bb3769cf0dfbc790e5822ad1894e7 (diff) | |
download | binaryen-efa6b497998dfcc2fe5b2e0f6d0904e51feb6812.tar.gz binaryen-efa6b497998dfcc2fe5b2e0f6d0904e51feb6812.tar.bz2 binaryen-efa6b497998dfcc2fe5b2e0f6d0904e51feb6812.zip |
wasm-reduce: Don't try to replace a non-number (like a reference) with a Const (#3218)
Also don't assume numbers are 32-bit.
-rw-r--r-- | src/tools/wasm-reduce.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/tools/wasm-reduce.cpp b/src/tools/wasm-reduce.cpp index 6b4483dd2..82594cd25 100644 --- a/src/tools/wasm-reduce.cpp +++ b/src/tools/wasm-reduce.cpp @@ -1039,7 +1039,12 @@ struct Reducer builder->makeConstantExpression(Literal::makeZeros(curr->type)); return tryToReplaceCurrent(n); } - Const* c = builder->makeConst(int32_t(0)); + if (!curr->type.isNumber()) { + return false; + } + // It's a number: try to replace it with a 0 or a 1 (trying more values + // could make sense too, but these handle most cases). + auto* c = builder->makeConst(Literal::makeZero(curr->type)); if (tryToReplaceCurrent(c)) { return true; } |