Merge pull request #835 from JIghtuse/master

Fixed #7139 (ValueFlow: Missed shift operation in for expression)
This commit is contained in:
Daniel Marjamäki 2016-10-04 12:23:33 +02:00 committed by GitHub
commit 4f922f56cb
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());
}
};