diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 8d15c960b..88c28338b 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1160,6 +1160,11 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const if (Token::simpleMatch(tok, "asm (")) return Result(Result::Type::BAILOUT); + if (mWhat == What::ValueFlow && Token::Match(tok, "while|for (")) { + // TODO: only bailout if expr is reassigned in loop + return Result(Result::Type::BAILOUT); + } + if (!local && Token::Match(tok, "%name% (") && !Token::simpleMatch(tok->linkAt(1), ") {")) { // TODO: this is a quick bailout return Result(Result::Type::BAILOUT); diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 4663c24e9..ab7bfd4be 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -2437,6 +2437,16 @@ private: ASSERT_EQUALS(true, values.front().isIntValue()); ASSERT_EQUALS(1, values.front().intvalue); + code = "void f() {\n" + " S s;\n" + " s.x = 1;\n" + " int y = 10;\n" + " while (s.x < y)\n" // s.x does not have known value + " s.x++;\n" + "}"; + values = tokenValues(code, "<"); + ASSERT_EQUALS(true, values.empty()); + code = "void f() {\n" " Hints hints;\n" " hints.x = 1;\n"