Bug hunting: Handle not better
This commit is contained in:
parent
0ccc5c695b
commit
b18dc0fdbb
|
@ -2267,6 +2267,17 @@ static ExprEngine::ValuePtr executeDeref(const Token *tok, Data &data)
|
|||
return ExprEngine::ValuePtr();
|
||||
}
|
||||
|
||||
static ExprEngine::ValuePtr executeNot(const Token *tok, Data &data)
|
||||
{
|
||||
ExprEngine::ValuePtr v = executeExpression(tok->astOperand1(), data);
|
||||
if (!v)
|
||||
return v;
|
||||
ExprEngine::ValuePtr zero = std::make_shared<ExprEngine::IntRange>("0", 0, 0);
|
||||
auto result = simplifyValue(std::make_shared<ExprEngine::BinOpResult>("==", v, zero));
|
||||
call(data.callbacks, tok, result, &data);
|
||||
return result;
|
||||
}
|
||||
|
||||
static ExprEngine::ValuePtr executeVariable(const Token *tok, Data &data)
|
||||
{
|
||||
auto val = data.getValue(tok->varId(), tok->valueType(), tok);
|
||||
|
@ -2345,6 +2356,9 @@ static ExprEngine::ValuePtr executeExpression1(const Token *tok, Data &data)
|
|||
if (tok->isUnaryOp("*"))
|
||||
return executeDeref(tok, data);
|
||||
|
||||
if (tok->isUnaryOp("!"))
|
||||
return executeNot(tok, data);
|
||||
|
||||
if (tok->varId())
|
||||
return executeVariable(tok, data);
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ private:
|
|||
TEST_CASE(expr9);
|
||||
TEST_CASE(exprAssign1);
|
||||
TEST_CASE(exprAssign2); // Truncation
|
||||
TEST_CASE(exprNot);
|
||||
|
||||
TEST_CASE(getValueConst1);
|
||||
|
||||
|
@ -352,6 +353,9 @@ private:
|
|||
ASSERT_EQUALS("2", getRange("void f(unsigned char x) { x = 258; int a = x }", "a=x"));
|
||||
}
|
||||
|
||||
void exprNot() {
|
||||
ASSERT_EQUALS("($1)==(0)", getRange("void f(unsigned char a) { return !a; }", "!a"));
|
||||
}
|
||||
|
||||
void getValueConst1() { // Data::getValue
|
||||
ASSERT_EQUALS("512", getRange("const int x=512; void func() { x=x }", "x=x"));
|
||||
|
|
Loading…
Reference in New Issue