Skip to content

Fix #15308 (metrics: remove duplicate function metrics (functions in headers used in several TUs)) - #9113

Merged
danmar merged 2 commits into
cppcheck-opensource:mainfrom
cppchecksolutions:fix-15308
Dec 3, 2026
Merged

danmar merged 2 commits into
cppcheck-opensource:mainfrom
cppchecksolutions:fix-15308

Conversation

@danmar

@danmar danmar commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

danmar and others added 2 commits December 3, 2026 15:49
…r and clang

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@dmcppcheck dmcppcheck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

The PR now adds up HISCalling values every time a function is reported, even when the reports come from the same file checked twice, so the totals come out too high. A project can list one source file several times, for example with different -D flags in compile_commands.json or as several Visual Studio configurations. The function defined in that file then gets its HISCalling multiplied by the number of configurations. I reproduced this: a function with value 2 in a file checked twice is reported with value="4". A header function called by another inline function in the same header will probably be counted once per TU in the same way, which also double-counts one caller. The other metrics are de-duplicated correctly. comments.md has no earlier comments.

Comments

# Comment By Where Status
1 HISCalling summed again when the same TU/configuration is reported more than once AI review cli/cppcheckexecutor.cpp:168 🆕 New

@danmar, please fix, resolve or reply to the open and new comments: #1.

Testing

  • Built cppcheck and testrunner in /work/pr without errors.
  • python3 -m pytest -q test/cli/metrics_test.py: 3 passed, including the new test_duplicate_metrics.
  • Reproduced the HISCalling overcount. I used a stub addon and a project that checks one .c file under two configurations.

addon.py:

import sys
print('{"metric":{"fileName":"a.c","function":"f","id":"HISCalling","lineNumber":1,"value":2}}')
print('{"metric":{"fileName":"a.c","function":"f","id":"HISStmt","lineNumber":1,"value":4}}')

a.c: void f(void){}

compile_commands.json:

[{"directory":"/work/scratch","command":"gcc -DCFG1 -c a.c","file":"a.c"},
 {"directory":"/work/scratch","command":"gcc -DCFG2 -c a.c","file":"a.c"}]
$ cppcheck --project=compile_commands.json --addon=addon.py --xml-version=3 -q
    <metrics>
        <metric fileName="a.c" function="f" id="HISCalling" lineNumber="1" value="4"/>
        <metric fileName="a.c" function="f" id="HISStmt" lineNumber="1" value="4"/>
    </metrics>

HISStmt is de-duplicated correctly, but HISCalling is 4 when it should be 2. The output is the same with -j2.


Automated review of 3ed8273 by Claude. The pull request was built and tested locally.

Comment thread cli/cppcheckexecutor.cpp Resolved
@danmar
danmar merged commit 5e00e72 into cppcheck-opensource:main Dec 3, 2026
74 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants