CLI: Added --max-ctu-depth

This commit is contained in:
Daniel Marjamäki 2019-02-03 17:51:02 +01:00
parent 7f506517ee
commit 437800f46d
7 changed files with 31 additions and 1 deletions

View File

@ -155,6 +155,10 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
else if (std::strcmp(argv[i], "--dump") == 0)
mSettings->dump = true;
// max ctu depth
else if (std::strncmp(argv[i], "--max-ctu-depth=", 16) == 0)
mSettings->maxCtuDepth = std::atoi(argv[i] + 16);
// (Experimental) exception handling inside cppcheck client
else if (std::strcmp(argv[i], "--exception-handling") == 0)
mSettings->exceptionHandling = true;
@ -1013,6 +1017,9 @@ void CmdLineParser::printHelp()
" distributed with Cppcheck is loaded automatically.\n"
" For more information about library files, read the\n"
" manual.\n"
" --max-ctu-depth=N Max depth in whole program analysis. The default value\n"
" is 2. A larger value will mean more errors can be found\n"
" but also means the analysis will be slower.\n"
" --output-file=<file> Write results to file, rather than standard error.\n"
" --project=<file> Run Cppcheck on project. The <file> can be a Visual\n"
" Studio Solution (*.sln), Visual Studio Project\n"

View File

@ -1036,6 +1036,8 @@ void CppCheck::getErrorMessages()
bool CppCheck::analyseWholeProgram()
{
bool errors = false;
// Init CTU
CTU::maxCtuDepth = mSettings.maxCtuDepth;
// Analyse the tokens
CTU::FileInfo ctu;
for (const Check::FileInfo *fi : mFileInfo) {
@ -1100,6 +1102,9 @@ void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::map<s
}
}
// Set CTU max depth
CTU::maxCtuDepth = mSettings.maxCtuDepth;
// Analyse the tokens
for (Check *check : Check::instances())
check->analyseWholeProgram(&ctuFileInfo, fileInfoList, mSettings, *this);

View File

@ -38,6 +38,7 @@ static const char ATTR_MY_ID[] = "my-id";
static const char ATTR_MY_ARGNR[] = "my-argnr";
static const char ATTR_MY_ARGNAME[] = "my-argname";
int CTU::maxCtuDepth = 2;
std::string CTU::getFunctionId(const Tokenizer *tokenizer, const Function *function)
{
@ -426,7 +427,7 @@ static bool findPath(const std::string &callId,
int index,
bool warning)
{
if (index >= 10)
if (index >= CTU::maxCtuDepth || index >= 10)
return false;
const std::map<std::string, std::list<const CTU::FileInfo::CallBase *>>::const_iterator it = callsMap.find(callId);

View File

@ -117,6 +117,8 @@ namespace CTU {
bool warning) const;
};
extern int maxCtuDepth;
CPPCHECKLIB std::string toString(const std::list<FileInfo::UnsafeUsage> &unsafeUsage);
CPPCHECKLIB std::string getFunctionId(const Tokenizer *tokenizer, const Function *function);

View File

@ -32,6 +32,7 @@ Settings::Settings()
exceptionHandling(false),
inconclusive(false),
jointSuppressionReport(false),
maxCtuDepth(2),
experimental(false),
quiet(false),
inlineSuppressions(false),

View File

@ -85,6 +85,9 @@ public:
/** @brief Is --debug-template given? */
bool debugtemplate;
/** @brief --max-ctu-depth */
int maxCtuDepth;
/** @brief Is --dump given? */
bool dump;
std::string dumpFile;

View File

@ -165,6 +165,9 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/
<arg choice="opt">
<option>--max-configs=&lt;limit&gt;</option>
</arg>
<arg choice="opt">
<option>--max-ctu-depth=&lt;limit&gt;</option>
</arg>
<arg choice="opt">
<option>--platform=&lt;type&gt;</option>
</arg>
@ -457,6 +460,14 @@ There are false positives with this option. Each result must be carefully invest
the one that is effective.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--max-ctu-depths=&lt;limit&gt;</option>
</term>
<listitem>
<para>Maximum depth in whole program analysis. Default is 2.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--platform=&lt;type&gt;</option>