Skip to content

Commit ba6cf2e

Browse files
authored
Bysyncify: fix skipping of flattened if condition (#2187)
We assigned it to a local, but didn't run maybeSkip on it. As a result, it was executed during rewinding, which broke restoring the saved value. Found by the fuzzer.
1 parent 04c55fd commit ba6cf2e

4 files changed

Lines changed: 142 additions & 51 deletions

File tree

src/passes/Bysyncify.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,10 @@ struct BysyncifyFlow : public Pass {
658658
return iff;
659659
}
660660
auto conditionTemp = builder->addVar(func, i32);
661-
iff->condition = builder->makeLocalTee(conditionTemp, iff->condition);
661+
// TODO: can avoid pre if the condition is a get or a const
662+
auto* pre =
663+
makeMaybeSkip(builder->makeLocalSet(conditionTemp, iff->condition));
664+
iff->condition = builder->makeLocalGet(conditionTemp, i32);
662665
iff->condition = builder->makeBinary(
663666
OrInt32, iff->condition, builder->makeStateCheck(State::Rewinding));
664667
iff->ifTrue = process(iff->ifTrue);
@@ -674,7 +677,7 @@ struct BysyncifyFlow : public Pass {
674677
builder->makeStateCheck(State::Rewinding)),
675678
process(otherArm));
676679
otherIf->finalize();
677-
return builder->makeSequence(iff, otherIf);
680+
return builder->makeBlock({pre, iff, otherIf});
678681
} else if (auto* loop = curr->dynCast<Loop>()) {
679682
loop->body = process(loop->body);
680683
return loop;

test/passes/bysyncify.txt

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,11 +1365,18 @@
13651365
)
13661366
)
13671367
(block
1368+
(if
1369+
(i32.eq
1370+
(global.get $__bysyncify_state)
1371+
(i32.const 0)
1372+
)
1373+
(local.set $2
1374+
(local.get $1)
1375+
)
1376+
)
13681377
(if
13691378
(i32.or
1370-
(local.tee $2
1371-
(local.get $1)
1372-
)
1379+
(local.get $2)
13731380
(i32.eq
13741381
(global.get $__bysyncify_state)
13751382
(i32.const 2)
@@ -1616,11 +1623,18 @@
16161623
)
16171624
)
16181625
(block
1626+
(if
1627+
(i32.eq
1628+
(global.get $__bysyncify_state)
1629+
(i32.const 0)
1630+
)
1631+
(local.set $4
1632+
(local.get $1)
1633+
)
1634+
)
16191635
(if
16201636
(i32.or
1621-
(local.tee $4
1622-
(local.get $1)
1623-
)
1637+
(local.get $4)
16241638
(i32.eq
16251639
(global.get $__bysyncify_state)
16261640
(i32.const 2)
@@ -1856,11 +1870,18 @@
18561870
)
18571871
)
18581872
(block
1873+
(if
1874+
(i32.eq
1875+
(global.get $__bysyncify_state)
1876+
(i32.const 0)
1877+
)
1878+
(local.set $4
1879+
(local.get $1)
1880+
)
1881+
)
18591882
(if
18601883
(i32.or
1861-
(local.tee $4
1862-
(local.get $1)
1863-
)
1884+
(local.get $4)
18641885
(i32.eq
18651886
(global.get $__bysyncify_state)
18661887
(i32.const 2)

0 commit comments

Comments
 (0)