@@ -156,9 +156,9 @@ namespace {
156156 bool escapeUnknown = false ;
157157 // The path that walked the block is at its end
158158 bool reachesEnd = true ;
159- // The fork that walked the block, and the condition that holds on it. Without a fork
160- // this traversal walked the block.
161- std::shared_ptr<ForwardTraversal> path;
159+ // The traversal that walked the block
160+ ForwardTraversal* traversal = nullptr ;
161+ // The condition that holds on it, if it is a fork
162162 const Token* condTok = nullptr ;
163163 bool isEscape () const {
164164 return escape || escapeUnknown;
@@ -590,24 +590,23 @@ namespace {
590590 // The value only flows into the then block when the condition can split it; for an opaque
591591 // or correlated condition (e.g. 'if (f(x))') it does not, so the fork is analyze-only: the
592592 // block's effect is still tracked but nothing is reported in it.
593- const std::shared_ptr<ForwardTraversal> ft =
594- std::make_shared<ForwardTraversal>(fork (!analyzer->updateScope (thenEnd, false )));
595- ft->actions = actions;
593+ ForwardTraversal ft = fork (!analyzer->updateScope (thenEnd, false ));
594+ ft.actions = actions;
596595 if (split) {
597596 ++(*forkBudget);
598- ++ft-> forkDepth ;
597+ ++ft. forkDepth ;
599598 }
600- ft-> analyzer ->assume (condTok, true , Analyzer::Assume::Pending);
601- Branch thenBranch = ft-> updateBranch (thenEnd, depth - 1 );
602- thenBranch.path = ft;
599+ ft. analyzer ->assume (condTok, true , Analyzer::Assume::Pending);
600+ Branch thenBranch = ft. updateBranch (thenEnd, depth - 1 );
601+ thenBranch.traversal = & ft;
603602 thenBranch.condTok = condTok;
604603 // The branch limit counts the branches on the way past the if, as it does for this path
605- ft-> branchCount = branchCount;
604+ ft. branchCount = branchCount;
606605 // A path that stopped in the then block is covered if this path goes on for it
607- Outcome thenStops = std::move (ft-> parted );
608- ft-> parted = Outcome{};
606+ Outcome thenStops = std::move (ft. parted );
607+ ft. parted = Outcome{};
609608 if (!thenBranch.reachesEnd )
610- thenStops.stop (ft-> actions , ft-> terminate );
609+ thenStops.stop (ft. actions , ft. terminate );
611610 parted.add (thenStops, !split);
612611
613612 // The condition is an assumption on this path if the then path drops the value. If the
@@ -619,7 +618,7 @@ namespace {
619618 bool assumed = true ;
620619 if (thenBranch.isDead ())
621620 analyzer->assume (condTok, false , Analyzer::Assume::None | pending);
622- else if (thenBranch.reachesEnd && (split || ft-> isConditionFalse (condTok, thenEnd->previous ())))
621+ else if (thenBranch.reachesEnd && (split || ft. isConditionFalse (condTok, thenEnd->previous ())))
623622 analyzer->assume (condTok, false , Analyzer::Assume::Quiet | Analyzer::Assume::Absolute | pending);
624623 else
625624 assumed = false ;
@@ -635,10 +634,11 @@ namespace {
635634 // at an earlier token, and every condition evaluated later looks for changes from there.
636635 analyzer->updateState (ifEnd->next ());
637636 }
637+ elseBranch.traversal = this ;
638638 return updatePastBranches ({thenBranch, elseBranch}, conditional, ifEnd->next (), end, depth, split);
639639 }
640640
641- // The blocks of a branching statement were walked, each on its fork or on this traversal.
641+ // The blocks of a branching statement were walked, each on a fork or on this traversal.
642642 // split: every path goes on to the end of the range on its own. Otherwise one path goes on
643643 // past the statement for all of them.
644644 Progress updatePastBranches (const std::vector<Branch>& branches, bool conditional, Token* next, const Token* end, int depth, bool split)
@@ -649,8 +649,8 @@ namespace {
649649 });
650650 actions |= action;
651651 const bool jumps = std::any_of (branches.cbegin (), branches.cend (), std::mem_fn (&Branch::hasGoto));
652- const bool reachesEnd = std::all_of (branches.cbegin (), branches.cend (), [](const Branch& branch) {
653- return branch.path || branch.reachesEnd ;
652+ const bool reachesEnd = std::all_of (branches.cbegin (), branches.cend (), [this ](const Branch& branch) {
653+ return branch.traversal != this || branch.reachesEnd ;
654654 });
655655 Progress progress = reachesEnd ? Progress::Continue : Progress::Break;
656656 if (reachesEnd) {
@@ -663,9 +663,9 @@ namespace {
663663 const bool forksGoOn = split || progress == Progress::Break;
664664 std::vector<ForwardTraversal*> successors;
665665 for (const Branch& branch : branches) {
666- if (! branch.path || !branch.reachesEnd )
666+ if (branch.traversal == this || !branch.reachesEnd )
667667 continue ;
668- ForwardTraversal& ft = *branch.path ;
668+ ForwardTraversal& ft = *branch.traversal ;
669669 ft.actions |= action;
670670 if (jumps) {
671671 stopFork (ft, Analyzer::Terminate::Bail);
0 commit comments