summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-10-10 10:11:31 -0700
committerGitHub <noreply@github.com>2017-10-10 10:11:31 -0700
commitde9a8687baac9695807042d6ba4e7b47dd7c5fe9 (patch)
tree323c6bd656bf2143bcef857a9ddde11f60fcc8e2 /src
parent58d13aeef288d33fa6634e31985ae6c296d88edb (diff)
downloadbinaryen-de9a8687baac9695807042d6ba4e7b47dd7c5fe9.tar.gz
binaryen-de9a8687baac9695807042d6ba4e7b47dd7c5fe9.tar.bz2
binaryen-de9a8687baac9695807042d6ba4e7b47dd7c5fe9.zip
fix a dce fuzz bug where if changed to unreachable but didn't propagate that effect up. also add set_global support in dce (#1218)
Diffstat (limited to 'src')
-rw-r--r--src/ast/type-updating.h13
-rw-r--r--src/passes/DeadCodeElimination.cpp6
2 files changed, 18 insertions, 1 deletions
diff --git a/src/ast/type-updating.h b/src/ast/type-updating.h
index 8063b3e59..c5f1d5344 100644
--- a/src/ast/type-updating.h
+++ b/src/ast/type-updating.h
@@ -266,6 +266,19 @@ struct TypeUpdater : public ExpressionStackWalker<TypeUpdater, UnifiedExpression
}
}
}
+
+ // efficiently update the type of an if, given the data we know. this
+ // can remove a concrete type and turn the if unreachable when it is
+ // unreachable
+ void maybeUpdateTypeToUnreachable(If* curr) {
+ if (!isConcreteWasmType(curr->type)) {
+ return; // nothing concrete to change to unreachable
+ }
+ curr->finalize();
+ if (curr->type == unreachable) {
+ propagateTypesUp(curr);
+ }
+ }
};
} // namespace wasm
diff --git a/src/passes/DeadCodeElimination.cpp b/src/passes/DeadCodeElimination.cpp
index e5673a0cc..48fc4a91c 100644
--- a/src/passes/DeadCodeElimination.cpp
+++ b/src/passes/DeadCodeElimination.cpp
@@ -216,7 +216,7 @@ struct DeadCodeElimination : public WalkerPass<PostWalker<DeadCodeElimination>>
replaceCurrent(curr->condition);
}
// the if may have had a type, but can now be unreachable, which allows more reduction outside
- curr->finalize();
+ typeUpdater.maybeUpdateTypeToUnreachable(curr);
}
static void scan(DeadCodeElimination* self, Expression** currp) {
@@ -351,6 +351,10 @@ struct DeadCodeElimination : public WalkerPass<PostWalker<DeadCodeElimination>>
blockifyReachableOperands({ curr->value }, curr->type);
}
+ void visitSetGlobal(SetGlobal* curr) {
+ blockifyReachableOperands({ curr->value }, curr->type);
+ }
+
void visitLoad(Load* curr) {
blockifyReachableOperands({ curr->ptr }, curr->type);
}