Skip to content

Commit 849eebb

Browse files
committed
valueflow-fast: Added a --check-level=fast option.
1 parent f1ddd1a commit 849eebb

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

cli/cmdlineparser.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
475475
else if (std::strncmp(argv[i], "--check-level=", 14) == 0) {
476476
Settings::CheckLevel level = Settings::CheckLevel::normal;
477477
const std::string level_s(argv[i] + 14);
478-
if (level_s == "normal")
478+
if (level_s == "fast")
479+
level = Settings::CheckLevel::fast;
480+
else if (level_s == "normal")
479481
level = Settings::CheckLevel::normal;
480482
else if (level_s == "exhaustive")
481483
level = Settings::CheckLevel::exhaustive;
@@ -1471,8 +1473,11 @@ void CmdLineParser::printHelp() const
14711473
" --check-config Check cppcheck configuration. The normal code\n"
14721474
" analysis is disabled by this flag.\n"
14731475
" --check-level=<level>\n"
1474-
" Configure how much checking you want:\n"
1475-
" * normal: Cppcheck uses some compromises in the checking so\n"
1476+
" Configure how much valueflow analysis you want:\n"
1477+
" * fast: All checkers are executed however the valueflow is\n"
1478+
" limited. Our goal is to perform as much valueflow analysis as\n"
1479+
" we can however it should take less time than parsing the file.\n"
1480+
" * normal: Cppcheck uses some compromises in the analysis so\n"
14761481
" the checking will finish in reasonable time.\n"
14771482
" * exhaustive: deeper analysis that you choose when you can\n"
14781483
" wait.\n"

lib/settings.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,16 @@ void Settings::loadSummaries()
287287

288288
void Settings::setCheckLevel(CheckLevel level)
289289
{
290-
if (level == CheckLevel::normal) {
290+
if (level == CheckLevel::fast) {
291+
// Checking should finish quickly.
292+
checkLevel = level;
293+
vfOptions.maxSubFunctionArgs = 8;
294+
vfOptions.maxIfCount = 100;
295+
vfOptions.doConditionExpressionAnalysis = false;
296+
vfOptions.maxForwardBranches = 4;
297+
vfOptions.maxIterations = 1;
298+
}
299+
else if (level == CheckLevel::normal) {
291300
// Checking should finish in reasonable time.
292301
checkLevel = level;
293302
vfOptions.maxSubFunctionArgs = 8;

lib/settings.h

+1
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ class CPPCHECKLIB WARN_UNUSED Settings {
487487
}
488488

489489
enum class CheckLevel {
490+
fast,
490491
normal,
491492
exhaustive
492493
};

lib/valueflow.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -8592,9 +8592,9 @@ static ValueFlowPassAdaptor<F> makeValueFlowPassAdaptor(const char* name, bool c
85928592
return {name, cpp, run};
85938593
}
85948594

8595-
#define VALUEFLOW_ADAPTOR(cpp, ...) \
8595+
#define VALUEFLOW_ADAPTOR(cpp, slow, ...) \
85968596
makeValueFlowPassAdaptor(#__VA_ARGS__, \
8597-
(cpp), \
8597+
(cpp), \
85988598
[](TokenList& tokenlist, \
85998599
SymbolDatabase& symboldatabase, \
86008600
ErrorLogger& errorLogger, \
@@ -8603,13 +8603,14 @@ static ValueFlowPassAdaptor<F> makeValueFlowPassAdaptor(const char* name, bool c
86038603
(void)tokenlist; \
86048604
(void)symboldatabase; \
86058605
(void)errorLogger; \
8606-
(void)settings; \
86078606
(void)skippedFunctions; \
8608-
__VA_ARGS__; \
8607+
if (!(slow) || settings.checkLevel >= Settings::CheckLevel::normal) \
8608+
__VA_ARGS__; \
86098609
})
86108610

8611-
#define VFA(...) VALUEFLOW_ADAPTOR(false, __VA_ARGS__)
8612-
#define VFA_CPP(...) VALUEFLOW_ADAPTOR(true, __VA_ARGS__)
8611+
#define VFA(...) VALUEFLOW_ADAPTOR(false, false, __VA_ARGS__)
8612+
#define VFA_CPP(...) VALUEFLOW_ADAPTOR(true, false, __VA_ARGS__)
8613+
#define VFA_SLOW(...) VALUEFLOW_ADAPTOR(false, true, __VA_ARGS__)
86138614

86148615
void ValueFlow::setValues(TokenList& tokenlist,
86158616
SymbolDatabase& symboldatabase,

0 commit comments

Comments
 (0)