Repository navigation
Fix #12795 (FP knownConditionTrueFalse: object read through pointer may be changed by function call) - #9043
Open
tropibyte wants to merge 1 commit into
Open
Fix #12795 (FP knownConditionTrueFalse: object read through pointer may be changed by function call)#9043tropibyte wants to merge 1 commit into
tropibyte wants to merge 1 commit into
Conversation
…ay be changed by function call)
A member read through a local pointer ('p->i') was assumed unchanged across a
function call, so 'o = p->i; modify(); if (p->i == o)' was reported as always
true even when modify() can change the object.
Dereferencing a pointer is now treated as non-local unless the pointer is
known to point at a local object, or at memory from 'new' or a library
allocation function (malloc, calloc, ...) whose address never escapes the
function. 'new' of a type with a constructor or base class is treated
conservatively, since the constructor could store 'this'.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
p->i,*p,p[i]) is no longer assumed unchanged across a function call, unless the pointer is known to point at a local object, or at memory fromnewor a library allocation function (malloc,calloc, ...) whose address never escapes the function.porp->ito a function, taking&p->i, binding a reference, calling a member function throughp, returning or reassigningp, use in a lambda, placementnew, andnewof a type with a constructor or base class all keep the check quiet.&p->iinto a local that never escapes is also treated as an escape, so that rare true positive is not reported.TODO_ASSERTfor #12795 and adds cases fornew,calloc(C),static_cast<S*>(std::malloc(...)), and the escape variants.