Skip to content

Commit 6e9e38a

Browse files
committed
1
1 parent 89a95dd commit 6e9e38a

6 files changed

Lines changed: 37 additions & 16 deletions

File tree

.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
@@ -23,5 +23,3 @@ autoNoType
2323
bailoutUninitVar
2424

2525
*:externals/*/*
26-
27-
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;
@@ -1093,6 +1101,13 @@ void CmdLineParser::printHelp()
10931101
" execute clang/clang-tidy/addons.\n"
10941102
" --check-config Check cppcheck configuration. The normal code\n"
10951103
" analysis is disabled by this flag.\n"
1104+
" --check-level=<level>\n"
1105+
" Configure how much checking you want:\n"
1106+
" * normal: Cppcheck uses some compromises in the checking so\n"
1107+
" the checking will finish in reasonable time.\n"
1108+
" * exhaustive: deeper analysis that you choose when you can\n"
1109+
" wait.\n"
1110+
" The default choice is 'normal'.\n"
10961111
" --check-library Show information messages when library files have\n"
10971112
" incomplete info.\n"
10981113
" --clang=<path> Experimental: Use Clang parser instead of the builtin Cppcheck\n"
@@ -1215,12 +1230,6 @@ void CmdLineParser::printHelp()
12151230
" is 2. A larger value will mean more errors can be found\n"
12161231
" but also means the analysis will be slower.\n"
12171232
" --output-file=<file> Write results to file, rather than standard error.\n"
1218-
" --performance-valueflow-max-if-count=<limit>\n"
1219-
" If you have many conditional scopes in a function then\n"
1220-
" the number of possible control flow paths through that\n"
1221-
" function explodes and that can lead to very long analysis\n"
1222-
" time. Valueflow is limited in functions that have more\n"
1223-
" than <limit> conditional scopes.\n"
12241233
" --platform=<type>, --platform=<file>\n"
12251234
" Specifies platform specific types and sizes. The\n"
12261235
" available builtin platforms are:\n"

lib/settings.cpp

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

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

lib/settings.h

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

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

260260
/** @brief plist output (--plist-output=&lt;dir&gt;) */
261261
std::string plistOutput;
@@ -439,6 +439,9 @@ class CPPCHECKLIB Settings {
439439

440440
void loadSummaries();
441441

442+
void setCheckLevelExhaustive();
443+
void setCheckLevelNormal();
444+
442445
private:
443446
static std::string parseEnabled(const std::string &str, std::tuple<SimpleEnableGroup<Severity::SeverityType>, SimpleEnableGroup<Checks>> &groups);
444447
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)