ExprEngine: Passing variable address to function

This commit is contained in:
Daniel Marjamäki 2019-09-24 19:53:33 +02:00
parent 524c9f5936
commit 1769af4a6c
2 changed files with 12 additions and 0 deletions

View File

@ -603,12 +603,19 @@ static ExprEngine::ValuePtr executeFunctionCall(const Token *tok, Data &data)
{
for (const Token *argtok : getArguments(tok)) {
auto val = executeExpression(argtok, data);
if (!argtok->valueType() || (argtok->valueType()->constness & 1) == 1)
continue;
if (auto arrayValue = std::dynamic_pointer_cast<ExprEngine::ArrayValue>(val)) {
ValueType vt(*argtok->valueType());
vt.pointer = 0;
auto anyVal = getValueRangeFromValueType(data.getNewSymbolName(), &vt, *data.settings);
for (int i = 0; i < arrayValue->data.size(); ++i)
arrayValue->data[i] = anyVal;
} else if (auto addressOf = std::dynamic_pointer_cast<ExprEngine::AddressOfValue>(val)) {
ValueType vt(*argtok->valueType());
vt.pointer = 0;
if (vt.isIntegral() && argtok->valueType()->pointer == 1)
data.memory[addressOf->varId] = getValueRangeFromValueType(data.getNewSymbolName(), &vt, *data.settings);
}
}
auto val = getValueRangeFromValueType(data.getNewSymbolName(), tok->valueType(), *data.settings);

View File

@ -49,6 +49,7 @@ private:
TEST_CASE(functionCall1);
TEST_CASE(functionCall2);
TEST_CASE(functionCall3);
TEST_CASE(if1);
TEST_CASE(if2);
@ -159,6 +160,10 @@ private:
ASSERT_EQUALS("-32768:32767", getRange(code, "value=value"));
}
void functionCall3() {
ASSERT_EQUALS("-2147483648:2147483647", getRange("void f() { int x = -1; fgets(stdin, \"%d\", &x); x=x; }", "x=x"));
}
void if1() {
ASSERT_EQUALS("7:32768", getRange("inf f(short x) { if (x > 5) a = x + 1; }", "x+1"));
}