@@ -8501,10 +8501,17 @@ static void valueFlowContainerSetTokValue(TokenList* tokenlist, const Settings*
85018501 }
85028502}
85038503
8504+ static const Scope* getFunctionScope (const Scope* scope) {
8505+ while (scope && scope->type != Scope::ScopeType::eFunction)
8506+ scope = scope->nestedIn ;
8507+ return scope;
8508+ }
8509+
85048510static void valueFlowContainerSize (TokenList* tokenlist,
85058511 SymbolDatabase* symboldatabase,
85068512 ErrorLogger* /* errorLogger*/ ,
8507- const Settings* settings)
8513+ const Settings* settings,
8514+ const std::set<const Scope*>& skippedFunctions)
85088515{
85098516 // declaration
85108517 for (const Variable *var : symboldatabase->variableList ()) {
@@ -8516,6 +8523,8 @@ static void valueFlowContainerSize(TokenList* tokenlist,
85168523 continue ;
85178524 if (!astIsContainer (var->nameToken ()))
85188525 continue ;
8526+ if (skippedFunctions.count (getFunctionScope (var->scope ())))
8527+ continue ;
85198528
85208529 bool known = true ;
85218530 int size = 0 ;
@@ -9077,7 +9086,7 @@ void ValueFlow::setValues(TokenList *tokenlist, SymbolDatabase* symboldatabase,
90779086 const std::uint64_t stopTime = getValueFlowStopTime (settings);
90789087
90799088 std::set<const Scope*> skippedFunctions;
9080- if (settings->performanceValueFlowMaxIfCount < 1000 ) {
9089+ if (settings->performanceValueFlowMaxIfCount > 0 ) {
90819090 for (const Scope* functionScope: symboldatabase->functionScopes ) {
90829091 int countIfScopes = 0 ;
90839092 std::vector<const Scope*> scopes{functionScope};
@@ -9093,15 +9102,17 @@ void ValueFlow::setValues(TokenList *tokenlist, SymbolDatabase* symboldatabase,
90939102 if (countIfScopes > settings->performanceValueFlowMaxIfCount ) {
90949103 skippedFunctions.emplace (functionScope);
90959104
9096- const std::string& functionName = functionScope->className ;
9097- const std::list<ErrorMessage::FileLocation> callstack (1 , ErrorMessage::FileLocation (functionScope->bodyStart , tokenlist));
9098- const ErrorMessage errmsg (callstack, tokenlist->getSourceFilePath (), Severity::information,
9099- " ValueFlow analysis is limited in " + functionName + " because if-count in function " +
9100- std::to_string (countIfScopes) + " exceeds limit " +
9101- std::to_string (settings->performanceValueFlowMaxIfCount ) + " . The limit can be adjusted with "
9102- " --performance-valueflow-max-if-count. Increasing the if-count limit will likely increase the "
9103- " analysis time." , " performanceValueflowMaxIfCountExceeded" , Certainty::normal);
9104- errorLogger->reportErr (errmsg);
9105+ if (settings->severity .isEnabled (Severity::information)) {
9106+ const std::string& functionName = functionScope->className ;
9107+ const std::list<ErrorMessage::FileLocation> callstack (1 , ErrorMessage::FileLocation (functionScope->bodyStart , tokenlist));
9108+ const ErrorMessage errmsg (callstack, tokenlist->getSourceFilePath (), Severity::information,
9109+ " ValueFlow analysis is limited in " + functionName + " because if-count in function " +
9110+ std::to_string (countIfScopes) + " exceeds limit " +
9111+ std::to_string (settings->performanceValueFlowMaxIfCount ) + " . The limit can be adjusted with "
9112+ " --performance-valueflow-max-if-count. Increasing the if-count limit will likely increase the "
9113+ " analysis time." , " performanceValueflowMaxIfCountExceeded" , Certainty::normal);
9114+ errorLogger->reportErr (errmsg);
9115+ }
91059116 }
91069117 }
91079118 }
@@ -9159,8 +9170,8 @@ void ValueFlow::setValues(TokenList *tokenlist, SymbolDatabase* symboldatabase,
91599170 valueFlowCondition (IteratorConditionHandler{}, tokenlist, symboldatabase, errorLogger, settings, skippedFunctions);
91609171 if (std::time (nullptr ) < stopTime)
91619172 valueFlowIteratorInfer (tokenlist, settings);
9162- if (std::time (nullptr ) < stopTime && skippedFunctions. empty () )
9163- valueFlowContainerSize (tokenlist, symboldatabase, errorLogger, settings);
9173+ if (std::time (nullptr ) < stopTime)
9174+ valueFlowContainerSize (tokenlist, symboldatabase, errorLogger, settings, skippedFunctions );
91649175 if (std::time (nullptr ) < stopTime)
91659176 valueFlowCondition (ContainerConditionHandler{}, tokenlist, symboldatabase, errorLogger, settings, skippedFunctions);
91669177 }
0 commit comments