ValueFlow: remove handling of == for complex expressions it did not work properly

This commit is contained in:
Daniel Marjamäki 2019-01-01 17:23:46 +01:00
parent 20436ea986
commit be7afac875
2 changed files with 3 additions and 19 deletions

View File

@ -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<Token *>(tok2), v, settings);
}
}

View File

@ -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() {