@@ -443,7 +443,7 @@ namespace {
443443 if (checkElse && isDoWhile &&
444444 (condTok->hasKnownIntValue () ||
445445 (!bodyAnalysis.isModified () && !condAnalysis.isModified () && condAnalysis.isRead ()))) {
446- if (updateRange (endBlock-> link (), endBlock) == Progress::Break)
446+ if (updateScope ( endBlock) == Progress::Break)
447447 return Break ();
448448 return updateRecursive (condTok);
449449 }
@@ -519,8 +519,17 @@ namespace {
519519 return updateLoop (endToken, endBlock, condTok, initTok, stepTok, true );
520520 }
521521
522- Progress updateScope (Token* endBlock) {
523- return updateRange (endBlock->link (), endBlock);
522+ Progress updateScope (Token* endBlock, int depth = 20 )
523+ {
524+ if (!endBlock)
525+ return Break ();
526+ assert (endBlock->link ());
527+ Token* ctx = endBlock->link ()->previous ();
528+ if (Token::simpleMatch (ctx, " )" ))
529+ ctx = ctx->link ()->previous ();
530+ if (ctx)
531+ analyzer->updateState (ctx);
532+ return updateRange (endBlock->link (), endBlock, depth);
524533 }
525534
526535 Progress updateRange (Token* start, const Token* end, int depth = 20 ) {
@@ -682,7 +691,7 @@ namespace {
682691 thenBranch.escape = isEscapeScope (endBlock, thenBranch.escapeUnknown );
683692 if (thenBranch.check ) {
684693 thenBranch.active = true ;
685- if (updateRange (endCond-> next (), endBlock, depth - 1 ) == Progress::Break)
694+ if (updateScope ( endBlock, depth - 1 ) == Progress::Break)
686695 return Break ();
687696 } else if (!elseBranch.check ) {
688697 thenBranch.active = true ;
@@ -694,7 +703,7 @@ namespace {
694703 elseBranch.escape = isEscapeScope (endBlock->linkAt (2 ), elseBranch.escapeUnknown );
695704 if (elseBranch.check ) {
696705 elseBranch.active = true ;
697- const Progress result = updateRange (endBlock-> tokAt ( 2 ), endBlock->linkAt (2 ), depth - 1 );
706+ const Progress result = updateScope ( endBlock->linkAt (2 ), depth - 1 );
698707 if (result == Progress::Break)
699708 return Break ();
700709 } else if (!thenBranch.check ) {
@@ -746,7 +755,7 @@ namespace {
746755 } else if (Token::simpleMatch (tok, " try {" )) {
747756 Token* endBlock = tok->next ()->link ();
748757 ForwardTraversal tryTraversal = fork ();
749- tryTraversal.updateRange (tok-> next (), endBlock, depth - 1 );
758+ tryTraversal.updateScope ( endBlock, depth - 1 );
750759 bool bail = tryTraversal.actions .isModified ();
751760 if (bail) {
752761 actions = tryTraversal.actions ;
@@ -760,7 +769,7 @@ namespace {
760769 return Break ();
761770 endBlock = endCatch->linkAt (1 );
762771 ForwardTraversal ft = fork ();
763- ft.updateRange (endBlock-> link (), endBlock, depth - 1 );
772+ ft.updateScope ( endBlock, depth - 1 );
764773 bail |= ft.terminate != Analyzer::Terminate::None || ft.actions .isModified ();
765774 }
766775 if (bail)
@@ -880,6 +889,8 @@ Analyzer::Result valueFlowGenericForward(Token* start, const Token* end, const V
880889 if (a->invalid ())
881890 return Analyzer::Result{Analyzer::Action::None, Analyzer::Terminate::Bail};
882891 ForwardTraversal ft{a, settings};
892+ if (start)
893+ ft.analyzer ->updateState (start);
883894 ft.updateRange (start, end);
884895 return Analyzer::Result{ ft.actions , ft.terminate };
885896}
0 commit comments