Rename 'Verification' to 'Bug hunting'

This commit is contained in:
Daniel Marjamäki 2020-01-14 21:17:07 +01:00
parent 434b506e58
commit 7820b5dbcc
8 changed files with 82 additions and 82 deletions

View File

@ -192,25 +192,22 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
else if (std::strcmp(argv[i], "--safe-functions") == 0) else if (std::strcmp(argv[i], "--safe-functions") == 0)
mSettings->safeChecks.externalFunctions = mSettings->safeChecks.internalFunctions = true; mSettings->safeChecks.externalFunctions = mSettings->safeChecks.internalFunctions = true;
// Experimental: Verify // Bug hunting
else if (std::strcmp(argv[i], "--verify") == 0) else if (std::strcmp(argv[i], "--bug-hunting") == 0)
mSettings->verification = true; mSettings->bugHunting = true;
else if (std::strncmp(argv[i], "--verify-report=", 16) == 0) { else if (std::strcmp(argv[i], "--debug-bug-hunting") == 0)
mSettings->verification = true; mSettings->bugHunting = mSettings->debugBugHunting = true;
mSettings->verificationReport = argv[i] + 16; /*
} else if (std::strcmp(argv[i], "--debug-verify") == 0) else if (std::strncmp(argv[i], "--check-diff=", 13) == 0) {
mSettings->debugVerification = true; std::ifstream fin(argv[i] + 13);
else if (std::strncmp(argv[i], "--verify-diff=", 14) == 0) {
std::ifstream fin(argv[i] + 14);
if (!fin.is_open()) { if (!fin.is_open()) {
printMessage("cppcheck: could not open file " + std::string(argv[i] + 14) + "."); printMessage("cppcheck: could not open file " + std::string(argv[i] + 13) + ".");
return false; return false;
} }
mSettings->verifyDiff = Settings::loadDiffFile(fin); mSettings->checkDiff = Settings::loadDiffFile(fin);
mSettings->verification = true;
for (const auto &diff: mSettings->verifyDiff) { for (const auto &diff: mSettings->bugHuntingDiff) {
if (!Path::acceptFile(diff.filename)) if (!Path::acceptFile(diff.filename))
continue; continue;
const std::string filename = Path::fromNativeSeparators(diff.filename); const std::string filename = Path::fromNativeSeparators(diff.filename);
@ -218,7 +215,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
mPathNames.push_back(filename); mPathNames.push_back(filename);
} }
} }
*/
// Enforce language (--language=, -x) // Enforce language (--language=, -x)
else if (std::strncmp(argv[i], "--language=", 11) == 0 || std::strcmp(argv[i], "-x") == 0) { else if (std::strncmp(argv[i], "--language=", 11) == 0 || std::strcmp(argv[i], "-x") == 0) {
std::string str; std::string str;

View File

@ -79,14 +79,14 @@
/*static*/ FILE* CppCheckExecutor::mExceptionOutput = stdout; /*static*/ FILE* CppCheckExecutor::mExceptionOutput = stdout;
CppCheckExecutor::CppCheckExecutor() CppCheckExecutor::CppCheckExecutor()
: mSettings(nullptr), mLatestProgressOutputTime(0), mErrorOutput(nullptr), mVerificationOutput(nullptr), mShowAllErrors(false) : mSettings(nullptr), mLatestProgressOutputTime(0), mErrorOutput(nullptr), mBugHuntingReport(nullptr), mShowAllErrors(false)
{ {
} }
CppCheckExecutor::~CppCheckExecutor() CppCheckExecutor::~CppCheckExecutor()
{ {
delete mErrorOutput; delete mErrorOutput;
delete mVerificationOutput; delete mBugHuntingReport;
} }
bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* const argv[]) bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* const argv[])
@ -1095,9 +1095,9 @@ void CppCheckExecutor::reportVerification(const std::string &str)
{ {
if (!mSettings || str.empty()) if (!mSettings || str.empty())
return; return;
if (!mVerificationOutput) if (!mBugHuntingReport)
mVerificationOutput = new std::ofstream(mSettings->verificationReport); mBugHuntingReport = new std::ofstream(mSettings->bugHuntingReport);
(*mVerificationOutput) << str << std::endl; (*mBugHuntingReport) << str << std::endl;
} }
void CppCheckExecutor::setExceptionOutput(FILE* exceptionOutput) void CppCheckExecutor::setExceptionOutput(FILE* exceptionOutput)

View File

@ -190,9 +190,9 @@ private:
std::ofstream *mErrorOutput; std::ofstream *mErrorOutput;
/** /**
* Verification report * Bug hunting report
*/ */
std::ostream *mVerificationOutput; std::ostream *mBugHuntingReport;
/** /**
* Has --errorlist been given? * Has --errorlist been given?

View File

@ -301,7 +301,7 @@ unsigned int CppCheck::check(const std::string &path)
tokenizer.printDebugOutput(1); tokenizer.printDebugOutput(1);
#ifdef USE_Z3 #ifdef USE_Z3
if (mSettings.verification) if (mSettings.bugHunting)
ExprEngine::runChecks(this, &tokenizer, &mSettings); ExprEngine::runChecks(this, &tokenizer, &mSettings);
#endif #endif
return 0; return 0;
@ -838,6 +838,9 @@ void CppCheck::checkRawTokens(const Tokenizer &tokenizer)
void CppCheck::checkNormalTokens(const Tokenizer &tokenizer) void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
{ {
if (mSettings.bugHunting)
ExprEngine::runChecks(this, &tokenizer, &mSettings);
else {
// 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())
@ -850,10 +853,6 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
check->runChecks(&tokenizer, &mSettings, this); check->runChecks(&tokenizer, &mSettings, this);
} }
// Verification using ExprEngine..
if (mSettings.verification)
ExprEngine::runChecks(this, &tokenizer, &mSettings);
// Analyse the tokens.. // Analyse the tokens..
CTU::FileInfo *fi1 = CTU::getFileInfo(&tokenizer); CTU::FileInfo *fi1 = CTU::getFileInfo(&tokenizer);
@ -872,6 +871,7 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
executeRules("normal", tokenizer); executeRules("normal", tokenizer);
} }
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -1719,20 +1719,20 @@ void ExprEngine::executeFunction(const Scope *functionScope, const Tokenizer *to
// TODO.. what about functions in headers? // TODO.. what about functions in headers?
return; return;
if (!settings->verifyDiff.empty()) { if (!settings->checkDiff.empty()) {
const std::string filename = tokenizer->list.getFiles().at(functionScope->bodyStart->fileIndex()); const std::string filename = tokenizer->list.getFiles().at(functionScope->bodyStart->fileIndex());
bool verify = false; bool check = false;
for (const auto &diff: settings->verifyDiff) { for (const auto &diff: settings->checkDiff) {
if (diff.filename != filename) if (diff.filename != filename)
continue; continue;
if (diff.fromLine > functionScope->bodyEnd->linenr()) if (diff.fromLine > functionScope->bodyEnd->linenr())
continue; continue;
if (diff.toLine < functionScope->bodyStart->linenr()) if (diff.toLine < functionScope->bodyStart->linenr())
continue; continue;
verify = true; check = true;
break; break;
} }
if (!verify) if (!check)
return; return;
} }
@ -1757,19 +1757,21 @@ void ExprEngine::executeFunction(const Scope *functionScope, const Tokenizer *to
} }
} }
if (settings->debugVerification && (settings->verbose || callbacks.empty() || !trackExecution.isAllOk())) { const bool bugHuntingReport = !settings->bugHuntingReport.empty();
if (!settings->verificationReport.empty())
if (settings->debugBugHunting && (settings->verbose || callbacks.empty() || !trackExecution.isAllOk())) {
if (bugHuntingReport)
report << "[debug]" << std::endl; report << "[debug]" << std::endl;
trackExecution.print(report); trackExecution.print(report);
if (!callbacks.empty()) { if (!callbacks.empty()) {
if (!settings->verificationReport.empty()) if (bugHuntingReport)
report << "[details]" << std::endl; report << "[details]" << std::endl;
trackExecution.report(report, functionScope); trackExecution.report(report, functionScope);
} }
} }
// Write a verification report // Write a verification report
if (!settings->verificationReport.empty()) { if (bugHuntingReport) {
report << "[function-report] " report << "[function-report] "
<< Path::stripDirectoryPart(tokenizer->list.getFiles().at(functionScope->bodyStart->fileIndex())) << ":" << Path::stripDirectoryPart(tokenizer->list.getFiles().at(functionScope->bodyStart->fileIndex())) << ":"
<< functionScope->bodyStart->linenr() << ":" << functionScope->bodyStart->linenr() << ":"
@ -2044,7 +2046,7 @@ void ExprEngine::runChecks(ErrorLogger *errorLogger, const Tokenizer *tokenizer,
std::ostringstream report; std::ostringstream report;
ExprEngine::executeAllFunctions(tokenizer, settings, callbacks, report); ExprEngine::executeAllFunctions(tokenizer, settings, callbacks, report);
if (settings->verificationReport.empty()) if (settings->bugHuntingReport.empty())
std::cout << report.str(); std::cout << report.str();
else if (errorLogger) else if (errorLogger)
errorLogger->reportVerification(report.str()); errorLogger->reportVerification(report.str());

View File

@ -46,8 +46,8 @@ Settings::Settings()
experimental(false), experimental(false),
force(false), force(false),
inconclusive(false), inconclusive(false),
verification(false), bugHunting(false),
debugVerification(false), debugBugHunting(false),
inlineSuppressions(false), inlineSuppressions(false),
jobs(1), jobs(1),
jointSuppressionReport(false), jointSuppressionReport(false),

View File

@ -194,22 +194,22 @@ public:
SafeChecks safeChecks; SafeChecks safeChecks;
/** @brief Enable verification analysis */ /** @brief Bug hunting */
bool verification; bool bugHunting;
/** @brief Verification report filename */ /** @brief Debug bug hunting */
std::string verificationReport; bool debugBugHunting;
/** @brief Generate verification debug output */ /** Filename for bug hunting report */
bool debugVerification; std::string bugHuntingReport;
/** @brief Verify diff */ /** @brief Check diff */
struct Diff { struct Diff {
std::string filename; std::string filename;
int fromLine; int fromLine;
int toLine; int toLine;
}; };
std::vector<Diff> verifyDiff; std::vector<Diff> checkDiff;
/** @brief check unknown function return values */ /** @brief check unknown function return values */
std::set<std::string> checkUnknownFunctionReturn; std::set<std::string> checkUnknownFunctionReturn;

View File

@ -137,7 +137,8 @@ private:
std::string trackExecution(const char code[]) { std::string trackExecution(const char code[]) {
Settings settings; Settings settings;
settings.debugVerification = true; settings.bugHunting = true;
settings.debugBugHunting = true;
settings.platform(cppcheck::Platform::Unix64); settings.platform(cppcheck::Platform::Unix64);
settings.library.smartPointers.insert("std::shared_ptr"); settings.library.smartPointers.insert("std::shared_ptr");
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);