summaryrefslogtreecommitdiff
path: root/src/passes/RemoveUnusedBrs.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-07-18 11:22:08 -0700
committerGitHub <noreply@github.com>2017-07-18 11:22:08 -0700
commit0b2122d49a28f199ef7fde247e7e7a14829fa96e (patch)
treedef77ee01192fd27fca6cec61fa82c4525873ddf /src/passes/RemoveUnusedBrs.cpp
parent275c5ebafdf2860edb965d322bdad4c3e3717bea (diff)
parent2daf000f471afdcf21f784f83440bb4bdc1a9de9 (diff)
downloadbinaryen-0b2122d49a28f199ef7fde247e7e7a14829fa96e.tar.gz
binaryen-0b2122d49a28f199ef7fde247e7e7a14829fa96e.tar.bz2
binaryen-0b2122d49a28f199ef7fde247e7e7a14829fa96e.zip
Merge pull request #1100 from WebAssembly/fuzz-4
Yet more fuzz fixes
Diffstat (limited to 'src/passes/RemoveUnusedBrs.cpp')
-rw-r--r--src/passes/RemoveUnusedBrs.cpp38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp
index b725de901..9fed3e4a5 100644
--- a/src/passes/RemoveUnusedBrs.cpp
+++ b/src/passes/RemoveUnusedBrs.cpp
@@ -226,17 +226,51 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
// we need the ifTrue to break, so it cannot reach the code we want to move
if (ExpressionAnalyzer::obviouslyDoesNotFlowOut(iff->ifTrue)) {
iff->ifFalse = builder.stealSlice(block, i + 1, list.size());
+ iff->finalize();
+ block->finalize();
return true;
}
} else {
// this is already an if-else. if one side is a dead end, we can append to the other, if
// there is no returned value to concern us
assert(!isConcreteWasmType(iff->type)); // can't be, since in the middle of a block
+
+ // ensures the first node is a block, if it isn't already, and merges in the second,
+ // either as a single element or, if a block, by appending to the first block. this
+ // keeps the order of operations in place, that is, the appended element will be
+ // executed after the first node's elements
+ auto blockifyMerge = [&](Expression* any, Expression* append) -> Block* {
+ Block* block = nullptr;
+ if (any) block = any->dynCast<Block>();
+ // if the first isn't a block, or it's a block with a name (so we might
+ // branch to the end, and so can't append to it, we might skip that code!)
+ // then make a new block
+ if (!block || block->name.is()) {
+ block = builder.makeBlock(any);
+ } else {
+ assert(!isConcreteWasmType(block->type));
+ }
+ auto* other = append->dynCast<Block>();
+ if (!other) {
+ block->list.push_back(append);
+ } else {
+ for (auto* item : other->list) {
+ block->list.push_back(item);
+ }
+ }
+ block->finalize();
+ return block;
+ };
+
if (ExpressionAnalyzer::obviouslyDoesNotFlowOut(iff->ifTrue)) {
- iff->ifFalse = builder.blockifyMerge(iff->ifFalse, builder.stealSlice(block, i + 1, list.size()));
+ iff->ifFalse = blockifyMerge(iff->ifFalse, builder.stealSlice(block, i + 1, list.size()));
+ iff->finalize();
+ block->finalize();
return true;
} else if (ExpressionAnalyzer::obviouslyDoesNotFlowOut(iff->ifFalse)) {
- iff->ifTrue = builder.blockifyMerge(iff->ifTrue, builder.stealSlice(block, i + 1, list.size()));
+ iff->ifTrue = blockifyMerge(iff->ifTrue, builder.stealSlice(block, i + 1, list.size()));
+ iff->finalize();
+ block->finalize();
return true;
}
}