Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a --check-level option #4942

Merged
merged 2 commits into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 0 additions & 2 deletions .selfcheck_suppressions
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@ autoNoType
bailoutUninitVar

*:externals/*/*

performanceValueflowMaxIfCountExceeded
21 changes: 15 additions & 6 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1093,6 +1101,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"
Expand Down Expand Up @@ -1215,12 +1230,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"
Expand Down
14 changes: 14 additions & 0 deletions lib/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Settings::Settings()
{
severity.setEnabled(Severity::error, true);
certainty.setEnabled(Certainty::normal, true);
setCheckLevelNormal();
}

void Settings::loadCppcheckCfg()
Expand Down Expand Up @@ -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;
}
5 changes: 4 additions & 1 deletion lib/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class CPPCHECKLIB Settings {
int performanceValueFlowMaxTime;

/** @brief --performance-valueflow-max-if-count=C */
int performanceValueFlowMaxIfCount = 100;
int performanceValueFlowMaxIfCount;

/** @brief plist output (--plist-output=&lt;dir&gt;) */
std::string plistOutput;
Expand Down Expand Up @@ -438,6 +438,9 @@ class CPPCHECKLIB Settings {
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);
Expand Down
7 changes: 2 additions & 5 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down