Skip to content

Commit 70cc24e

Browse files
committed
added CLI option to disable "ifdef" bailout
1 parent 31a5db8 commit 70cc24e

6 files changed

Lines changed: 14 additions & 3 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,10 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
10221022
mSettings.cppHeaderProbe = false;
10231023
}
10241024

1025+
else if (std::strcmp(argv[i], "--no-ifdef-bailout") == 0) {
1026+
mSettings.ifdefBailout = false;
1027+
}
1028+
10251029
// Write results in file
10261030
else if (std::strncmp(argv[i], "--output-file=", 14) == 0)
10271031
mSettings.outputFile = Path::simplifyPath(argv[i] + 14);

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2368,7 +2368,7 @@ const std::set<std::string> CheckClass::stl_containers_not_const = { "map", "uno
23682368
bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, MemberAccess& memberAccessed) const
23692369
{
23702370
if (mTokenizer->hasIfdef(func->functionScope->bodyStart, func->functionScope->bodyEnd))
2371-
return false;
2371+
return false; // TODO: log bailout?
23722372

23732373
auto getFuncTok = [](const Token* tok) -> const Token* {
23742374
if (Token::simpleMatch(tok, "this"))

lib/checkcondition.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ void CheckCondition::checkBadBitmaskCheck()
331331
// If there are #ifdef in the expression don't warn about redundant | to avoid FP
332332
const auto& startStop = tok->findExpressionStartEndTokens();
333333
if (mTokenizer->hasIfdef(startStop.first, startStop.second))
334-
continue;
334+
continue; // TODO: log bailout?
335335

336336
const bool isZero1 = (tok->astOperand1()->hasKnownIntValue() && tok->astOperand1()->getKnownIntValue() == 0);
337337
const bool isZero2 = (tok->astOperand2()->hasKnownIntValue() && tok->astOperand2()->getKnownIntValue() == 0);
@@ -765,6 +765,7 @@ void CheckCondition::multiCondition2()
765765
identicalConditionAfterEarlyExitError(cond1, secondCondition, errorPath);
766766
return ChildrenToVisit::done;
767767
}
768+
// TODO: log bailout?
768769
}
769770
return ChildrenToVisit::none;
770771
});

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ void CheckOther::checkVariableScope()
11001100
continue;
11011101

11021102
if (mTokenizer->hasIfdef(var->nameToken(), var->scope()->bodyEnd))
1103-
continue;
1103+
continue; // TODO: log bailout?
11041104

11051105
// reference of range for loop variable..
11061106
if (Token::Match(var->nameToken()->previous(), "& %var% = %var% .")) {

lib/settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ class CPPCHECKLIB WARN_UNUSED Settings {
256256
/** @brief Force checking the files with "too many" configurations (--force). */
257257
bool force{};
258258

259+
/** @brief Perform bailouts when #if blocks are encountered in checks. */
260+
bool ifdefBailout{true};
261+
259262
/** @brief List of include paths, e.g. "my/includes/" which should be used
260263
for finding include files inside source files. (-I) */
261264
std::list<std::string> includePaths;

lib/tokenize.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10918,6 +10918,9 @@ void Tokenizer::setDirectives(std::list<Directive> directives)
1091810918

1091910919
bool Tokenizer::hasIfdef(const Token *start, const Token *end) const
1092010920
{
10921+
if (!mSettings.ifdefBailout)
10922+
return false;
10923+
1092110924
const auto& directives = mDirectives;
1092210925
return std::any_of(directives.cbegin(), directives.cend(), [&](const Directive& d) {
1092310926
return startsWith(d.str, "#if") &&

0 commit comments

Comments
 (0)