Repository navigation
add missing #line directive to misra.py - #8879
driftregion wants to merge 1 commit into
Conversation
| dir = mo.group(1) | ||
| if dir not in ['define', 'elif', 'else', 'endif', 'error', 'if', 'ifdef', 'ifndef', 'include', | ||
| 'pragma', 'undef', 'warning']: | ||
| 'pragma', 'undef', 'warning', 'line']: |
There was a problem hiding this comment.
This is an AI review. Take it with a grain of salt and feel free to reject it by resolving the comment.
The fix looks right to me: #line is a standard directive, and with this change the 20.13 false positive is gone.
Could you add a regression test? One option that doesn't shift any line numbers in addons/test/misra/misra-test.c is to replace the empty line after #else1 // 20.13 (line 1946) with:
#line 1947I tried it with the same commands CI uses (cppcheck --dump -DDUMMY --suppress=uninitvar --inline-suppr misra/misra-test.c --std=c89 --platform=unix64 + misra.py -verify). Without your fix it reports Not expected: misra/misra-test.c:1946 20.13, and with your fix it passes.
There was a problem hiding this comment.
Hi Daniel, thanks for your work maintaining cppcheck. I had a look at the AI reviews on #8879, #8876, and cppcheck-opensource/simplecpp#704 just now. They seem reasonable. Before I go about addressing them, I'd like to request your human opinion on whether you endorse the AI-proposed changes. This statement makes it clear that the review was AI-generated (great idea btw), but leaves me with some confusion about whether the human in the loop endorses its content:
This is an AI review. Take it with a grain of salt and feel free to reject it by resolving the comment.
Thanks!
There was a problem hiding this comment.
I looked quickly. Adding that test seems reasonable to me.
I will mostly trust peoples judgments about AI reviews.
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no new problems. With this change, #line directives are no longer reported as misra-c2012-20.13, and I checked all the ways of spelling the directive that I tried. A malformed directive such as #lines 3 is still reported. The PR still doesn't add the regression test that was asked for in comments.md (#line 1947 in addons/test/misra/misra-test.c). That has already been raised, so I'm not repeating it as a separate comment.
Testing
- I built
cppcheckinpr/withmake -j8 cppcheck. - I wrote
scratch/t.cwith several spellings of the directive:I ran#line 10 # line 20 "x.c" # line 30 #line 40 # line 50 #lines 3 int x;
cppcheck --dump -q t.cand thenpython3 misra.py t.c.dumpwith both the PR's and the base'smisra.py.- PR: 20.13 is reported only for
#lines 3(x.c:50), which is correct. - Base: 20.13 is reported for all 6 directives.
- simplecpp turns tabs into single spaces in the directive string in the dump, so the space-only regex in
misra_20_13handles those cases correctly.
- PR: 20.13 is reported only for
- Existing MISRA verify test: I ran
cppcheck --dump -DDUMMY --suppress=uninitvar --inline-suppr misra/misra-test.c --std=c89 --platform=unix64followed bymisra.py -verify misra/misra-test.c.dump. It reported noNot expectedorNot detectedlines. - pytest:
python3 -m pytest addons/test/misra_test.pystopped with a collection error before running any tests, so that suite was not run. I did not look into the cause.
Automated review of d4aa765 by Claude. The pull request was built and tested locally.
Hello cppcheck maintainer. Thank you for your work.
The
#linepreprocessor directive (standard since C90) was missing from misra.py, leading to false positives in my analysis. I have added it here.See:
https://en.cppreference.com/c/preprocessor/line