From a32f61ae4a60af790ce82648a75f978bf5dfc3ba Mon Sep 17 00:00:00 2001 From: Boris Egorov Date: Tue, 4 Oct 2016 13:06:48 +0700 Subject: [PATCH] Fixed #7139 (ValueFlow: Missed shift operation in for expression) --- lib/valueflow.cpp | 4 ++++ test/testvalueflow.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index a0cf3330a..14e3d11d9 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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() == "&&") { diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 7d5b5d3d2..f986326e4 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -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()); } };