ExprEngine: Handle char literals

This commit is contained in:
Daniel Marjamäki 2019-09-24 20:10:51 +02:00
parent 3b3ff2bb62
commit 0471e74489
2 changed files with 9 additions and 4 deletions

View File

@ -747,7 +747,7 @@ static ExprEngine::ValuePtr executeExpression(const Token *tok, Data &data)
if (tok->isName() && tok->hasKnownIntValue()) if (tok->isName() && tok->hasKnownIntValue())
return executeKnownMacro(tok, data); return executeKnownMacro(tok, data);
if (tok->isNumber()) if (tok->isNumber() || tok->tokType() == Token::Type::eChar)
return executeNumber(tok); return executeNumber(tok);
if (tok->tokType() == Token::Type::eString) if (tok->tokType() == Token::Type::eString)

View File

@ -61,7 +61,8 @@ private:
TEST_CASE(localArray1); TEST_CASE(localArray1);
TEST_CASE(localArray2); TEST_CASE(localArray2);
TEST_CASE(localArray3); TEST_CASE(localArrayInit1);
TEST_CASE(localArrayInit2);
TEST_CASE(localArrayUninit); TEST_CASE(localArrayUninit);
TEST_CASE(pointerAlias1); TEST_CASE(pointerAlias1);
@ -193,11 +194,15 @@ private:
} }
void localArray2() { void localArray2() {
ASSERT_EQUALS("0:255", getRange("int f() { unsigned char arr[10] = \"\"; dostuff(arr); return arr[4]; }", "arr[4]"));
}
void localArrayInit1() {
ASSERT_EQUALS("0", getRange("inf f() { char arr[10] = \"\"; return arr[4]; }", "arr[4]")); ASSERT_EQUALS("0", getRange("inf f() { char arr[10] = \"\"; return arr[4]; }", "arr[4]"));
} }
void localArray3() { void localArrayInit2() {
ASSERT_EQUALS("0:255", getRange("int f() { unsigned char arr[10] = \"\"; dostuff(arr); return arr[4]; }", "arr[4]")); ASSERT_EQUALS("66", getRange("void f() { char str[] = \"hello\"; str[0] = \'B\'; }", "str[0]=\'B\'"));
} }
void localArrayUninit() { void localArrayUninit() {