Fix 10956: ValueFlow: Incorrect value when assigned to two variables (#4019)
* Fix 10956: ValueFlow: Incorrect value when assigned to two variables * Format
This commit is contained in:
parent
7721cd14b6
commit
09597bc7e8
|
@ -786,20 +786,6 @@ static ValueFlow::Value execute(const Token* expr, ProgramMemory& pm, const Sett
|
||||||
return v;
|
return v;
|
||||||
if (pm.hasValue(expr->exprId()))
|
if (pm.hasValue(expr->exprId()))
|
||||||
return pm.at(expr->exprId());
|
return pm.at(expr->exprId());
|
||||||
// Find symbolic values
|
|
||||||
for (const ValueFlow::Value& value : expr->values()) {
|
|
||||||
if (!value.isSymbolicValue())
|
|
||||||
continue;
|
|
||||||
// TODO: Handle possible symbolic values
|
|
||||||
if (!value.isKnown())
|
|
||||||
continue;
|
|
||||||
if (!pm.hasValue(value.tokvalue->exprId()))
|
|
||||||
continue;
|
|
||||||
ValueFlow::Value v2 = pm.at(value.tokvalue->exprId());
|
|
||||||
v2.intvalue += value.intvalue;
|
|
||||||
v2.valueKind = value.valueKind;
|
|
||||||
return v2;
|
|
||||||
}
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2286,6 +2286,7 @@ struct ValueFlowAnalyzer : Analyzer {
|
||||||
return v.isSymbolicValue() && currValue->equalValue(v);
|
return v.isSymbolicValue() && currValue->equalValue(v);
|
||||||
}))
|
}))
|
||||||
return false;
|
return false;
|
||||||
|
const bool isPoint = currValue->bound == ValueFlow::Value::Bound::Point && currValue->isIntValue();
|
||||||
const bool exact = !currValue->isIntValue() || currValue->isImpossible();
|
const bool exact = !currValue->isIntValue() || currValue->isImpossible();
|
||||||
for (const ValueFlow::Value& v : tok->values()) {
|
for (const ValueFlow::Value& v : tok->values()) {
|
||||||
if (!v.isSymbolicValue())
|
if (!v.isSymbolicValue())
|
||||||
|
@ -2295,7 +2296,7 @@ struct ValueFlowAnalyzer : Analyzer {
|
||||||
const bool toImpossible = v.isImpossible() && currValue->isKnown();
|
const bool toImpossible = v.isImpossible() && currValue->isKnown();
|
||||||
if (!v.isKnown() && !toImpossible)
|
if (!v.isKnown() && !toImpossible)
|
||||||
continue;
|
continue;
|
||||||
if (exact && v.intvalue != 0)
|
if (exact && v.intvalue != 0 && !isPoint)
|
||||||
continue;
|
continue;
|
||||||
std::vector<MathLib::bigint> r;
|
std::vector<MathLib::bigint> r;
|
||||||
ValueFlow::Value::Bound bound = currValue->bound;
|
ValueFlow::Value::Bound bound = currValue->bound;
|
||||||
|
|
|
@ -7143,6 +7143,17 @@ private:
|
||||||
" return 1 / x;\n"
|
" return 1 / x;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
|
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
|
||||||
|
|
||||||
|
code = "void f(int k) {\n"
|
||||||
|
" int x = k;\n"
|
||||||
|
" int j = k;\n"
|
||||||
|
" x--;\n"
|
||||||
|
" if (k != 0) {\n"
|
||||||
|
" x;\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n";
|
||||||
|
ASSERT_EQUALS(false, testValueOfX(code, 6U, -1));
|
||||||
|
ASSERT_EQUALS(true, testValueOfXImpossible(code, 6U, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueFlowSymbolicIdentity()
|
void valueFlowSymbolicIdentity()
|
||||||
|
|
Loading…
Reference in New Issue