Repository navigation
Fix #15292 Whole program analysis hangs with --cppcheck-build-dir when a header with nested calls is included by many files - #9093
Open
autoantwort wants to merge 2 commits into
Conversation
…en a header with nested calls is included by many files) With a build dir every file brings its own copy of the calls in a header, so findPath() tried each of them on every level and searched the same failed states again and again. Remember the visited states during one search. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The test with 2000 files hit the timeout on slow CI runners even with the fix. 100 files with --max-ctu-depth=4 take 0.1 s with the fix and more than a minute without it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Result on the real project from the ticket (5676 files, Debug|Win32,
The remaining difference to before #9024 comes from the nested calls that are now loaded and the quadratic part mentioned in the description. The other differences in the results (missingReturn, uninitStructMember) come from other commits between b3d8256^ and main. The first version of the performance test (2000 files) hit the timeout on the slower CI runners even with the fix. It now uses 100 files with a deeper call chain and (Written by Claude Code on behalf of @autoantwort.) |
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.
https://trac.cppcheck.net/ticket/15292
Since #9024 nested calls are loaded from the build dir. With
--cppcheck-build-dir, the whole program analysis can now hang when a header with nested calls is included by many files.Reproducer:
Cause: with a build dir every file brings its own copy of the calls in the header, so each header function has N entries in the calls map.
findPath()tries all of them on every level and does not remember searches that failed. One unsafe usage costs about N² steps with the default--max-ctu-depth=2, and there is one unsafe usage per file.Fix:
findPath()remembers the (callId, callArgNr, index) states it has visited during one search. Within one search the result of a state only depends on these three values, and a success ends the whole search, so a repeated state has failed before and can be skipped. The paths that are found and reported do not change.On the real project from the ticket (5676 files, one header included by 4434 files) the whole program analysis did not finish within 2.5 hours on main. With this PR it takes 38 s (6.6 s before #9024) and reports the same results as before #9024, see the comment below.
Test:
test_slow_ctu_header_included_by_many_filesintest/cli/performance_test.py(100 files, a header with a chain of 5 functions,--max-ctu-depth=4): 0.13 s with this PR, hits the 20 s timeout without it.Limitations: the remaining cost is still quadratic in the number of files that include the header (N unsafe usages × N entries in the calls map). Deduplicating identical calls and unsafe usages from different files would remove that, but is not part of this PR.
This PR was created by Claude Code (an AI coding agent) on behalf of @autoantwort.
🤖 Generated with Claude Code