Skip to content

Commit c8b4667

Browse files
committed
split off handling of inline suppressions
1 parent 5f42093 commit c8b4667

File tree

5 files changed

+50
-7
lines changed

5 files changed

+50
-7
lines changed

Diff for: lib/cppcheck.cpp

+18-6
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,10 @@ unsigned int CppCheck::check(const FileSettings &fs)
602602
const unsigned int returnValue = temp.checkFile(Path::simplifyPath(fs.filename), fs.cfg);
603603
for (const auto& suppr : temp.mSettings.supprs.nomsg.getSuppressions())
604604
{
605+
// skip inline suppressions - are handled in checkFile()
606+
if (suppr.isInline)
607+
continue;
608+
605609
const bool res = mSettings.supprs.nomsg.updateSuppressionState(suppr);
606610
if (!res)
607611
throw InternalError(nullptr, "could not update suppression '" + suppr.errorId + "'"); // TODO: remove
@@ -947,8 +951,10 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
947951
fdump << "</dump>" << std::endl;
948952
}
949953

950-
// Need to call this even if the hash will skip this configuration
951-
mSettings.supprs.nomsg.markUnmatchedInlineSuppressionsAsChecked(tokenizer);
954+
if (mSettings.inlineSuppressions) {
955+
// Need to call this even if the hash will skip this configuration
956+
mSettings.supprs.nomsg.markUnmatchedInlineSuppressionsAsChecked(tokenizer);
957+
}
952958

953959
// Skip if we already met the same simplified token list
954960
if (mSettings.force || mSettings.maxConfigs > 1) {
@@ -1038,10 +1044,16 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
10381044
mAnalyzerInformation.close();
10391045
}
10401046

1041-
// In jointSuppressionReport mode, unmatched suppressions are
1042-
// collected after all files are processed
1043-
if (!mSettings.useSingleJob() && (mSettings.severity.isEnabled(Severity::information) || mSettings.checkConfiguration)) {
1044-
SuppressionList::reportUnmatchedSuppressions(mSettings.supprs.nomsg.getUnmatchedLocalSuppressions(filename, (bool)mUnusedFunctionsCheck), *this);
1047+
if (mSettings.severity.isEnabled(Severity::information) || mSettings.checkConfiguration) {
1048+
// TODO: check result?
1049+
SuppressionList::reportUnmatchedSuppressions(mSettings.supprs.nomsg.getUnmatchedInlineSuppressions(false), *this);
1050+
1051+
// In jointSuppressionReport mode, unmatched suppressions are
1052+
// collected after all files are processed
1053+
if (!mSettings.useSingleJob()) {
1054+
// TODO: check result?
1055+
SuppressionList::reportUnmatchedSuppressions(mSettings.supprs.nomsg.getUnmatchedLocalSuppressions(filename, (bool)mUnusedFunctionsCheck), *this);
1056+
}
10451057
}
10461058

10471059
mErrorList.clear();

Diff for: lib/preprocessor.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ static void addInlineSuppressions(const simplecpp::TokenList &tokens, const Sett
229229
// Add the suppressions.
230230
for (SuppressionList::Suppression &suppr : inlineSuppressions) {
231231
suppr.fileName = relativeFilename;
232+
suppr.isInline = true; // TODO: set earlier
232233

233234
if (SuppressionList::Type::blockBegin == suppr.type)
234235
{

Diff for: lib/suppressions.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@ std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedLocalSuppre
492492
std::string tmpFile = Path::simplifyPath(file);
493493
std::list<Suppression> result;
494494
for (const Suppression &s : mSuppressions) {
495+
if (s.isInline)
496+
continue;
495497
if (s.matched || ((s.lineNumber != Suppression::NO_LINE) && !s.checked))
496498
continue;
497499
if (s.type == SuppressionList::Type::macro)
@@ -513,6 +515,8 @@ std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedGlobalSuppr
513515
{
514516
std::list<Suppression> result;
515517
for (const Suppression &s : mSuppressions) {
518+
if (s.isInline)
519+
continue;
516520
if (s.matched || ((s.lineNumber != Suppression::NO_LINE) && !s.checked))
517521
continue;
518522
if (s.hash > 0)
@@ -528,6 +532,25 @@ std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedGlobalSuppr
528532
return result;
529533
}
530534

535+
std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedInlineSuppressions(const bool unusedFunctionChecking) const
536+
{
537+
std::list<SuppressionList::Suppression> result;
538+
for (const SuppressionList::Suppression &s : SuppressionList::mSuppressions) {
539+
if (!s.isInline)
540+
continue;
541+
if (!s.checked)
542+
continue;
543+
if (s.matched)
544+
continue;
545+
if (s.hash > 0)
546+
continue;
547+
if (!unusedFunctionChecking && s.errorId == ID_UNUSEDFUNCTION)
548+
continue;
549+
result.push_back(s);
550+
}
551+
return result;
552+
}
553+
531554
const std::list<SuppressionList::Suppression> &SuppressionList::getSuppressions() const
532555
{
533556
return mSuppressions;

Diff for: lib/suppressions.h

+7
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class CPPCHECKLIB SuppressionList {
148148
bool thisAndNextLine{}; // Special case for backwards compatibility: { // cppcheck-suppress something
149149
bool matched{};
150150
bool checked{}; // for inline suppressions, checked or not
151+
bool isInline{};
151152

152153
enum { NO_LINE = -1 };
153154
};
@@ -244,6 +245,12 @@ class CPPCHECKLIB SuppressionList {
244245
*/
245246
std::list<Suppression> getUnmatchedGlobalSuppressions(const bool unusedFunctionChecking) const;
246247

248+
/**
249+
* @brief Returns list of unmatched inline suppressions.
250+
* @return list of unmatched suppressions
251+
*/
252+
std::list<Suppression> getUnmatchedInlineSuppressions(const bool unusedFunctionChecking) const;
253+
247254
/**
248255
* @brief Returns list of all suppressions.
249256
* @return list of suppressions

Diff for: test/testsuppressions.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ class TestSuppressions : public TestFixture {
880880
"#define DIV(A,B) A/B\n"
881881
"a = DIV(10,1);\n",
882882
"");
883-
ASSERT_EQUALS("", errout_str()); // <- no unmatched suppression reported for macro suppression
883+
ASSERT_EQUALS("[test.cpp:2]: (information) Unmatched suppression: abc\n", errout_str());
884884
}
885885

886886
void suppressionsSettingsFiles() {

0 commit comments

Comments
 (0)