Skip to content

Commit 7726a5b

Browse files
authored
Add a --check-level option (#4942)
1 parent 3eeeaef commit 7726a5b

File tree

6 files changed

+37
-16
lines changed

6 files changed

+37
-16
lines changed

.github/workflows/CI-unixish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ jobs:
446446
447447
- name: Self check
448448
run: |
449-
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"
449+
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"
450450
ec=0
451451
452452
# early exit
@@ -464,4 +464,4 @@ jobs:
464464
./cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp || ec=1
465465
# triage
466466
./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
467-
exit $ec
467+
exit $ec

.selfcheck_suppressions

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,3 @@ autoNoType
2424
bailoutUninitVar
2525

2626
*:externals/*/*
27-
28-
performanceValueflowMaxIfCountExceeded

cli/cmdlineparser.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
254254
else if (std::strcmp(argv[i], "--check-config") == 0)
255255
mSettings.checkConfiguration = true;
256256

257+
// Check code exhaustively
258+
else if (std::strcmp(argv[i], "--check-level=exhaustive") == 0)
259+
mSettings.setCheckLevelExhaustive();
260+
261+
// Check code with normal analysis
262+
else if (std::strcmp(argv[i], "--check-level=normal") == 0)
263+
mSettings.setCheckLevelNormal();
264+
257265
// Check library definitions
258266
else if (std::strcmp(argv[i], "--check-library") == 0) {
259267
mSettings.checkLibrary = true;
@@ -1092,6 +1100,13 @@ void CmdLineParser::printHelp()
10921100
" execute clang/clang-tidy/addons.\n"
10931101
" --check-config Check cppcheck configuration. The normal code\n"
10941102
" analysis is disabled by this flag.\n"
1103+
" --check-level=<level>\n"
1104+
" Configure how much checking you want:\n"
1105+
" * normal: Cppcheck uses some compromises in the checking so\n"
1106+
" the checking will finish in reasonable time.\n"
1107+
" * exhaustive: deeper analysis that you choose when you can\n"
1108+
" wait.\n"
1109+
" The default choice is 'normal'.\n"
10951110
" --check-library Show information messages when library files have\n"
10961111
" incomplete info.\n"
10971112
" --clang=<path> Experimental: Use Clang parser instead of the builtin Cppcheck\n"
@@ -1214,12 +1229,6 @@ void CmdLineParser::printHelp()
12141229
" is 2. A larger value will mean more errors can be found\n"
12151230
" but also means the analysis will be slower.\n"
12161231
" --output-file=<file> Write results to file, rather than standard error.\n"
1217-
" --performance-valueflow-max-if-count=<limit>\n"
1218-
" If you have many conditional scopes in a function then\n"
1219-
" the number of possible control flow paths through that\n"
1220-
" function explodes and that can lead to very long analysis\n"
1221-
" time. Valueflow is limited in functions that have more\n"
1222-
" than <limit> conditional scopes.\n"
12231232
" --platform=<type>, --platform=<file>\n"
12241233
" Specifies platform specific types and sizes. The\n"
12251234
" available builtin platforms are:\n"

lib/settings.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Settings::Settings()
7878
{
7979
severity.setEnabled(Severity::error, true);
8080
certainty.setEnabled(Certainty::normal, true);
81+
setCheckLevelNormal();
8182
}
8283

8384
void Settings::loadCppcheckCfg()
@@ -222,3 +223,16 @@ void Settings::loadSummaries()
222223
{
223224
Summaries::loadReturn(buildDir, summaryReturn);
224225
}
226+
227+
228+
void Settings::setCheckLevelExhaustive()
229+
{
230+
// Checking can take a little while. ~ 10 times slower than normal analysis is OK.
231+
performanceValueFlowMaxIfCount = -1;
232+
}
233+
234+
void Settings::setCheckLevelNormal()
235+
{
236+
// Checking should finish in reasonable time.
237+
performanceValueFlowMaxIfCount = 100;
238+
}

lib/settings.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class CPPCHECKLIB Settings {
250250
int performanceValueFlowMaxTime;
251251

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

255255
/** @brief plist output (--plist-output=&lt;dir&gt;) */
256256
std::string plistOutput;
@@ -438,6 +438,9 @@ class CPPCHECKLIB Settings {
438438
return jobs == 1;
439439
}
440440

441+
void setCheckLevelExhaustive();
442+
void setCheckLevelNormal();
443+
441444
private:
442445
static std::string parseEnabled(const std::string &str, std::tuple<SimpleEnableGroup<Severity::SeverityType>, SimpleEnableGroup<Checks>> &groups);
443446
std::string applyEnabled(const std::string &str, bool enable);

lib/valueflow.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9106,11 +9106,8 @@ void ValueFlow::setValues(TokenList *tokenlist, SymbolDatabase* symboldatabase,
91069106
const std::string& functionName = functionScope->className;
91079107
const std::list<ErrorMessage::FileLocation> callstack(1, ErrorMessage::FileLocation(functionScope->bodyStart, tokenlist));
91089108
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);
9109+
"ValueFlow analysis is limited in " + functionName + ". Use --check-level=exhaustive if full analysis is wanted.",
9110+
"checkLevelNormal", Certainty::normal);
91149111
errorLogger->reportErr(errmsg);
91159112
}
91169113
}

0 commit comments

Comments
 (0)