summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tools/wasm-reduce.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/tools/wasm-reduce.cpp b/src/tools/wasm-reduce.cpp
index 40ad58115..a0126e80d 100644
--- a/src/tools/wasm-reduce.cpp
+++ b/src/tools/wasm-reduce.cpp
@@ -476,16 +476,26 @@ struct Reducer
void visitExpression(Expression* curr) {
if (getFunction() && curr == getFunction()->body) {
- // At the top level, we can try to reduce anything to an unreachable, and
- // it is useful to do so when possible.
+ // At the top level, we can try to reduce anything to an unreachable or a
+ // nop, and it is useful to do so when possible.
if (!curr->is<Unreachable>() && !curr->is<Nop>() &&
shouldTryToReduce(1000)) {
auto* save = curr;
Unreachable un;
- replaceCurrent(&un);
+ Nop nop;
+ bool useUnreachable = getFunction()->sig.results != Type::none;
+ if (useUnreachable) {
+ replaceCurrent(&un);
+ } else {
+ replaceCurrent(&nop);
+ }
if (writeAndTestReduction()) {
- replaceCurrent(builder->makeUnreachable());
- std::cerr << "| body unreachified (" << getFunction()->name
+ if (useUnreachable) {
+ replaceCurrent(builder->makeUnreachable());
+ } else {
+ replaceCurrent(builder->makeNop());
+ }
+ std::cerr << "| body emptied (" << getFunction()->name
<< ")\n";
noteReduction();
return;