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");
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
long tmp;
|
||||
try {
|
||||
|
|
|
@ -19,6 +19,10 @@
|
|||
#ifndef 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 CPPCHECKLIB_EXPORT
|
||||
# define CPPCHECKLIB __declspec(dllexport)
|
||||
|
|
|
@ -1055,13 +1055,27 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
|
|||
const char* unusedFunctionOnly = std::getenv("UNUSEDFUNCTION_ONLY");
|
||||
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
|
||||
for (Check *check : Check::instances()) {
|
||||
if (Settings::terminated())
|
||||
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;
|
||||
}
|
||||
|
||||
if (doUnusedFunctionOnly && dynamic_cast<CheckUnusedFunctions*>(check) == nullptr)
|
||||
continue;
|
||||
|
|
|
@ -39,6 +39,7 @@ Settings::Settings()
|
|||
checkConfiguration(false),
|
||||
checkHeaders(true),
|
||||
checkLibrary(false),
|
||||
checksMaxTime(0),
|
||||
checkUnusedTemplates(true),
|
||||
clang(false),
|
||||
clangExecutable("clang"),
|
||||
|
@ -66,6 +67,8 @@ Settings::Settings()
|
|||
relativePaths(false),
|
||||
reportProgress(false),
|
||||
showtime(SHOWTIME_MODES::SHOWTIME_NONE),
|
||||
templateMaxTime(0),
|
||||
typedefMaxTime(0),
|
||||
valueFlowMaxIterations(4),
|
||||
verbose(false),
|
||||
xml(false),
|
||||
|
|
|
@ -125,6 +125,9 @@ public:
|
|||
/** Check for incomplete info in library files? */
|
||||
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 */
|
||||
std::set<std::string> checkUnknownFunctionReturn;
|
||||
|
||||
|
@ -342,6 +345,12 @@ public:
|
|||
* text mode, e.g. "{file}:{line} {info}" */
|
||||
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 */
|
||||
std::string userDefines;
|
||||
|
||||
|
|
|
@ -3112,12 +3112,22 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
|
|||
Token * const tok2 = instantiation.token();
|
||||
if (mErrorLogger && !mTokenList.getFiles().empty())
|
||||
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;
|
||||
#else
|
||||
(void)maxtime;
|
||||
#endif
|
||||
}
|
||||
|
||||
assert(mTokenList.validateToken(tok2)); // that assertion fails on examples from #6021
|
||||
|
||||
const Token *startToken = tok2;
|
||||
|
@ -3173,12 +3183,22 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
|
|||
Token * tok2 = const_cast<Token *>(templateDeclaration.nameToken());
|
||||
if (mErrorLogger && !mTokenList.getFiles().empty())
|
||||
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;
|
||||
#else
|
||||
(void)maxtime;
|
||||
#endif
|
||||
}
|
||||
|
||||
assert(mTokenList.validateToken(tok2)); // that assertion fails on examples from #6021
|
||||
|
||||
Token *startToken = tok2;
|
||||
|
|
|
@ -164,11 +164,8 @@ Tokenizer::Tokenizer() :
|
|||
mVarId(0),
|
||||
mUnnamedCount(0),
|
||||
mCodeWithTemplates(false), //is there any templates?
|
||||
mTimerResults(nullptr)
|
||||
#ifdef MAXTIME
|
||||
, mMaxTime(std::time(0) + MAXTIME)
|
||||
#endif
|
||||
, mPreprocessor(nullptr)
|
||||
mTimerResults(nullptr),
|
||||
mPreprocessor(nullptr)
|
||||
{}
|
||||
|
||||
Tokenizer::Tokenizer(const Settings *settings, ErrorLogger *errorLogger) :
|
||||
|
@ -180,11 +177,8 @@ Tokenizer::Tokenizer(const Settings *settings, ErrorLogger *errorLogger) :
|
|||
mVarId(0),
|
||||
mUnnamedCount(0),
|
||||
mCodeWithTemplates(false), //is there any templates?
|
||||
mTimerResults(nullptr)
|
||||
#ifdef MAXTIME
|
||||
,mMaxTime(std::time(0) + MAXTIME)
|
||||
#endif
|
||||
, mPreprocessor(nullptr)
|
||||
mTimerResults(nullptr),
|
||||
mPreprocessor(nullptr)
|
||||
{
|
||||
// make sure settings are specified
|
||||
assert(mSettings);
|
||||
|
@ -614,6 +608,8 @@ void Tokenizer::simplifyTypedef()
|
|||
// Convert "using a::b;" to corresponding typedef statements
|
||||
simplifyUsingToTypedef();
|
||||
|
||||
const std::time_t maxTime = mSettings->typedefMaxTime > 0 ? std::time(nullptr) + mSettings->typedefMaxTime: 0;
|
||||
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
if (mErrorLogger && !list.getFiles().empty())
|
||||
mErrorLogger->reportProgress(list.getFiles()[0], "Tokenize (typedef)", tok->progressValue());
|
||||
|
@ -621,8 +617,20 @@ void Tokenizer::simplifyTypedef()
|
|||
if (Settings::terminated())
|
||||
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;
|
||||
}
|
||||
|
||||
if (goback) {
|
||||
//jump back once, see the comment at the end of the function
|
||||
|
@ -3461,12 +3469,9 @@ void Tokenizer::simplifyTemplates()
|
|||
if (isC())
|
||||
return;
|
||||
|
||||
const std::time_t maxTime = mSettings->templateMaxTime > 0 ? std::time(nullptr) + mSettings->templateMaxTime : 0;
|
||||
mTemplateSimplifier->simplifyTemplates(
|
||||
#ifdef MAXTIME
|
||||
mMaxTime,
|
||||
#else
|
||||
0, // ignored
|
||||
#endif
|
||||
maxTime,
|
||||
mCodeWithTemplates);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -680,15 +680,6 @@ public:
|
|||
*/
|
||||
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 {
|
||||
return mSettings;
|
||||
}
|
||||
|
@ -759,11 +750,6 @@ private:
|
|||
*/
|
||||
TimerResults *mTimerResults;
|
||||
|
||||
#ifdef MAXTIME
|
||||
/** Tokenizer maxtime */
|
||||
const std::time_t mMaxTime;
|
||||
#endif
|
||||
|
||||
const Preprocessor *mPreprocessor;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue