Repository navigation
Fix #15264 FP knownConditionTrueFalse: then-block treated as always escaping when only one path through a nested if returns - #9070
Draft
autoantwort wants to merge 1 commit into
Conversation
…scaping when only one path through a nested if returns The forward traversal carries the true path of an opaque condition past the if on a fork. Since 4b66976 the main traversal also commits to the false path (absolute assumption) when the then-branch falls through. When the main path later escapes, the traversal reported Terminate::Escape although the fork fell through, so afterCondition() considered the block dead. A fork that is carried to the end of the whole traversal, or stops because the value is modified, now makes the result fall through, together with its actions. A fork that stops for another reason, or a then-path that stops in the branch or is not followed (fork limits), is unknown: if the main path escapes, the result is Terminate::Bail. The result stays Terminate::Escape if the traversed range ends with an escape. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Trac: https://trac.cppcheck.net/ticket/15264
Regression of #15042 (4b66976).
If
g()andbare true the then-block falls through, soacan be true at line 11. The same cause loses true positives, e.g.nullPointerRedundantCheckforif (!p) { ...same block... } use(*p);.Cause:
afterCondition()treats the then-block as dead when the forward traversal returnsTerminate::Escape. The traversal carries the true path of the opaqueg()past the innerifon a fork, and since 4b66976 the main traversal commits to the false path (absolute assumption). On the main pathwstays false, thereturnis taken and the traversal ends withEscape. The fork (w == true) falls through, but only the main traversal's terminate and actions are returned.Fix:
ForwardTraversalrecords how the carried forks end:Progress::Continue) or stopped because the value is modified makes the result fall through (Terminate::None), together with the fork's actions;Terminate::Bail;isEscapeScope) every path escapes and the result staysEscape.Forks inside a branch or loop body only walk to the end of that block and do not count.
Tests: snippets 1, 2 and 5 (the fork-limit case at normal level) of
TestCondition::knownConditionAfterConditionalEscapeandTestNullPointer::nullpointerAfterConditionalEscapefail without the fix. The other new snippets (including thezeroDivCondadditions) pass on main too; they guard against variants of the fix that over-reach (loop-body forks, bailing forks, fork limits).Limitations (unchanged vs main, listed in the ticket):
if, awhile/forbody, or a known-true innerif. Fixing that needs per-range tracking of the forks that fell through.--check-level=normal, because the then-path is not followed within the fork limits).The fix for #15266 (#9068) also touches
lib/forwardanalyzer.cpp; I have it rebased onto this branch and will update whichever PR is merged second.Verification: new tests fail without the fix,
testrunnerpasses. The light corpus (test/cfg,samples, normal and exhaustive) is unchanged and runtime is the same or lower. On a large internal code base the only change vs main is the removed FP.This PR was created by Claude Code (an AI coding agent) on behalf of @autoantwort.
🤖 Generated with Claude Code