ExprEngine: Guess function call return value

This commit is contained in:
Daniel Marjamäki 2019-09-22 16:40:48 +02:00
parent 5c07cfd2e8
commit 6e17853ea9
2 changed files with 13 additions and 1 deletions

View File

@ -606,7 +606,7 @@ static ExprEngine::ValuePtr executeExpression(const Token *tok, Data &data)
if (tok->astOperand1() && tok->astOperand2() && tok->str() == "[")
return executeArrayIndex(tok, data);
if (tok->str() == "(" && tok->astOperand2())
if (tok->str() == "(" && !tok->isCast())
return executeFunctionCall(tok, data);
if (tok->str() == ".")

View File

@ -41,6 +41,7 @@ private:
TEST_CASE(exprAssign1);
TEST_CASE(functionCall1);
TEST_CASE(functionCall2);
TEST_CASE(if1);
TEST_CASE(if2);
@ -127,6 +128,17 @@ private:
ASSERT_EQUALS("-2147483648:2147483647", getRange("int atoi(const char *p); void f() { int x = atoi(a); x = x; }", "x=x"));
}
void functionCall2() {
const char code[] = "namespace NS {\n"
" short getValue();\n"
"}"
"void f() {\n"
" short value = NS::getValue();\n"
" value = value;\n"
"}";
ASSERT_EQUALS("-32768:32767", getRange(code, "value=value"));
}
void if1() {
ASSERT_EQUALS("7:32768", getRange("inf f(short x) { if (x > 5) a = x + 1; }", "x+1"));
}