Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8010,12 +8010,12 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
if (mSettings.platform.type != Platform::Type::Unspecified) {
if (type <= ValueType::Type::INT && mSettings.platform.isIntValue(unsignedSuffix ? (value >> 1) : value))
type = ValueType::Type::INT;
else if (type <= ValueType::Type::INT && !MathLib::isDec(tokStr) && mSettings.platform.isIntValue(value >> 2)) {
else if (type <= ValueType::Type::INT && !MathLib::isDec(tokStr) && mSettings.platform.isIntValue(value >> 1)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

This is not caused by the PR, but it is the same condition: MathLib::isDec() returns true for octal literals. Octal literals follow the same type rules as hex (C11 6.4.4.1), but they never reach this branch. For example, with --platform=unix32 the literal 037777777777 (= 0xFFFFFFFF) gets the type signed long long instead of unsigned int, in both base and PR. You could fix it here, or open a follow-up ticket.

type = ValueType::Type::INT;
sign = ValueType::Sign::UNSIGNED;
} else if (type <= ValueType::Type::LONG && mSettings.platform.isLongValue(unsignedSuffix ? (value >> 1) : value))
type = ValueType::Type::LONG;
else if (type <= ValueType::Type::LONG && !MathLib::isDec(tokStr) && mSettings.platform.isLongValue(value >> 2)) {
else if (type <= ValueType::Type::LONG && !MathLib::isDec(tokStr) && mSettings.platform.isLongValue(value >> 1)) {
type = ValueType::Type::LONG;
sign = ValueType::Sign::UNSIGNED;
} else if (mSettings.platform.isLongLongValue(unsignedSuffix ? (value >> 1) : value))
Expand Down
7 changes: 7 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9922,6 +9922,13 @@ class TestSymbolDatabase : public TestFixture {
ASSERT_EQUALS("signed long long", typeOf("0xFFFFFFFFFFFF;\n", "0xFFFFFFFFFFFF", false, &s));
ASSERT_EQUALS("unsigned long long", typeOf("0xFFFFFFFFFFFFU;\n", "0xFFFFFFFFFFFFU", false, &s));
ASSERT_EQUALS("unsigned long long", typeOf("0xFFFFFFFF00000000;\n", "0xFFFFFFFF00000000", false, &s));
ASSERT_EQUALS("signed long", typeOf("0x10000;\n", "0x10000", false, &s));
ASSERT_EQUALS("signed long", typeOf("0x1FFFF;\n", "0x1FFFF", false, &s));
ASSERT_EQUALS("signed long long", typeOf("0x100000000;\n", "0x100000000", false, &s));
ASSERT_EQUALS("signed long long", typeOf("0x100000000L;\n", "0x100000000L", false, &s));
ASSERT_EQUALS("unsigned long long", typeOf("0x100000000U;\n", "0x100000000U", false, &s));
ASSERT_EQUALS("unsigned long long", typeOf("0x100000000UL;\n", "0x100000000UL", false, &s));
ASSERT_EQUALS("signed long long", typeOf("0x1FFFFFFFF;\n", "0x1FFFFFFFF", false, &s));

ASSERT_EQUALS("signed long", typeOf("2147483648;\n", "2147483648", false, &sSameSize));
ASSERT_EQUALS("unsigned long", typeOf("0xc000000000000000;\n", "0xc000000000000000", false, &sSameSize));
Expand Down
Loading