Repository navigation
Follow up #15213 (misra.py: the CTU step takes quadratic time when a typedef or tag name is declared at many locations) - #9095
Open
g-chauvel wants to merge 1 commit into
Conversation
…typedef or tag name is declared at many locations)
dmcppcheck
reviewed
Nov 30, 2026
dmcppcheck
left a comment
Contributor
There was a problem hiding this comment.
AI review
I found no problems. The new add_declaration() produces the same results as the old one. It uses the same (file, line) key as is_different_location(). On a duplicate it still reports the first declaration that was stored, because Python dicts keep insertion order, so next(iter(values())) is the old declarations[0]. The used flags are merged the same way as before. The two unused-declaration comprehensions were updated to match the dict. A differential test on random inputs gave the same violations and the same output on base and on the PR. Nobody had commented on the PR before this review.
Testing
- Built
cppcheckin/work/prwithmake -j8 cppcheck; the build succeeded. I did not buildtestrunner, because the PR changes only Python files. PYTHONPATH=addons python3 -m pytest -q addons/test/misra_test.py: 23 passed, including the newtest_ctu_declaration_locationcases.- Differential test (
/work/scratch/diff.py):- It loads
base/addons/misra.pyandpr/addons/misra.pyside by side. - For 3000 seeds it writes a random
.ctu-infofile with 1 to 8MisraTypedefInfo/MisraTagNamerecords. The records use random names (X/Y), files (a.h/b.h), lines and columns (1–2) andusedflags. - It runs
analyse_ctu_infowith each version and compares the sortedexisting_violationsand the stdout/stderr. - Result:
all same, with no difference in any case.
- It loads
- I did not time the 20000-file scenario from the description. A dict lookup instead of the linear scan removes the quadratic behaviour.
Automated review of 79e72ce by Claude. The pull request was built and tested locally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since #9053,
add_declaration()compares each declaration with all the previous ones of the same name, so a name declared at many locations makes the CTU step quadratic for 2.3, 2.4, 5.6 and 5.7. This PR keeps the declarations of a name in a dict keyed by(file, line), the same location test asis_different_location().With the same typedef name in every source file, on Linux:
real 0m1.698sreal 0m0.193sreal 0m6.362sreal 0m0.347sreal 0m24.614sreal 0m0.598s