From be7afac875106abfd19c4f1ac9f0c8cd40903191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 1 Jan 2019 17:23:46 +0100 Subject: [PATCH] ValueFlow: remove handling of == for complex expressions it did not work properly --- lib/valueflow.cpp | 12 +++--------- test/testvalueflow.cpp | 10 ---------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 68a9b6af9..d96988ab1 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -4669,20 +4669,14 @@ static void valueFlowContainerAfterCondition(TokenList *tokenlist, static void valueFlowFwdAnalysis(const TokenList *tokenlist, const Settings *settings) { for (const Token *tok = tokenlist->front(); tok; tok = tok->next()) { - if (!Token::Match(tok, "=|==") || !tok->astOperand1() || !tok->astOperand2()) + if (tok->str() != "=" || !tok->astOperand1() || !tok->astOperand2()) continue; if (!tok->scope()->isExecutable()) continue; if (!tok->astOperand2()->hasKnownIntValue()) continue; - const bool assign = tok->isAssignmentOp(); ValueFlow::Value v(tok->astOperand2()->values().front()); - if (assign) - v.errorPath.emplace_back(tok, tok->astOperand1()->expressionString() + " is assigned value " + MathLib::toString(v.intvalue)); - else { - v.errorPath.emplace_back(tok, "Assuming that " + tok->astOperand1()->expressionString() + " has the value " + MathLib::toString(v.intvalue)); - v.condition = tok; - } + v.errorPath.emplace_back(tok, tok->astOperand1()->expressionString() + " is assigned value " + MathLib::toString(v.intvalue)); FwdAnalysis fwdAnalysis(tokenlist->isCPP(), settings->library); const Token *startToken = tok->findExpressionStartEndTokens().second->next(); const Scope *functionScope = tok->scope(); @@ -4693,7 +4687,7 @@ static void valueFlowFwdAnalysis(const TokenList *tokenlist, const Settings *set const Scope *s = tok2->scope(); while (s && s != tok->scope()) s = s->nestedIn; - v.valueKind = assign && s ? ValueFlow::Value::ValueKind::Known : ValueFlow::Value::ValueKind::Possible; + v.valueKind = s ? ValueFlow::Value::ValueKind::Known : ValueFlow::Value::ValueKind::Possible; setTokenValue(const_cast(tok2), v, settings); } } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 89d418afc..44b958269 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -2436,16 +2436,6 @@ private: ASSERT_EQUALS(true, values.front().isKnown()); ASSERT_EQUALS(true, values.front().isIntValue()); ASSERT_EQUALS(1, values.front().intvalue); - - code = "void f(const Foo foo) {\n" - " if (foo.x == 2) {}\n" - " x = 0 + foo.x;\n" // <- foo.x might be 2 - "}"; - values = tokenValues(code, "+"); - ASSERT_EQUALS(1U, values.size()); - ASSERT_EQUALS(false, values.front().isKnown()); - ASSERT_EQUALS(true, values.front().isIntValue()); - ASSERT_EQUALS(2, values.front().intvalue); } void valueFlowSwitchVariable() {