ValueFlow: Don't calculate x<<64 and x>>64

This commit is contained in:
Daniel Marjamäki 2016-11-06 20:40:58 +01:00
parent dd69d5eabe
commit ac7b351d1e
2 changed files with 4 additions and 2 deletions

View File

@ -432,7 +432,7 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
result.intvalue = value1->intvalue > value2->intvalue;
else if (parent->str() == ">=")
result.intvalue = value1->intvalue >= value2->intvalue;
else if (parent->str() == ">>" && value1->intvalue >= 0 && value2->intvalue >= 0)
else if (parent->str() == ">>" && value1->intvalue >= 0 && value2->intvalue >= 0 && value2->intvalue < 64)
result.intvalue = value1->intvalue >> value2->intvalue;
else
break;
@ -445,7 +445,7 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
result.intvalue = value1->intvalue < value2->intvalue;
else if (parent->str() == "<=")
result.intvalue = value1->intvalue <= value2->intvalue;
else if (parent->str() == "<<" && value1->intvalue >= 0 && value2->intvalue >= 0)
else if (parent->str() == "<<" && value1->intvalue >= 0 && value2->intvalue >= 0 && value2->intvalue < 64)
result.intvalue = value1->intvalue << value2->intvalue;
else
break;

View File

@ -282,8 +282,10 @@ private:
// Don't calculate if there is UB
ASSERT(tokenValues("-1<<10","<<").empty());
ASSERT(tokenValues("10<<-1","<<").empty());
ASSERT(tokenValues("10<<64","<<").empty());
ASSERT(tokenValues("-1>>10",">>").empty());
ASSERT(tokenValues("10>>-1",">>").empty());
ASSERT(tokenValues("10>>64",">>").empty());
// calculation using 1,2 variables/values
code = "void f(int x) {\n"