summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-10-09 19:51:22 -0700
committerGitHub <noreply@github.com>2020-10-09 19:51:22 -0700
commitcaf624d0b1b81cf93cfb66dfdb50f49c5cc51578 (patch)
treecdb61ee8ddd3f6008e30ccd2c0f700aa421d9afb /src
parent399cb3df1e2e053fc601ed77744d41fe2378e54c (diff)
downloadbinaryen-caf624d0b1b81cf93cfb66dfdb50f49c5cc51578.tar.gz
binaryen-caf624d0b1b81cf93cfb66dfdb50f49c5cc51578.tar.bz2
binaryen-caf624d0b1b81cf93cfb66dfdb50f49c5cc51578.zip
RemoveUnusedBrs fuzz fix for switches with a single target and with a value (#3220)
We turn a br_table with a single target into a br, but we reverse the order of the condition and the value when doing so, which we forgot to take into account.
Diffstat (limited to 'src')
-rw-r--r--src/passes/RemoveUnusedBrs.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp
index 2238e9e95..0a3374c4d 100644
--- a/src/passes/RemoveUnusedBrs.cpp
+++ b/src/passes/RemoveUnusedBrs.cpp
@@ -828,11 +828,18 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
void visitSwitch(Switch* curr) {
if (BranchUtils::getUniqueTargets(curr).size() == 1) {
- // This switch has just one target no matter what; replace with a br.
- Builder builder(*getModule());
- replaceCurrent(builder.makeSequence(
- builder.makeDrop(curr->condition), // might have side effects
- builder.makeBreak(curr->default_, curr->value)));
+ // This switch has just one target no matter what; replace with a br
+ // if we can (to do so, we must put the condition before a possible
+ // value).
+ if (!curr->value || EffectAnalyzer::canReorder(passOptions,
+ getModule()->features,
+ curr->condition,
+ curr->value)) {
+ Builder builder(*getModule());
+ replaceCurrent(builder.makeSequence(
+ builder.makeDrop(curr->condition), // might have side effects
+ builder.makeBreak(curr->default_, curr->value)));
+ }
}
}