Fixed #7139 (ValueFlow: Missed shift operation in for expression)

This commit is contained in:
Boris Egorov 2016-10-04 13:06:48 +07:00
parent ba6cda9c86
commit a32f61ae4a
2 changed files with 17 additions and 0 deletions

View File

@ -1929,6 +1929,10 @@ static void execute(const Token *expr,
*result = result1 / result2;
else if (expr->str() == "%")
*result = result1 % result2;
else if (expr->str() == "<<")
*result = result1 << result2;
else if (expr->str() == ">>")
*result = result1 >> result2;
}
else if (expr->str() == "&&") {

View File

@ -1968,6 +1968,19 @@ private:
value = valueOfTok(code, "&");
ASSERT_EQUALS(0, value.intvalue);
ASSERT(value.isKnown());
// Ticket #7139
// "<<" in third expression of for
code = "void f(void) {\n"
" int bit, x;\n"
" for (bit = 1, x = 0; bit < 128; bit = bit << 1, x++) {\n"
" z = x;\n" // <- known value [0..6]
" }\n"
"}\n";
ASSERT_EQUALS(true, testValueOfX(code, 4U, 0));
ASSERT_EQUALS(true, testValueOfX(code, 4U, 6));
ASSERT_EQUALS(false, testValueOfX(code, 4U, 7));
ASSERT(value.isKnown());
}
};