Bug hunting; Better handling of constant
This commit is contained in:
parent
bb6b4f9f41
commit
65721dd7a9
|
@ -464,6 +464,17 @@ namespace {
|
||||||
return it->second;
|
return it->second;
|
||||||
if (!valueType)
|
if (!valueType)
|
||||||
return ExprEngine::ValuePtr();
|
return ExprEngine::ValuePtr();
|
||||||
|
|
||||||
|
// constant value..
|
||||||
|
const Variable *var = tokenizer->getSymbolDatabase()->getVariableFromVarId(varId);
|
||||||
|
if (var && valueType->constness == 1 && Token::Match(var->nameToken(), "%var% =")) {
|
||||||
|
const Token *initExpr = var->nameToken()->next()->astOperand2();
|
||||||
|
if (initExpr && initExpr->hasKnownIntValue()) {
|
||||||
|
auto intval = initExpr->getKnownIntValue();
|
||||||
|
return std::make_shared<ExprEngine::IntRange>(std::to_string(intval), intval, intval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ExprEngine::ValuePtr value = getValueRangeFromValueType(getNewSymbolName(), valueType, *settings);
|
ExprEngine::ValuePtr value = getValueRangeFromValueType(getNewSymbolName(), valueType, *settings);
|
||||||
if (value) {
|
if (value) {
|
||||||
if (tok->variable() && tok->variable()->nameToken())
|
if (tok->variable() && tok->variable()->nameToken())
|
||||||
|
|
|
@ -51,6 +51,8 @@ private:
|
||||||
TEST_CASE(exprAssign1);
|
TEST_CASE(exprAssign1);
|
||||||
TEST_CASE(exprAssign2); // Truncation
|
TEST_CASE(exprAssign2); // Truncation
|
||||||
|
|
||||||
|
TEST_CASE(getValueConst1);
|
||||||
|
|
||||||
TEST_CASE(inc1);
|
TEST_CASE(inc1);
|
||||||
TEST_CASE(inc2);
|
TEST_CASE(inc2);
|
||||||
|
|
||||||
|
@ -348,6 +350,12 @@ private:
|
||||||
ASSERT_EQUALS("2", getRange("void f(unsigned char x) { x = 258; int a = x }", "a=x"));
|
ASSERT_EQUALS("2", getRange("void f(unsigned char x) { x = 258; int a = x }", "a=x"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void getValueConst1() { // Data::getValue
|
||||||
|
ASSERT_EQUALS("512", getRange("const int x=512; void func() { x=x }", "x=x"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void inc1() {
|
void inc1() {
|
||||||
ASSERT_EQUALS("(and (>= $1 (- 2147483648)) (<= $1 2147483647))\n"
|
ASSERT_EQUALS("(and (>= $1 (- 2147483648)) (<= $1 2147483647))\n"
|
||||||
"(= (+ $1 1) $1)\n"
|
"(= (+ $1 1) $1)\n"
|
||||||
|
|
Loading…
Reference in New Issue