Fix issue 9362: FP: (style) Condition '(v&1)==0' is always false (#2200)

This commit is contained in:
Paul Fultz II 2019-09-21 12:53:54 -05:00 committed by amai2012
parent da91c139d5
commit c1961cec1c
2 changed files with 14 additions and 0 deletions

View File

@ -770,6 +770,10 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
if (parent->isComparisonOp() && value.isImpossible()) if (parent->isComparisonOp() && value.isImpossible())
return; return;
// Skip operators with impossible values that are not invertible
if (Token::Match(parent, "%|/|&|%or%") && value.isImpossible())
return;
// known result when a operand is 0. // known result when a operand is 0.
if (Token::Match(parent, "[&*]") && value.isKnown() && value.isIntValue() && value.intvalue==0) { if (Token::Match(parent, "[&*]") && value.isKnown() && value.isIntValue() && value.intvalue==0) {
setTokenValue(parent, value, settings); setTokenValue(parent, value, settings);

View File

@ -3294,6 +3294,16 @@ private:
" else if (isdigit(c) != 0) {}\n" " else if (isdigit(c) != 0) {}\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #9362
check("uint8_t g();\n"
"void f() {\n"
" const uint8_t v = g();\n"
" if((v != 0x00)) {\n"
" if( (v & 0x01) == 0x00) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void alwaysTrueContainer() { void alwaysTrueContainer() {