Repository navigation
Fix #15246 (Remove the unexpanded macro name filter from setLocationMacros) - #9056
Conversation
|
There should probably be a trac ticket for this PR. Please create it, or ask us to create it. Then the PR title should be updated. |
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no new problems in the PR's own commit (0d83da1). That commit removes the unexpanded-name filter from setLocationMacros and adds a test for it.
simplecpp 1.10.2 only records a usage in two cases: when a macro is really expanded, or when the name appears in a directive (#ifdef, #ifndef, defined, or a function-like name without ( in #if). Directive lines produce no tokens, so those usages never match an entry in mLocationMacros. The filter therefore has nothing left to catch.
I tried several ways of putting a bare or indirectly used function-like macro name on the same line as DIV(1,0). In none of them was the zerodiv wrongly suppressed. Usages that really are expanded on the line are still suppressed, as before.
The other commits (the simplecpp 1.10.x update from #9048) were not the focus of this review.
Testing
-
Build:
make -j8 cppcheck testrunnerinpr/succeeded. -
Unit tests:
./testrunner TestSuppressions TestPreprocessor TestCppcheckran 271 tests with 0 failures and 6 todos. -
Python tests:
python3 -m pytest other_test.pyintest/cligave 210 passed and 10 failed. All 10 failures come from the environment, not from the PR:- the
--rule/--rule-filetests fail because this build has no rules support; - the
test_redundant_file_readstests fail withFileNotFoundError, probably because strace is missing here.
None of the tests that the PR changes failed.
- the
-
Manual tests, run with
cppcheck --inline-suppr --enable=information. In each caseALIAShascppcheck-suppress-macro zerodivon its definition andDIVdoes not:- These should still report zerodiv, and they do. The
ALIASsuppression is reported as unmatched, and the dump has no usage ofALIAS:int ALIAS = DIV(1,0);#define G ALIASthenint G = DIV(1,0);int ID(ALIAS) = DIV(1,0);sizeof(int(*)[ID(ALIAS)])on the same line asDIV(1,0)int ALIAS; int x = DIV(1,0);
- These should be suppressed, and they are:
DIV(1,0) + CALL(ALIAS)with#define CALL(m) m(1,1), and the self-referential macros#define x xand#define F(a) F(a)when they are expanded on the line of aDIV(1,0).
- These should still report zerodiv, and they do. The
-
I did not build
base/for a comparison, because it also has the older simplecpp and the results would not isolate this commit.
Automated review of 0d83da1 by Claude. The pull request was built and tested locally.
|
Test results for commit 0d83da1 (tools/test-my-pr.py, main compared to this PR): Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-9056/ Posted automatically by the cppcheck PR test runner. +N: warnings only with this PR, -N: warnings only with main. The AI review is written by Claude and can be wrong. |
|
Created https://trac.cppcheck.net/ticket/15246 and updated the PR title. |
0d83da1 to
0613c15
Compare
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no new problems in this PR's own commit, which removes the unexpanded-name filter from setLocationMacros and adds a TestSuppressions case. To isolate that change, I built a copy of the PR with only the old filter put back in lib/cppcheck.cpp. On 15 inputs, it and the PR's cppcheck gave identical results. The inputs put a bare or indirectly used function-like macro name on the same line as DIV(1,0). So with simplecpp 1.10.2 the filter no longer changes the results. The trac ticket that C1 asked for has been created, and the title has been updated.
Comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | PR should have a trac ticket and an updated title | @dmcppcheck | general | ✅ Fixed |
Testing
Builds: make -j8 cppcheck testrunner in pr/ succeeded, and make -j8 cppcheck in base/ succeeded. I also built a copy of pr/ (scratch/prf) where lib/cppcheck.cpp is replaced by the base version, which still has the filter. All other code is the same as the PR, so any difference between the two would come from removing the filter.
Unit tests: ./testrunner TestSuppressions TestPreprocessor TestCppcheck ran 271 tests with 0 failures and 6 todos.
Manual tests: each file starts with
#define DIV(A,B) A/B
// cppcheck-suppress-macro zerodiv
#define ALIAS(A,B) A/BEach was run with cppcheck -q --inline-suppr --enable=information --template='{line}:{column} {id}', using the PR's cppcheck and the cppcheck with the filter put back. The bodies tested:
int ALIAS = DIV(1,0);ALIAS LP 1,0), whereLPis defined as(#define F ALIASfollowed byF(1,0)ID(ALIAS)(1,0)andID(ALIAS) + DIV(1,0)ALIAS(1,0) + DIV(1,0)G(ALIAS), whereG(x)isx(1,0)STR(ALIAS(1,0)), whereSTRstringifies its argumentCAT(ALI,AS)(1,0), whereCATpastes its arguments together#define ALIAS2 ALIAS#if defined(ALIAS)before the line withDIV#ifdef ALIASin the middle of a statementDIV(ALIAS,0)#linedirectives that give an#ifdef ALIASline the same line number as theDIVline- a self-referencing function-like macro,
S(A,B) S + A/B, next to a variable namedS
Both builds gave the same output for every file. The zerodiv was suppressed only where ALIAS (or the suppressed macro) is really expanded on the line. That is the existing line-based behaviour and was not changed by this PR.
Automated review of 0613c15 by Claude. The pull request was built and tested locally.
|
This pull request has merge conflicts that must be resolved. |
The filter skipped a macro usage whose location held the bare name of a function-like macro, because simplecpp recorded a usage there although nothing was expanded. simplecpp 1.10.2 no longer records it (cppcheck-opensource/simplecpp#759), so the filter has nothing left to do. The existing test for that case passes with or without the filter, as no other macro is expanded on its line. The new test puts DIV(1,0) on the same line as a bare ALIAS, and fails if simplecpp records the bare name and the filter is gone. The comment on the usage loop now says what it skips: usages on lines without macro-expanded tokens.
0613c15 to
b277a55
Compare
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no new problems. With simplecpp 1.10.2, a bare function-like macro name no longer gets a macro usage, so the removed filter in setLocationMacros had nothing left to catch. The simplified loop behaves the same as before. C2 and C5 already compared the PR with a build that still has the filter and saw no difference on a wide range of inputs. The containers and algorithms still used in lib/cppcheck.cpp (std::set, std::transform, std::inserter) are used elsewhere in the file, so removing this code leaves no includes unused.
Comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | PR should have a trac ticket and an updated title | @dmcppcheck | general | ✅ Fixed |
Testing
- Build:
make -j8 cppcheck testrunnerinpr/succeeded. - Unit tests:
./testrunner TestSuppressions TestPreprocessor TestCppcheckran 271 tests with 0 failures and 6 todos. - Manual test: I ran
cppcheck -q --inline-suppr --enable=informationon a file whereALIAShascppcheck-suppress-macro zerodivand this line contains both a bareALIASand a realALIAS(1,0)expansion:int ALIAS = DIV(1,0); int y = ALIAS(1,0);
- Both zerodivs on that line were suppressed. That is the existing line-based behaviour:
ALIASis really expanded on the line. The PR does not change it. - The PR's own new test, with only the bare name on the line, reports zerodiv as it should.
- Both zerodivs on that line were suppressed. That is the existing line-based behaviour:
- Not repeated: C2 and C5 already covered the wider set of bare and indirect macro-name inputs and the comparison with the filter put back, so I did not run them again.
Automated review of b277a55 by Claude. The pull request was built and tested locally.
|
Re the manual test where both zerodivs on |
|
Test results for commit b277a55 (tools/test-my-pr.py, main compared to this PR): Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-9056/ Posted automatically by the cppcheck PR test runner. +N: warnings only with this PR, -N: warnings only with main. The AI review is written by Claude and can be wrong. |
https://trac.cppcheck.net/ticket/15246
Rebased onto main now that #9048 is merged.
#9018 added a filter to
setLocationMacrosthat skips a macro usage at the position of a bare function-like macro name, because simplecpp recorded a usage there although nothing was expanded. simplecpp 1.10.2 doesn't record it anymore (cppcheck-opensource/simplecpp#759), so the filter has nothing left to do.The test I added in #9018 for that case turned out not to cover the filter. It has no other macro on the line, so the usage never reached
mLocationMacroseither way. The new test putsDIV(1,0)on the same line as a bareALIASwithcppcheck-suppress-macro zerodivonALIAS. Confirmed it fails with the filter removed and simplecpp's old usage order put back, and passes on 1.10.2.TestSuppressions, TestPreprocessor and TestCppcheck pass on macOS arm64 with
-Werror, andrunformatwith uncrustify 0.80.1 makes no changes.