converted (undocumented) define `MAXTIME` into (undocumented) command-line options `--checks-max-time=`, `--template-max-time=` and `--typedef-max-time=` (#4661)
This commit is contained in:
parent
71cdacdc97
commit
d3a2cdc26c
|
@ -250,6 +250,10 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
mSettings->addEnabled("information");
|
mSettings->addEnabled("information");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (std::strncmp(argv[i], "--checks-max-time=", 18) == 0) {
|
||||||
|
mSettings->checksMaxTime = std::atoi(argv[i] + 18);
|
||||||
|
}
|
||||||
|
|
||||||
else if (std::strcmp(argv[i], "--clang") == 0) {
|
else if (std::strcmp(argv[i], "--clang") == 0) {
|
||||||
mSettings->clang = true;
|
mSettings->clang = true;
|
||||||
}
|
}
|
||||||
|
@ -915,6 +919,14 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (std::strncmp(argv[i], "--template-max-time=", 20) == 0) {
|
||||||
|
mSettings->templateMaxTime = std::atoi(argv[i] + 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (std::strncmp(argv[i], "--typedef-max-time=", 19) == 0) {
|
||||||
|
mSettings->typedefMaxTime = std::atoi(argv[i] + 19);
|
||||||
|
}
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--valueflow-max-iterations=", 27) == 0) {
|
else if (std::strncmp(argv[i], "--valueflow-max-iterations=", 27) == 0) {
|
||||||
long tmp;
|
long tmp;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -19,6 +19,10 @@
|
||||||
#ifndef configH
|
#ifndef configH
|
||||||
#define configH
|
#define configH
|
||||||
|
|
||||||
|
#ifdef MAXTIME
|
||||||
|
#error "MAXTIME is no longer supported - please use command-line options --checks-max-time=, --template-max-time= and --typedef-max-time= instead"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# ifdef CPPCHECKLIB_EXPORT
|
# ifdef CPPCHECKLIB_EXPORT
|
||||||
# define CPPCHECKLIB __declspec(dllexport)
|
# define CPPCHECKLIB __declspec(dllexport)
|
||||||
|
|
|
@ -1055,13 +1055,27 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
|
||||||
const char* unusedFunctionOnly = std::getenv("UNUSEDFUNCTION_ONLY");
|
const char* unusedFunctionOnly = std::getenv("UNUSEDFUNCTION_ONLY");
|
||||||
const bool doUnusedFunctionOnly = unusedFunctionOnly && (std::strcmp(unusedFunctionOnly, "1") == 0);
|
const bool doUnusedFunctionOnly = unusedFunctionOnly && (std::strcmp(unusedFunctionOnly, "1") == 0);
|
||||||
|
|
||||||
|
const std::time_t maxTime = mSettings.checksMaxTime > 0 ? std::time(nullptr) + mSettings.checksMaxTime : 0;
|
||||||
|
|
||||||
// call all "runChecks" in all registered Check classes
|
// call all "runChecks" in all registered Check classes
|
||||||
for (Check *check : Check::instances()) {
|
for (Check *check : Check::instances()) {
|
||||||
if (Settings::terminated())
|
if (Settings::terminated())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (Tokenizer::isMaxTime())
|
if (maxTime > 0 && std::time(nullptr) > maxTime) {
|
||||||
|
if (mSettings.debugwarnings) {
|
||||||
|
ErrorMessage::FileLocation loc;
|
||||||
|
loc.setfile(tokenizer.list.getFiles()[0]);
|
||||||
|
ErrorMessage errmsg({std::move(loc)},
|
||||||
|
emptyString,
|
||||||
|
Severity::debug,
|
||||||
|
"Checks maximum time exceeded",
|
||||||
|
"checksMaxTime",
|
||||||
|
Certainty::normal);
|
||||||
|
reportErr(errmsg);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (doUnusedFunctionOnly && dynamic_cast<CheckUnusedFunctions*>(check) == nullptr)
|
if (doUnusedFunctionOnly && dynamic_cast<CheckUnusedFunctions*>(check) == nullptr)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -39,6 +39,7 @@ Settings::Settings()
|
||||||
checkConfiguration(false),
|
checkConfiguration(false),
|
||||||
checkHeaders(true),
|
checkHeaders(true),
|
||||||
checkLibrary(false),
|
checkLibrary(false),
|
||||||
|
checksMaxTime(0),
|
||||||
checkUnusedTemplates(true),
|
checkUnusedTemplates(true),
|
||||||
clang(false),
|
clang(false),
|
||||||
clangExecutable("clang"),
|
clangExecutable("clang"),
|
||||||
|
@ -66,6 +67,8 @@ Settings::Settings()
|
||||||
relativePaths(false),
|
relativePaths(false),
|
||||||
reportProgress(false),
|
reportProgress(false),
|
||||||
showtime(SHOWTIME_MODES::SHOWTIME_NONE),
|
showtime(SHOWTIME_MODES::SHOWTIME_NONE),
|
||||||
|
templateMaxTime(0),
|
||||||
|
typedefMaxTime(0),
|
||||||
valueFlowMaxIterations(4),
|
valueFlowMaxIterations(4),
|
||||||
verbose(false),
|
verbose(false),
|
||||||
xml(false),
|
xml(false),
|
||||||
|
|
|
@ -125,6 +125,9 @@ public:
|
||||||
/** Check for incomplete info in library files? */
|
/** Check for incomplete info in library files? */
|
||||||
bool checkLibrary;
|
bool checkLibrary;
|
||||||
|
|
||||||
|
/** @brief The maximum time in seconds for the checks of a single file */
|
||||||
|
std::size_t checksMaxTime;
|
||||||
|
|
||||||
/** @brief check unknown function return values */
|
/** @brief check unknown function return values */
|
||||||
std::set<std::string> checkUnknownFunctionReturn;
|
std::set<std::string> checkUnknownFunctionReturn;
|
||||||
|
|
||||||
|
@ -342,6 +345,12 @@ public:
|
||||||
* text mode, e.g. "{file}:{line} {info}" */
|
* text mode, e.g. "{file}:{line} {info}" */
|
||||||
std::string templateLocation;
|
std::string templateLocation;
|
||||||
|
|
||||||
|
/** @brief The maximum time in seconds for the template instantation */
|
||||||
|
std::size_t templateMaxTime;
|
||||||
|
|
||||||
|
/** @brief The maximum time in seconds for the typedef simplification */
|
||||||
|
std::size_t typedefMaxTime;
|
||||||
|
|
||||||
/** @brief defines given by the user */
|
/** @brief defines given by the user */
|
||||||
std::string userDefines;
|
std::string userDefines;
|
||||||
|
|
||||||
|
|
|
@ -3112,12 +3112,22 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
|
||||||
Token * const tok2 = instantiation.token();
|
Token * const tok2 = instantiation.token();
|
||||||
if (mErrorLogger && !mTokenList.getFiles().empty())
|
if (mErrorLogger && !mTokenList.getFiles().empty())
|
||||||
mErrorLogger->reportProgress(mTokenList.getFiles()[0], "TemplateSimplifier::simplifyTemplateInstantiations()", tok2->progressValue());
|
mErrorLogger->reportProgress(mTokenList.getFiles()[0], "TemplateSimplifier::simplifyTemplateInstantiations()", tok2->progressValue());
|
||||||
#ifdef MAXTIME
|
|
||||||
if (std::time(0) > maxtime)
|
if (maxtime > 0 && std::time(nullptr) > maxtime) {
|
||||||
|
if (mSettings->debugwarnings) {
|
||||||
|
ErrorMessage::FileLocation loc;
|
||||||
|
loc.setfile(mTokenList.getFiles()[0]);
|
||||||
|
ErrorMessage errmsg({std::move(loc)},
|
||||||
|
emptyString,
|
||||||
|
Severity::debug,
|
||||||
|
"Template instantation maximum time exceeded",
|
||||||
|
"templateMaxTime",
|
||||||
|
Certainty::normal);
|
||||||
|
mErrorLogger->reportErr(errmsg);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
#else
|
}
|
||||||
(void)maxtime;
|
|
||||||
#endif
|
|
||||||
assert(mTokenList.validateToken(tok2)); // that assertion fails on examples from #6021
|
assert(mTokenList.validateToken(tok2)); // that assertion fails on examples from #6021
|
||||||
|
|
||||||
const Token *startToken = tok2;
|
const Token *startToken = tok2;
|
||||||
|
@ -3173,12 +3183,22 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
|
||||||
Token * tok2 = const_cast<Token *>(templateDeclaration.nameToken());
|
Token * tok2 = const_cast<Token *>(templateDeclaration.nameToken());
|
||||||
if (mErrorLogger && !mTokenList.getFiles().empty())
|
if (mErrorLogger && !mTokenList.getFiles().empty())
|
||||||
mErrorLogger->reportProgress(mTokenList.getFiles()[0], "TemplateSimplifier::simplifyTemplateInstantiations()", tok2->progressValue());
|
mErrorLogger->reportProgress(mTokenList.getFiles()[0], "TemplateSimplifier::simplifyTemplateInstantiations()", tok2->progressValue());
|
||||||
#ifdef MAXTIME
|
|
||||||
if (std::time(0) > maxtime)
|
if (maxtime > 0 && std::time(nullptr) > maxtime) {
|
||||||
|
if (mSettings->debugwarnings) {
|
||||||
|
ErrorMessage::FileLocation loc;
|
||||||
|
loc.setfile(mTokenList.getFiles()[0]);
|
||||||
|
ErrorMessage errmsg({std::move(loc)},
|
||||||
|
emptyString,
|
||||||
|
Severity::debug,
|
||||||
|
"Template instantation maximum time exceeded",
|
||||||
|
"templateMaxTime",
|
||||||
|
Certainty::normal);
|
||||||
|
mErrorLogger->reportErr(errmsg);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
#else
|
}
|
||||||
(void)maxtime;
|
|
||||||
#endif
|
|
||||||
assert(mTokenList.validateToken(tok2)); // that assertion fails on examples from #6021
|
assert(mTokenList.validateToken(tok2)); // that assertion fails on examples from #6021
|
||||||
|
|
||||||
Token *startToken = tok2;
|
Token *startToken = tok2;
|
||||||
|
|
|
@ -164,11 +164,8 @@ Tokenizer::Tokenizer() :
|
||||||
mVarId(0),
|
mVarId(0),
|
||||||
mUnnamedCount(0),
|
mUnnamedCount(0),
|
||||||
mCodeWithTemplates(false), //is there any templates?
|
mCodeWithTemplates(false), //is there any templates?
|
||||||
mTimerResults(nullptr)
|
mTimerResults(nullptr),
|
||||||
#ifdef MAXTIME
|
mPreprocessor(nullptr)
|
||||||
, mMaxTime(std::time(0) + MAXTIME)
|
|
||||||
#endif
|
|
||||||
, mPreprocessor(nullptr)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Tokenizer::Tokenizer(const Settings *settings, ErrorLogger *errorLogger) :
|
Tokenizer::Tokenizer(const Settings *settings, ErrorLogger *errorLogger) :
|
||||||
|
@ -180,11 +177,8 @@ Tokenizer::Tokenizer(const Settings *settings, ErrorLogger *errorLogger) :
|
||||||
mVarId(0),
|
mVarId(0),
|
||||||
mUnnamedCount(0),
|
mUnnamedCount(0),
|
||||||
mCodeWithTemplates(false), //is there any templates?
|
mCodeWithTemplates(false), //is there any templates?
|
||||||
mTimerResults(nullptr)
|
mTimerResults(nullptr),
|
||||||
#ifdef MAXTIME
|
mPreprocessor(nullptr)
|
||||||
,mMaxTime(std::time(0) + MAXTIME)
|
|
||||||
#endif
|
|
||||||
, mPreprocessor(nullptr)
|
|
||||||
{
|
{
|
||||||
// make sure settings are specified
|
// make sure settings are specified
|
||||||
assert(mSettings);
|
assert(mSettings);
|
||||||
|
@ -614,6 +608,8 @@ void Tokenizer::simplifyTypedef()
|
||||||
// Convert "using a::b;" to corresponding typedef statements
|
// Convert "using a::b;" to corresponding typedef statements
|
||||||
simplifyUsingToTypedef();
|
simplifyUsingToTypedef();
|
||||||
|
|
||||||
|
const std::time_t maxTime = mSettings->typedefMaxTime > 0 ? std::time(nullptr) + mSettings->typedefMaxTime: 0;
|
||||||
|
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (mErrorLogger && !list.getFiles().empty())
|
if (mErrorLogger && !list.getFiles().empty())
|
||||||
mErrorLogger->reportProgress(list.getFiles()[0], "Tokenize (typedef)", tok->progressValue());
|
mErrorLogger->reportProgress(list.getFiles()[0], "Tokenize (typedef)", tok->progressValue());
|
||||||
|
@ -621,8 +617,20 @@ void Tokenizer::simplifyTypedef()
|
||||||
if (Settings::terminated())
|
if (Settings::terminated())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (isMaxTime())
|
if (maxTime > 0 && std::time(nullptr) > maxTime) {
|
||||||
|
if (mSettings->debugwarnings) {
|
||||||
|
ErrorMessage::FileLocation loc;
|
||||||
|
loc.setfile(list.getFiles()[0]);
|
||||||
|
ErrorMessage errmsg({std::move(loc)},
|
||||||
|
emptyString,
|
||||||
|
Severity::debug,
|
||||||
|
"Typedef simplification instantation maximum time exceeded",
|
||||||
|
"typedefMaxTime",
|
||||||
|
Certainty::normal);
|
||||||
|
mErrorLogger->reportErr(errmsg);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (goback) {
|
if (goback) {
|
||||||
//jump back once, see the comment at the end of the function
|
//jump back once, see the comment at the end of the function
|
||||||
|
@ -3461,12 +3469,9 @@ void Tokenizer::simplifyTemplates()
|
||||||
if (isC())
|
if (isC())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const std::time_t maxTime = mSettings->templateMaxTime > 0 ? std::time(nullptr) + mSettings->templateMaxTime : 0;
|
||||||
mTemplateSimplifier->simplifyTemplates(
|
mTemplateSimplifier->simplifyTemplates(
|
||||||
#ifdef MAXTIME
|
maxTime,
|
||||||
mMaxTime,
|
|
||||||
#else
|
|
||||||
0, // ignored
|
|
||||||
#endif
|
|
||||||
mCodeWithTemplates);
|
mCodeWithTemplates);
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
|
@ -680,15 +680,6 @@ public:
|
||||||
*/
|
*/
|
||||||
static const Token * startOfExecutableScope(const Token * tok);
|
static const Token * startOfExecutableScope(const Token * tok);
|
||||||
|
|
||||||
#ifdef MAXTIME
|
|
||||||
bool isMaxTime() const {
|
|
||||||
return (std::time(0) > mMaxTime);
|
|
||||||
#else
|
|
||||||
static bool isMaxTime() {
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
const Settings *getSettings() const {
|
const Settings *getSettings() const {
|
||||||
return mSettings;
|
return mSettings;
|
||||||
}
|
}
|
||||||
|
@ -759,11 +750,6 @@ private:
|
||||||
*/
|
*/
|
||||||
TimerResults *mTimerResults;
|
TimerResults *mTimerResults;
|
||||||
|
|
||||||
#ifdef MAXTIME
|
|
||||||
/** Tokenizer maxtime */
|
|
||||||
const std::time_t mMaxTime;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const Preprocessor *mPreprocessor;
|
const Preprocessor *mPreprocessor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue