diff --git a/lib/exprengine.cpp b/lib/exprengine.cpp index bd4ce6666..edc190214 100644 --- a/lib/exprengine.cpp +++ b/lib/exprengine.cpp @@ -1170,6 +1170,18 @@ static ExprEngine::ValuePtr executeAssign(const Token *tok, Data &data) static ExprEngine::ValuePtr executeFunctionCall(const Token *tok, Data &data) { + if (Token::simpleMatch(tok->previous(), "sizeof (")) { + ExprEngine::ValuePtr retVal; + if (tok->hasKnownIntValue()) { + const MathLib::bigint value = tok->getKnownIntValue(); + retVal = std::make_shared(std::to_string(value), value, value); + } else { + retVal = std::make_shared(data.getNewSymbolName(), 1, 0x7fffffff); + } + call(data.callbacks, tok, retVal, &data); + return retVal; + } + std::vector argValues; for (const Token *argtok : getArguments(tok)) { auto val = executeExpression(argtok, data); diff --git a/test/testexprengine.cpp b/test/testexprengine.cpp index 3487ebfbe..1688814e8 100644 --- a/test/testexprengine.cpp +++ b/test/testexprengine.cpp @@ -72,6 +72,7 @@ private: TEST_CASE(functionCall1); TEST_CASE(functionCall2); TEST_CASE(functionCall3); + TEST_CASE(functionCall4); TEST_CASE(int1); @@ -435,6 +436,10 @@ private: ASSERT_EQUALS("-2147483648:2147483647", getRange("int fgets(int, const char *, void *); void f() { int x = -1; fgets(stdin, \"%d\", &x); x=x; }", "x=x")); } + void functionCall4() { + ASSERT_EQUALS("1:2147483647", getRange("void f() { sizeof(data); }", "sizeof(data)")); + } + void int1() { ASSERT_EQUALS("(declare-fun $1 () Int)\n"