Fix 10148: False positive: knownConditionTrueFalse in for loop due to &= (#3425)
This commit is contained in:
parent
6541efdb9a
commit
4566e0e439
|
@ -2160,6 +2160,9 @@ struct ValueFlowAnalyzer : Analyzer {
|
|||
if (!(value->isIntValue() || value->isFloatValue() || value->isSymbolicValue()))
|
||||
return Action::None;
|
||||
const Token* parent = tok->astParent();
|
||||
// Only if its invertible
|
||||
if (value->isImpossible() && !Token::Match(parent, "+=|-=|*=|++|--"))
|
||||
return Action::None;
|
||||
|
||||
if (parent && parent->isAssignmentOp() && astIsLHS(tok) &&
|
||||
parent->astOperand2()->hasKnownValue()) {
|
||||
|
|
|
@ -3770,6 +3770,17 @@ private:
|
|||
" return a || ! b || ! a;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Condition '!a' is always true\n", errout.str());
|
||||
|
||||
// #10148
|
||||
check("void f(int i) {\n"
|
||||
" if (i >= 64) {}\n"
|
||||
" else if (i >= 32) {\n"
|
||||
" i &= 31;\n"
|
||||
" if (i == 0) {}\n"
|
||||
" else {}\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void alwaysTrueSymbolic()
|
||||
|
|
Loading…
Reference in New Issue