Repository navigation
Fix #15308 (metrics: remove duplicate function metrics (functions in headers used in several TUs)) - #9113
Conversation
…headers used in several TUs))
…r and clang Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dmcppcheck
left a comment
There was a problem hiding this comment.
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
cppcheckandtestrunnerin/work/prwithout errors. python3 -m pytest -q test/cli/metrics_test.py: 3 passed, including the newtest_duplicate_metrics.- Reproduced the
HISCallingovercount. I used a stub addon and a project that checks one.cfile 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.
No description provided.