-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix #8266 identicalConditionAfterEarlyExit variable modified in if-clause #3610
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
Conversation
lib/astutils.cpp
Outdated
ftok = ftok->astParent(); | ||
if (ftok && ftok->tokType() == Token::eLogicalOp) | ||
ptok = ftok->astOperand1(); // check lhs |
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.
Why are we moving to the lhs side of logical ops? Wont this miss the parent function call? This seems like it would jump to g
in the expression f(g(x) || y)
instead of f
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.
The example looks something like if (g(b) || b)
, and g(b)
was not considered so far.
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.
Ah yea but you need to check isVariableChanged
on the first b
and not the second b
. The first b
should return true and the second b
should return false.
lib/astutils.cpp
Outdated
if ((ftok && Token::Match(ftok->link(), ")|} !!{")) || (ptok && Token::Match(ptok->link(), ")|} !!{"))) { | ||
bool isChanged = false, inconclusive = false; | ||
if (ptok) { | ||
isChanged |= isVariableChangedByFunctionCall(ptok->next(), indirect, settings, &inconclusive); // lhs can be a function |
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.
Whats the reason to pass ptok->next()
?
lib/checkcondition.cpp
Outdated
@@ -707,7 +707,8 @@ void CheckCondition::multiCondition2() | |||
return ChildrenToVisit::op1_and_op2; | |||
|
|||
if ((!cond1->hasKnownIntValue() || !secondCondition->hasKnownIntValue()) && | |||
isSameExpression(mTokenizer->isCPP(), true, cond1, secondCondition, mSettings->library, true, true, &errorPath)) { | |||
isSameExpression(mTokenizer->isCPP(), true, cond1, secondCondition, mSettings->library, true, true, &errorPath) && | |||
!isExpressionChangedAt(cond1, secondCondition, 0, false, mSettings, mTokenizer->isCPP())) { |
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.
Dont you need to check if the expression is changed before the secondCondtion
not at the secondCondition
?
Above at line 663, we check if the variables are changed in the second condition. It should probably just be changed to just use isExpressionChanged(cond1, condStartToken, condEndToken, 0, false, mSettings, mTokenizer->isCPP())
.
|
What assumptions are you talking about?
Yes, mostly. Although, it seems like we should remove this |
Back to the unmodified code, with the test case
Under which circumstances is |
Are you referring to line 657? That is only checking for changes before the At line 663, it checks if the second condition modifies the variable or expression. Of course, its quite in adequate and should just use
It should return true when |
a6e1886
to
cf203e2
Compare
Using |
Is this OK now? |
It looks good to me. If @pfultz2 has no complaint I think we should merge it. |
LGTM |
For discussion.
This reinstates some warnings associated with #9914, which were specifically suppressed at one point. However, it sounds like the warnings are now OK again?