From ba6cf2eff312a571fb1964e05aeb285c63a4772c Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sun, 30 Jun 2019 08:43:06 -0700 Subject: 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. --- src/passes/Bysyncify.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/passes/Bysyncify.cpp b/src/passes/Bysyncify.cpp index 416869194..5e2f73e5c 100644 --- a/src/passes/Bysyncify.cpp +++ b/src/passes/Bysyncify.cpp @@ -658,7 +658,10 @@ private: return iff; } auto conditionTemp = builder->addVar(func, i32); - iff->condition = builder->makeLocalTee(conditionTemp, iff->condition); + // TODO: can avoid pre if the condition is a get or a const + auto* pre = + makeMaybeSkip(builder->makeLocalSet(conditionTemp, iff->condition)); + iff->condition = builder->makeLocalGet(conditionTemp, i32); iff->condition = builder->makeBinary( OrInt32, iff->condition, builder->makeStateCheck(State::Rewinding)); iff->ifTrue = process(iff->ifTrue); @@ -674,7 +677,7 @@ private: builder->makeStateCheck(State::Rewinding)), process(otherArm)); otherIf->finalize(); - return builder->makeSequence(iff, otherIf); + return builder->makeBlock({pre, iff, otherIf}); } else if (auto* loop = curr->dynCast()) { loop->body = process(loop->body); return loop; -- cgit v1.2.3