@@ -506,15 +506,11 @@ namespace {
506506 Outcome outer = std::move (parted);
507507 parted = Outcome{};
508508 const Progress p = updateRange (endBlock->link (), endBlock, depth);
509- const Branch branch = resolve (endBlock, outcome (p) );
509+ const Outcome paths = outcome (p);
510510 outer.add (parted, false );
511511 parted = std::move (outer);
512512 actions |= outerActions;
513- return branch;
514- }
515513
516- Branch resolve (Token* endBlock, const Outcome& paths) const
517- {
518514 Branch branch{endBlock};
519515 branch.action = paths.action ;
520516 branch.reachesEnd = paths.reached > 0 ;
@@ -528,13 +524,13 @@ namespace {
528524 branch.escapeUnknown = !structuralEscape || structuralUnknown;
529525 if (branch.escapeUnknown )
530526 branch.action |= analyzeScope (endBlock);
531- return branch;
527+ } else {
528+ // Detect an escape the paths did not flag (e.g. an unknown noreturn call);
529+ // escapeUnknown reports a possible (unknown) escape.
530+ branch.escape = isEscapeScope (endBlock, branch.escapeUnknown );
531+ if (paths.unwalked ())
532+ branch.action |= analyzeScope (endBlock);
532533 }
533- // Detect an escape the paths did not flag (e.g. an unknown noreturn call);
534- // escapeUnknown reports a possible (unknown) escape.
535- branch.escape = isEscapeScope (endBlock, branch.escapeUnknown );
536- if (paths.unwalked ())
537- branch.action |= analyzeScope (endBlock);
538534 return branch;
539535 }
540536
@@ -581,6 +577,29 @@ namespace {
581577 parted = std::move (paths);
582578 }
583579
580+ // Walk a block on a fork of this traversal, on which the condition holds
581+ Branch updateForkedBranch (ForwardTraversal& ft, const Token* condTok, Token* endBlock, int depth, bool split)
582+ {
583+ ft.actions = actions;
584+ if (split) {
585+ ++(*forkBudget);
586+ ++ft.forkDepth ;
587+ }
588+ ft.analyzer ->assume (condTok, true , Analyzer::Assume::Pending);
589+ Branch branch = ft.updateBranch (endBlock, depth);
590+ branch.traversal = &ft;
591+ branch.condTok = condTok;
592+ // The branch limit counts the branches on the way past the block, as it does for this path
593+ ft.branchCount = branchCount;
594+ // A path that stopped in the block is covered if this path goes on for it
595+ Outcome stops = std::move (ft.parted );
596+ ft.parted = Outcome{};
597+ if (!branch.reachesEnd )
598+ stops.stop (ft.actions , ft.terminate );
599+ parted.add (stops, !split);
600+ return branch;
601+ }
602+
584603 // Neither outcome of the condition is known: the then block is walked on a fork, the else
585604 // block on this traversal.
586605 Progress updateBothBranches (const Token* condTok, Token* thenEnd, Token* elseEnd, const Token* end, int depth, bool split)
@@ -591,23 +610,7 @@ namespace {
591610 // or correlated condition (e.g. 'if (f(x))') it does not, so the fork is analyze-only: the
592611 // block's effect is still tracked but nothing is reported in it.
593612 ForwardTraversal ft = fork (!analyzer->updateScope (thenEnd, false ));
594- ft.actions = actions;
595- if (split) {
596- ++(*forkBudget);
597- ++ft.forkDepth ;
598- }
599- ft.analyzer ->assume (condTok, true , Analyzer::Assume::Pending);
600- Branch thenBranch = ft.updateBranch (thenEnd, depth - 1 );
601- thenBranch.traversal = &ft;
602- thenBranch.condTok = condTok;
603- // The branch limit counts the branches on the way past the if, as it does for this path
604- ft.branchCount = branchCount;
605- // A path that stopped in the then block is covered if this path goes on for it
606- Outcome thenStops = std::move (ft.parted );
607- ft.parted = Outcome{};
608- if (!thenBranch.reachesEnd )
609- thenStops.stop (ft.actions , ft.terminate );
610- parted.add (thenStops, !split);
613+ const Branch thenBranch = updateForkedBranch (ft, condTok, thenEnd, depth - 1 , split);
611614
612615 // The condition is an assumption on this path if the then path drops the value. If the
613616 // then path goes on past the if, the value is the same with and without it. Otherwise
0 commit comments