From 10426f6707ab13b072f297a16e1e499abcd3db7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Tue, 27 Sep 2022 20:04:35 +0200 Subject: [PATCH] cppcheck.cpp: only call `getFileInfo()` if necessary (#4510) --- lib/cppcheck.cpp | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 861f7d870..3f4185fe6 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -971,8 +971,10 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string mExitCode=1; // e.g. reflect a syntax error } - mAnalyzerInformation.setFileInfo("CheckUnusedFunctions", checkUnusedFunctions.analyzerInfo()); - mAnalyzerInformation.close(); + if (!mSettings.buildDir.empty()) { + mAnalyzerInformation.setFileInfo("CheckUnusedFunctions", checkUnusedFunctions.analyzerInfo()); + mAnalyzerInformation.close(); + } // In jointSuppressionReport mode, unmatched suppressions are // collected after all files are processed @@ -1039,19 +1041,26 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer) // TODO: Use CTU for Clang analysis return; - // Analyse the tokens.. - CTU::FileInfo *fi1 = CTU::getFileInfo(&tokenizer); - if (fi1) { - mFileInfo.push_back(fi1); - mAnalyzerInformation.setFileInfo("ctu", fi1->toString()); - } + if (mSettings.jobs == 1 || !mSettings.buildDir.empty()) { + // Analyse the tokens.. - for (const Check *check : Check::instances()) { - Check::FileInfo *fi = check->getFileInfo(&tokenizer, &mSettings); - if (fi != nullptr) { - mFileInfo.push_back(fi); - mAnalyzerInformation.setFileInfo(check->name(), fi->toString()); + CTU::FileInfo *fi1 = CTU::getFileInfo(&tokenizer); + if (fi1) { + if (mSettings.jobs == 1) + mFileInfo.push_back(fi1); + if (!mSettings.buildDir.empty()) + mAnalyzerInformation.setFileInfo("ctu", fi1->toString()); + } + + for (const Check *check: Check::instances()) { + Check::FileInfo *fi = check->getFileInfo(&tokenizer, &mSettings); + if (fi != nullptr) { + if (mSettings.jobs == 1) + mFileInfo.push_back(fi); + if (!mSettings.buildDir.empty()) + mAnalyzerInformation.setFileInfo(check->name(), fi->toString()); + } } } @@ -1535,7 +1544,8 @@ void CppCheck::reportErr(const ErrorMessage &msg) if (std::find(mErrorList.begin(), mErrorList.end(), errmsg) != mErrorList.end()) return; - mAnalyzerInformation.reportErr(msg, mSettings.verbose); + if (!mSettings.buildDir.empty()) + mAnalyzerInformation.reportErr(msg, mSettings.verbose); const Suppressions::ErrorMessage errorMessage = msg.toSuppressionsErrorMessage();