Add a --check-level option (#4942)
This commit is contained in:
parent
3eeeaeffd2
commit
7726a5b5b3
|
@ -446,7 +446,7 @@ jobs:
|
|||
|
||||
- name: Self check
|
||||
run: |
|
||||
selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings"
|
||||
selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings --check-level=exhaustive"
|
||||
ec=0
|
||||
|
||||
# early exit
|
||||
|
@ -464,4 +464,4 @@ jobs:
|
|||
./cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp || ec=1
|
||||
# triage
|
||||
./cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 -DQT_CHARTS_LIB --library=qt -Itools/triage/temp -Igui tools/triage/*.cpp tools/triage/temp/*.cpp || ec=1
|
||||
exit $ec
|
||||
exit $ec
|
||||
|
|
|
@ -24,5 +24,3 @@ autoNoType
|
|||
bailoutUninitVar
|
||||
|
||||
*:externals/*/*
|
||||
|
||||
performanceValueflowMaxIfCountExceeded
|
||||
|
|
|
@ -254,6 +254,14 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
|||
else if (std::strcmp(argv[i], "--check-config") == 0)
|
||||
mSettings.checkConfiguration = true;
|
||||
|
||||
// Check code exhaustively
|
||||
else if (std::strcmp(argv[i], "--check-level=exhaustive") == 0)
|
||||
mSettings.setCheckLevelExhaustive();
|
||||
|
||||
// Check code with normal analysis
|
||||
else if (std::strcmp(argv[i], "--check-level=normal") == 0)
|
||||
mSettings.setCheckLevelNormal();
|
||||
|
||||
// Check library definitions
|
||||
else if (std::strcmp(argv[i], "--check-library") == 0) {
|
||||
mSettings.checkLibrary = true;
|
||||
|
@ -1092,6 +1100,13 @@ void CmdLineParser::printHelp()
|
|||
" execute clang/clang-tidy/addons.\n"
|
||||
" --check-config Check cppcheck configuration. The normal code\n"
|
||||
" analysis is disabled by this flag.\n"
|
||||
" --check-level=<level>\n"
|
||||
" Configure how much checking you want:\n"
|
||||
" * normal: Cppcheck uses some compromises in the checking so\n"
|
||||
" the checking will finish in reasonable time.\n"
|
||||
" * exhaustive: deeper analysis that you choose when you can\n"
|
||||
" wait.\n"
|
||||
" The default choice is 'normal'.\n"
|
||||
" --check-library Show information messages when library files have\n"
|
||||
" incomplete info.\n"
|
||||
" --clang=<path> Experimental: Use Clang parser instead of the builtin Cppcheck\n"
|
||||
|
@ -1214,12 +1229,6 @@ void CmdLineParser::printHelp()
|
|||
" is 2. A larger value will mean more errors can be found\n"
|
||||
" but also means the analysis will be slower.\n"
|
||||
" --output-file=<file> Write results to file, rather than standard error.\n"
|
||||
" --performance-valueflow-max-if-count=<limit>\n"
|
||||
" If you have many conditional scopes in a function then\n"
|
||||
" the number of possible control flow paths through that\n"
|
||||
" function explodes and that can lead to very long analysis\n"
|
||||
" time. Valueflow is limited in functions that have more\n"
|
||||
" than <limit> conditional scopes.\n"
|
||||
" --platform=<type>, --platform=<file>\n"
|
||||
" Specifies platform specific types and sizes. The\n"
|
||||
" available builtin platforms are:\n"
|
||||
|
|
|
@ -78,6 +78,7 @@ Settings::Settings()
|
|||
{
|
||||
severity.setEnabled(Severity::error, true);
|
||||
certainty.setEnabled(Certainty::normal, true);
|
||||
setCheckLevelNormal();
|
||||
}
|
||||
|
||||
void Settings::loadCppcheckCfg()
|
||||
|
@ -222,3 +223,16 @@ void Settings::loadSummaries()
|
|||
{
|
||||
Summaries::loadReturn(buildDir, summaryReturn);
|
||||
}
|
||||
|
||||
|
||||
void Settings::setCheckLevelExhaustive()
|
||||
{
|
||||
// Checking can take a little while. ~ 10 times slower than normal analysis is OK.
|
||||
performanceValueFlowMaxIfCount = -1;
|
||||
}
|
||||
|
||||
void Settings::setCheckLevelNormal()
|
||||
{
|
||||
// Checking should finish in reasonable time.
|
||||
performanceValueFlowMaxIfCount = 100;
|
||||
}
|
||||
|
|
|
@ -250,7 +250,7 @@ public:
|
|||
int performanceValueFlowMaxTime;
|
||||
|
||||
/** @brief --performance-valueflow-max-if-count=C */
|
||||
int performanceValueFlowMaxIfCount = 100;
|
||||
int performanceValueFlowMaxIfCount;
|
||||
|
||||
/** @brief plist output (--plist-output=<dir>) */
|
||||
std::string plistOutput;
|
||||
|
@ -438,6 +438,9 @@ public:
|
|||
return jobs == 1;
|
||||
}
|
||||
|
||||
void setCheckLevelExhaustive();
|
||||
void setCheckLevelNormal();
|
||||
|
||||
private:
|
||||
static std::string parseEnabled(const std::string &str, std::tuple<SimpleEnableGroup<Severity::SeverityType>, SimpleEnableGroup<Checks>> &groups);
|
||||
std::string applyEnabled(const std::string &str, bool enable);
|
||||
|
|
|
@ -9106,11 +9106,8 @@ void ValueFlow::setValues(TokenList *tokenlist, SymbolDatabase* symboldatabase,
|
|||
const std::string& functionName = functionScope->className;
|
||||
const std::list<ErrorMessage::FileLocation> callstack(1, ErrorMessage::FileLocation(functionScope->bodyStart, tokenlist));
|
||||
const ErrorMessage errmsg(callstack, tokenlist->getSourceFilePath(), Severity::information,
|
||||
"ValueFlow analysis is limited in " + functionName + " because if-count in function " +
|
||||
std::to_string(countIfScopes) + " exceeds limit " +
|
||||
std::to_string(settings->performanceValueFlowMaxIfCount) + ". The limit can be adjusted with "
|
||||
"--performance-valueflow-max-if-count. Increasing the if-count limit will likely increase the "
|
||||
"analysis time.", "performanceValueflowMaxIfCountExceeded", Certainty::normal);
|
||||
"ValueFlow analysis is limited in " + functionName + ". Use --check-level=exhaustive if full analysis is wanted.",
|
||||
"checkLevelNormal", Certainty::normal);
|
||||
errorLogger->reportErr(errmsg);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue