Repository navigation
Fix #15226 FP constParameterPointer with unknown types or functions #9083
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
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 |
|---|---|---|
|
|
@@ -2053,7 +2053,7 @@ void CheckOtherImpl::checkConstPointer() | |
| int argn = -1; | ||
| if (Token::simpleMatch(gparent, "return")) { | ||
| const Function* function = getEnclosingFunction(var); | ||
| if (function && (!Function::returnsReference(function) || Function::returnsConst(function))) | ||
| if (function && (!Function::returnsReference(function, /*unknown*/ true) || Function::returnsConst(function))) | ||
|
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
auto f1(int* p) { return *p; } // constParameterPointer lost (base reports it)
int f3() { int i = 0; return [](int* p) { return *p; }(&i); } // lost, see the new TODO in testother.cppThe ticket case |
||
| continue; | ||
| } | ||
| else if (Token::Match(gparent, "%assign%") && parent == gparent->astOperand2()) { | ||
|
|
||
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
With this change, a
+/-whose valueType is unknown is skipped too. That covers any operand of unknown type: an undeclared function call, or a variable of an unknown typeU. Ing(h() + x),getTokenArgumentFunction(x)now returnsg. Becausegis unknown,isVariableChangedByFunctionCall()falls through to "Safe guess: Assume that parameter is changed", although only a temporary is passed.Reproduced regressions, all reported by base and no longer by the PR:
It would be safer to skip the operator only when one of its operands is (or may be) a pointer, for example when the operand
tokitself has a pointer valueType. Alternatively, fix the #15226 case incheckConstPointeralone instead of in this shared helper, which has more than 15 callers.