3434
3535#include < algorithm>
3636#include < cassert>
37- #include < cstddef>
3837#include < cstdio>
3938#include < cstdint>
4039#include < functional>
@@ -87,11 +86,12 @@ namespace {
8786 reached += paths.reached ;
8887 }
8988 bool hasEscape () const {
90- return std::find (stops. cbegin (), stops. cend (), Analyzer::Terminate::Escape) != stops. cend ( );
89+ return contains (stops, Analyzer::Terminate::Escape);
9190 }
9291 bool allEscape () const {
93- return reached == 0 && !stops.empty () &&
94- std::count (stops.cbegin (), stops.cend (), Analyzer::Terminate::Escape) == static_cast <std::ptrdiff_t >(stops.size ());
92+ return reached == 0 && !stops.empty () && std::all_of (stops.cbegin (), stops.cend (), [](Analyzer::Terminate t) {
93+ return t == Analyzer::Terminate::Escape;
94+ });
9595 }
9696 Analyzer::Terminate worst () const {
9797 Analyzer::Terminate result = Analyzer::Terminate::None;
@@ -535,7 +535,7 @@ namespace {
535535 }
536536
537537 // The condition was evaluated: walk the one block of the if that it selects
538- Progress updateSingleIfBranch (Token* endBlock, const Token* skippedBlock, const Token* condTok, const Token* ifEnd, int depth)
538+ Progress updateSingleIfBranch (Token* endBlock, const Token* skippedBlock, const Token* condTok, int depth)
539539 {
540540 // The condition is only "known" because of an earlier assumption, so the
541541 // skipped block could still modify the value -> lower to possible
@@ -545,8 +545,8 @@ namespace {
545545 if (!endBlock) {
546546 // Record the state past the skipped block, so that the conditions evaluated later do
547547 // not each look for changes in it
548- if (ifEnd ->next ())
549- analyzer->updateState (ifEnd ->next ());
548+ if (skippedBlock ->next ())
549+ analyzer->updateState (skippedBlock ->next ());
550550 return Progress::Continue;
551551 }
552552 updateScopeState (endBlock);
@@ -606,9 +606,8 @@ namespace {
606606
607607 // Neither outcome of the condition is known: the then block is walked on a fork, the else
608608 // block on this traversal.
609- Progress updateIfBranches (const Token* condTok, Token* thenEnd, Token* elseEnd, const Token* end, bool split, int depth)
609+ Progress updateIfBranches (const Token* condTok, Token* thenEnd, Token* elseEnd, const Token* end, bool conditional, bool split, int depth)
610610 {
611- const bool conditional = stopOnCondition (condTok);
612611 Token* ifEnd = elseEnd ? elseEnd : thenEnd;
613612 // The value only flows into the then block when the condition can split it; for an opaque
614613 // or correlated condition (e.g. 'if (f(x))') it does not, so the fork is analyze-only: the
@@ -624,7 +623,7 @@ namespace {
624623 const unsigned int pending = elseEnd ? Analyzer::Assume::Pending : Analyzer::Assume::None;
625624 bool assumed = true ;
626625 if (thenBranch.isDead ())
627- analyzer->assume (condTok, false , Analyzer::Assume::None | pending);
626+ analyzer->assume (condTok, false , pending);
628627 else if (thenBranch.reachesEnd && (split || ft.isConditionFalse (condTok, thenEnd->previous ())))
629628 analyzer->assume (condTok, false , Analyzer::Assume::Quiet | Analyzer::Assume::Absolute | pending);
630629 else
@@ -868,12 +867,12 @@ namespace {
868867 return updateRange (endBlock->link (), endBlock, false , depth);
869868 }
870869
871- Progress updateAllScopePaths (Token* endBlock, int depth = 20 )
870+ void updateAllScopePaths (Token* endBlock, int depth = 20 )
872871 {
873872 if (!endBlock)
874- return Break () ;
873+ return ;
875874 updateScopeState (endBlock);
876- return updateAllPaths (endBlock->link (), endBlock, depth);
875+ updateAllPaths (endBlock->link (), endBlock, depth);
877876 }
878877
879878 // Walk this path and every path that parts from it to the end of the range
@@ -884,15 +883,14 @@ namespace {
884883
885884 // As updatePaths(), and this traversal gets the joint result of the paths. It must not go on
886885 // after the range.
887- Progress updateAllPaths (Token* start, const Token* end, int depth = 20 ) {
886+ void updateAllPaths (Token* start, const Token* end, int depth = 20 ) {
888887 const Outcome paths = updatePaths (start, end, depth);
889888 // A path that stopped without an escape was not followed to one, but the code can show
890889 // that there is no way to the end of the range
891890 const bool escapes = paths.allEscape () ||
892891 (paths.reached == 0 && paths.hasEscape () && isReturnScope (end, settings ().library ));
893892 actions = paths.action ;
894893 terminate = escapes ? Analyzer::Terminate::Escape : paths.worst ();
895- return paths.reached == 0 ? Progress::Break : Progress::Continue;
896894 }
897895
898896 /* *
@@ -1059,17 +1057,18 @@ namespace {
10591057 // Check if condition is true or false
10601058 bool checkThen, checkElse;
10611059 std::tie (checkThen, checkElse) = evalCond (condTok);
1062- if (!checkThen && !checkElse && stopOnCondition (condTok) && stopUpdates ())
1060+ const bool conditional = !checkThen && !checkElse && stopOnCondition (condTok);
1061+ if (conditional && stopUpdates ())
10631062 return Break (Analyzer::Terminate::Conditional);
10641063 Token* elseEnd = Token::simpleMatch (endBlock, " } else {" ) ? endBlock->linkAt (2 ) : nullptr ;
10651064 tok = elseEnd ? elseEnd : endBlock;
10661065 if (checkThen) {
1067- if (updateSingleIfBranch (endBlock, elseEnd, condTok, tok, depth) == Progress::Break)
1066+ if (updateSingleIfBranch (endBlock, elseEnd, condTok, depth) == Progress::Break)
10681067 return Break ();
10691068 } else if (checkElse) {
1070- if (updateSingleIfBranch (elseEnd, endBlock, condTok, tok, depth) == Progress::Break)
1069+ if (updateSingleIfBranch (elseEnd, endBlock, condTok, depth) == Progress::Break)
10711070 return Break ();
1072- } else if (updateIfBranches (condTok, endBlock, elseEnd, end, split && canFork (), depth) == Progress::Break) {
1071+ } else if (updateIfBranches (condTok, endBlock, elseEnd, end, conditional, split && canFork (), depth) == Progress::Break) {
10731072 return Break ();
10741073 }
10751074 }
0 commit comments