Merge pull request #2721 from KenPatrickLehrmann/compound_assign_bitshift

Add missing operators <<= and >>=
This commit is contained in:
Daniel Marjamäki 2020-07-25 09:39:32 +02:00 committed by GitHub
commit fab3a8efc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -2106,6 +2106,10 @@ static bool evalAssignment(ValueFlow::Value &lhsValue, const std::string &assign
lhsValue.intvalue |= rhsValue.intvalue;
else if (assign == "^=")
lhsValue.intvalue ^= rhsValue.intvalue;
else if (assign == "<<=")
lhsValue.intvalue <<= rhsValue.intvalue;
else if (assign == ">>=")
lhsValue.intvalue >>= rhsValue.intvalue;
else
return false;
} else if (lhsValue.isFloatValue()) {

View File

@ -2530,6 +2530,20 @@ private:
" return x;\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 4U, 123.45F + 67, 0.01F));
code = "void f() {\n"
" int x = 123;\n"
" x >>= 1;\n"
" return x;\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 4U, 61));
code = "void f() {\n"
" int x = 123;\n"
" x <<= 1;\n"
" return x;\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 4U, 246));
}
void valueFlowForwardCorrelatedVariables() {