From dc8190baa5b50ff38e72b705193999197bb8d7c1 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 14 Aug 2025 12:48:07 +0200 Subject: [PATCH 01/11] Update suppressions.h --- lib/suppressions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/suppressions.h b/lib/suppressions.h index 11a92b320c2..84e2bc2cb6e 100644 --- a/lib/suppressions.h +++ b/lib/suppressions.h @@ -252,7 +252,7 @@ class CPPCHECKLIB SuppressionList { * @brief Create an xml dump of suppressions * @param out stream to write XML to */ - void dump(std::ostream &out) const; + void dump(std::ostream &out, const std::string& filePath = {}) const; /** * @brief Returns list of unmatched local (per-file) suppressions. From 5ae3576f5691f3264d028c1894d19472c1109524 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 14 Aug 2025 12:49:42 +0200 Subject: [PATCH 02/11] Update suppressions.cpp --- lib/suppressions.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 59b9ed835fa..dcd5e588402 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -512,12 +512,14 @@ bool SuppressionList::isSuppressed(const ::ErrorMessage &errmsg, const std::set< return isSuppressed(SuppressionList::ErrorMessage::fromErrorMessage(errmsg, macroNames)); } -void SuppressionList::dump(std::ostream & out) const +void SuppressionList::dump(std::ostream & out, const std::string& filePath) const { std::lock_guard lg(mSuppressionsSync); out << " " << std::endl; for (const Suppression &suppression : mSuppressions) { + if (!filePath.empty() && !suppression.fileName.empty() && filePath != suppression.fileName) + continue; out << " Date: Thu, 14 Aug 2025 12:50:23 +0200 Subject: [PATCH 03/11] Update cppcheck.h --- lib/cppcheck.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cppcheck.h b/lib/cppcheck.h index d56d7fa6b4f..57b75a32613 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -171,7 +171,7 @@ class CPPCHECKLIB CppCheck { * @param tokens Token list from preprocessed file. * @return hash */ - std::size_t calculateHash(const Preprocessor &preprocessor, const simplecpp::TokenList &tokens) const; + std::size_t calculateHash(const Preprocessor &preprocessor, const simplecpp::TokenList &tokens, const std::string& filePath = {}) const; /** * @brief Check a file using stream From 43604add2e0258640b17d37671e65e9145505164 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 14 Aug 2025 12:51:15 +0200 Subject: [PATCH 04/11] Update cppcheck.cpp --- lib/cppcheck.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 181551e05f6..a25b8c0d90e 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -850,7 +850,7 @@ static simplecpp::TokenList createTokenList(const std::string& filename, std::ve return {filename, files, outputList}; } -std::size_t CppCheck::calculateHash(const Preprocessor& preprocessor, const simplecpp::TokenList& tokens) const +std::size_t CppCheck::calculateHash(const Preprocessor& preprocessor, const simplecpp::TokenList& tokens, const std::string& filePath) const { std::ostringstream toolinfo; toolinfo << (mSettings.cppcheckCfgProductName.empty() ? CPPCHECK_VERSION_STRING : mSettings.cppcheckCfgProductName); @@ -867,7 +867,7 @@ std::size_t CppCheck::calculateHash(const Preprocessor& preprocessor, const simp } toolinfo << mSettings.premiumArgs; // TODO: do we need to add more options? - mSuppressions.nomsg.dump(toolinfo); + mSuppressions.nomsg.dump(toolinfo, filePath); return preprocessor.calculateHash(tokens, toolinfo.str()); } From 31566a8627b000ffe8e10a2476c310c5d5442f80 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 14 Aug 2025 12:52:31 +0200 Subject: [PATCH 05/11] Update cppcheck.cpp --- lib/cppcheck.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index a25b8c0d90e..fbc54683c6a 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1020,7 +1020,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string if (analyzerInformation) { // Calculate hash so it can be compared with old hash / future hashes - const std::size_t hash = calculateHash(preprocessor, tokens1); + const std::size_t hash = calculateHash(preprocessor, tokens1), file.spath()); std::list errors; if (!analyzerInformation->analyzeFile(mSettings.buildDir, file.spath(), cfgname, fileIndex, hash, errors)) { while (!errors.empty()) { From cded2bd83b9173d250252b34228283cbe721c41a Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 14 Aug 2025 12:57:23 +0200 Subject: [PATCH 06/11] Update cppcheck.cpp --- lib/cppcheck.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index fbc54683c6a..74bece05329 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1020,7 +1020,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string if (analyzerInformation) { // Calculate hash so it can be compared with old hash / future hashes - const std::size_t hash = calculateHash(preprocessor, tokens1), file.spath()); + const std::size_t hash = calculateHash(preprocessor, tokens1, file.spath()); std::list errors; if (!analyzerInformation->analyzeFile(mSettings.buildDir, file.spath(), cfgname, fileIndex, hash, errors)) { while (!errors.empty()) { From ab8907bcf7c35c371cd0c44b42cb0e7742461cc9 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 14 Aug 2025 16:57:59 +0200 Subject: [PATCH 07/11] Update suppressions.cpp --- lib/suppressions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index dcd5e588402..a7c30580700 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -518,7 +518,7 @@ void SuppressionList::dump(std::ostream & out, const std::string& filePath) cons out << " " << std::endl; for (const Suppression &suppression : mSuppressions) { - if (!filePath.empty() && !suppression.fileName.empty() && filePath != suppression.fileName) + if (suppression.isInline && !suppression.fileName.empty() && !filePath.empty() && filePath != suppression.fileName) continue; out << " Date: Thu, 14 Aug 2025 20:43:31 +0200 Subject: [PATCH 08/11] Add test --- test/cli/inline-suppress_test.py | 28 ++++++++++++++++++++++++++++ test/cli/reanalysis/a.cpp | 4 ++++ test/cli/reanalysis/b.cpp | 2 ++ test/cli/reanalysis/c.cpp | 2 ++ test/cli/reanalysis/d.cpp | 2 ++ 5 files changed, 38 insertions(+) create mode 100644 test/cli/reanalysis/a.cpp create mode 100644 test/cli/reanalysis/b.cpp create mode 100644 test/cli/reanalysis/c.cpp create mode 100644 test/cli/reanalysis/d.cpp diff --git a/test/cli/inline-suppress_test.py b/test/cli/inline-suppress_test.py index cdb3aeca355..addd6cacae4 100644 --- a/test/cli/inline-suppress_test.py +++ b/test/cli/inline-suppress_test.py @@ -247,6 +247,34 @@ def test_build_dir(tmpdir): assert stdout == '' assert ret == 0, stdout +def test_build_dir_threads_suppressions(tmpdir): + args = [ + '-q', + '--template=simple', + '--cppcheck-build-dir={}'.format(tmpdir), + '--enable=style', + '--inline-suppr', + '--executor=thread', + '-j4', + 'reanalysis' + ] + + ret, stdout, stderr = cppcheck(args, cwd=__script_dir) + lines = stderr.splitlines() + assert lines == [] + assert stdout == '' + assert ret == 0, stdout + + a1Path = os.path.join(tmpdir, 'd.a1') + mtimeOld = os.path.getmtime(a1Path) + + for i in range(1, 10): + cppcheck(args, cwd=__script_dir) + + mtimeNew = os.path.getmtime(a1Path) + + assert mtimeOld == mtimeNew + def __test_build_dir_unused_template(tmpdir, extra_args): args = [ diff --git a/test/cli/reanalysis/a.cpp b/test/cli/reanalysis/a.cpp new file mode 100644 index 00000000000..aad7e3efa61 --- /dev/null +++ b/test/cli/reanalysis/a.cpp @@ -0,0 +1,4 @@ +int main() { + int i; // cppcheck-suppress unusedVariable +} + diff --git a/test/cli/reanalysis/b.cpp b/test/cli/reanalysis/b.cpp new file mode 100644 index 00000000000..cb4df470113 --- /dev/null +++ b/test/cli/reanalysis/b.cpp @@ -0,0 +1,2 @@ +int main() {} + diff --git a/test/cli/reanalysis/c.cpp b/test/cli/reanalysis/c.cpp new file mode 100644 index 00000000000..cb4df470113 --- /dev/null +++ b/test/cli/reanalysis/c.cpp @@ -0,0 +1,2 @@ +int main() {} + diff --git a/test/cli/reanalysis/d.cpp b/test/cli/reanalysis/d.cpp new file mode 100644 index 00000000000..cb4df470113 --- /dev/null +++ b/test/cli/reanalysis/d.cpp @@ -0,0 +1,2 @@ +int main() {} + From adb34f2fbe55dac6878194a5b1faeecdda47bae1 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Thu, 14 Aug 2025 22:18:10 +0200 Subject: [PATCH 09/11] Fix --- test/cli/inline-suppress_test.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/cli/inline-suppress_test.py b/test/cli/inline-suppress_test.py index addd6cacae4..4157be4d77b 100644 --- a/test/cli/inline-suppress_test.py +++ b/test/cli/inline-suppress_test.py @@ -1,5 +1,5 @@ -# python -m pytest test-inline-suppress.py +# python -m pytest inline-suppress_test.py import json import os @@ -247,14 +247,13 @@ def test_build_dir(tmpdir): assert stdout == '' assert ret == 0, stdout -def test_build_dir_threads_suppressions(tmpdir): +def test_build_dir_threads_suppressions(tmpdir): #14064 args = [ '-q', '--template=simple', '--cppcheck-build-dir={}'.format(tmpdir), '--enable=style', '--inline-suppr', - '--executor=thread', '-j4', 'reanalysis' ] @@ -266,13 +265,13 @@ def test_build_dir_threads_suppressions(tmpdir): assert ret == 0, stdout a1Path = os.path.join(tmpdir, 'd.a1') + assert os.path.exists(a1Path) mtimeOld = os.path.getmtime(a1Path) - for i in range(1, 10): + for _ in range(1, 10): cppcheck(args, cwd=__script_dir) - - mtimeNew = os.path.getmtime(a1Path) + mtimeNew = os.path.getmtime(a1Path) assert mtimeOld == mtimeNew From 17f17ed09d48b609faca9adf3075137b9b27caf9 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 15 Aug 2025 15:46:52 +0200 Subject: [PATCH 10/11] Update inline-suppress_test.py --- test/cli/inline-suppress_test.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/cli/inline-suppress_test.py b/test/cli/inline-suppress_test.py index 4157be4d77b..3bc14455446 100644 --- a/test/cli/inline-suppress_test.py +++ b/test/cli/inline-suppress_test.py @@ -247,7 +247,7 @@ def test_build_dir(tmpdir): assert stdout == '' assert ret == 0, stdout -def test_build_dir_threads_suppressions(tmpdir): #14064 +def test_build_dir_jobs_suppressions(tmpdir): #14064 args = [ '-q', '--template=simple', @@ -268,6 +268,8 @@ def test_build_dir_threads_suppressions(tmpdir): #14064 assert os.path.exists(a1Path) mtimeOld = os.path.getmtime(a1Path) + time.sleep(1) + for _ in range(1, 10): cppcheck(args, cwd=__script_dir) @@ -497,4 +499,4 @@ def test_unmatched_cfg(): '{}cfg.c:9:0: information: Unmatched suppression: id [unmatchedSuppression]'.format(__proj_inline_suppres_path), ] assert stdout == '' - assert ret == 0, stdout \ No newline at end of file + assert ret == 0, stdout From 8b97065b8c2bd7b3b7185a923ac51e4cedbc2f19 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 15 Aug 2025 16:36:26 +0200 Subject: [PATCH 11/11] Update inline-suppress_test.py --- test/cli/inline-suppress_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/cli/inline-suppress_test.py b/test/cli/inline-suppress_test.py index 3bc14455446..ce3b68768cf 100644 --- a/test/cli/inline-suppress_test.py +++ b/test/cli/inline-suppress_test.py @@ -5,6 +5,7 @@ import os import pytest import sys +import time from testutils import cppcheck __script_dir = os.path.dirname(os.path.abspath(__file__))