Repository navigation
Fix #15219 FP constVariablePointer (pointer assignment with offset) #9033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
85ee700
a5d70b1
77ceb53
a236dc8
5db5d7f
d241c95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2007,8 +2007,8 @@ void CheckOtherImpl::checkConstPointer() | |
| pointers.emplace(var); | ||
| const Token* parent = tok->astParent(); | ||
| enum Deref : std::uint8_t { NONE, DEREF, MEMBER } deref = NONE; | ||
| bool hasIncDecPlus = false; | ||
| if (parent && (parent->isUnaryOp("*") || (((hasIncDecPlus = parent->isIncDecOp()) || (hasIncDecPlus = (parent->str() == "+"))) && | ||
| bool hasIncDecPlusMinus = false; | ||
| if (parent && (parent->isUnaryOp("*") || (((hasIncDecPlusMinus = parent->isIncDecOp()) || (hasIncDecPlusMinus = Token::Match(parent, "[+-]"))) && | ||
| parent->astParent() && parent->astParent()->isUnaryOp("*")))) | ||
| deref = DEREF; | ||
| else if (Token::simpleMatch(parent, "[") && parent->astOperand1() == tok && tok != nameTok) | ||
|
|
@@ -2044,7 +2044,7 @@ void CheckOtherImpl::checkConstPointer() | |
| } | ||
| } | ||
| } | ||
| if (hasIncDecPlus) { | ||
| if (hasIncDecPlusMinus) { | ||
| parent = gparent; | ||
| gparent = gparent ? gparent->astParent() : nullptr; | ||
| } | ||
|
|
@@ -2079,9 +2079,11 @@ void CheckOtherImpl::checkConstPointer() | |
| } | ||
| } else { | ||
| int argn = -1; | ||
| if (Token::Match(parent, "%oror%|%comp%|&&|?|!|-|<<|;")) | ||
| if (Token::Match(parent, "%oror%|%comp%|&&|?|!|<<|;")) | ||
| continue; | ||
| if (hasIncDecPlus && (!parent->astParent() || parent->astParent()->str() == ";")) | ||
| if (Token::simpleMatch(parent, "-") && parent->valueType() && parent->valueType()->pointer == 0) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI review This drops warnings when the pointer subtraction is only read. Treating Also, when the |
||
| continue; | ||
| if (hasIncDecPlusMinus && (!parent->astParent() || parent->astParent()->str() == ";")) | ||
| continue; | ||
| if (Token::simpleMatch(parent, "(") && Token::Match(parent->astOperand1(), "if|while")) | ||
| continue; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI review
Two more read-only cases that warned on main are silent now:
Both gave
constParameterPointeron main. With the PR they give nothing. Their+versions are not reported on main either, so this is the same existing gap for+that now also applies to-. It may be worth adding them to ticket 15227.