From e6a160979cf1fed41eeca7c8e49f97b33dd4ff18 Mon Sep 17 00:00:00 2001 From: Oleksandr Labetskyi Date: Fri, 12 Dec 2025 11:59:22 +0000 Subject: [PATCH 1/2] Fix #14325 add originalTypeName to library ValueType-s --- lib/symboldatabase.cpp | 4 ++++ test/testsymboldatabase.cpp | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index d4107884642..f591e54dd0e 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -8237,11 +8237,13 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings &sett else type = ValueType::Type::UNKNOWN_INT; sign = (podtype->sign == 'u') ? ValueType::UNSIGNED : ValueType::SIGNED; + originalTypeName = typestr; return true; } if (podtype && podtype->stdtype == Library::PodType::Type::NO) { type = ValueType::Type::POD; sign = ValueType::UNKNOWN_SIGN; + originalTypeName = typestr; return true; } @@ -8267,6 +8269,7 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings &sett pointer = 2; if (platformType->mConstPtr) constness = 1; + originalTypeName = typestr; return true; } if (!podtype && (typestr == "size_t" || typestr == "std::size_t")) { @@ -8280,6 +8283,7 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings &sett type = ValueType::Type::INT; else type = ValueType::Type::UNKNOWN_INT; + originalTypeName = typestr; return true; } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index e6a1527f2f2..eced3917eb7 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -11354,6 +11354,15 @@ class TestSymbolDatabase : public TestFixture { ASSERT(tok->valueType()->pointer == 1); ASSERT(tok->valueType()->constness == 0); } + + { + GET_SYMBOL_DB("int8_t value = 0;"); + const Token* tok = Token::findsimplematch(tokenizer.tokens(), "value"); + ASSERT(tok); + ASSERT(tok->valueType()); + ASSERT(tok->valueType()->originalTypeName == "int8_t"); + ASSERT(tok->valueType()->type == ValueType::Type::CHAR); + } } void dumpFriend() { From 06df4cf3c3abbc8465639f1ff1d129ed9227b4c8 Mon Sep 17 00:00:00 2001 From: Oleksandr Labetskyi Date: Sun, 14 Dec 2025 14:17:35 +0000 Subject: [PATCH 2/2] Nits --- lib/checkio.cpp | 1 + lib/symboldatabase.cpp | 10 ++++++---- test/testio.cpp | 14 ++++++++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 3662adfda8f..e7cb4aeb362 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -1938,6 +1938,7 @@ void CheckIO::invalidPrintfArgTypeError_float(const Token* tok, nonneg int numFo Severity CheckIO::getSeverity(const CheckIO::ArgumentInfo *argInfo) { + //TODO: It causes issues if we use fixed range types like int32_t etc so we should rewrite this to handle those types properly return (argInfo && argInfo->typeToken && !argInfo->typeToken->originalName().empty()) ? Severity::portability : Severity::warning; } diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index f591e54dd0e..d898d1effb0 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -8237,13 +8237,15 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings &sett else type = ValueType::Type::UNKNOWN_INT; sign = (podtype->sign == 'u') ? ValueType::UNSIGNED : ValueType::SIGNED; - originalTypeName = typestr; + if (originalTypeName.empty()) + originalTypeName = typestr; return true; } if (podtype && podtype->stdtype == Library::PodType::Type::NO) { type = ValueType::Type::POD; sign = ValueType::UNKNOWN_SIGN; - originalTypeName = typestr; + if (originalTypeName.empty()) + originalTypeName = typestr; return true; } @@ -8269,7 +8271,8 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings &sett pointer = 2; if (platformType->mConstPtr) constness = 1; - originalTypeName = typestr; + if (originalTypeName.empty()) + originalTypeName = typestr; return true; } if (!podtype && (typestr == "size_t" || typestr == "std::size_t")) { @@ -8283,7 +8286,6 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings &sett type = ValueType::Type::INT; else type = ValueType::Type::UNKNOWN_INT; - originalTypeName = typestr; return true; } diff --git a/test/testio.cpp b/test/testio.cpp index b402f5c0aa1..fc554c99f60 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -2915,14 +2915,16 @@ class TestIO : public TestFixture { "[test.cpp:3]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'.\n" "[test.cpp:3]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'.\n", errout_str()); + // We should revisit the logic behind portability checks here. check("struct Fred { int32_t i; } f;\n" "struct Fred & bar() { };\n" - "void foo() { printf(\"%d %ld %u %lu %f %Lf\", bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); }"); - ASSERT_EQUALS("[test.cpp:3]: (warning) %ld in format string (no. 2) requires 'long' but the argument type is 'signed int'.\n" - "[test.cpp:3]: (warning) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.\n" - "[test.cpp:3]: (warning) %lu in format string (no. 4) requires 'unsigned long' but the argument type is 'signed int'.\n" - "[test.cpp:3]: (warning) %f in format string (no. 5) requires 'double' but the argument type is 'signed int'.\n" - "[test.cpp:3]: (warning) %Lf in format string (no. 6) requires 'long double' but the argument type is 'signed int'.\n", + "void foo() { printf(\"%d %ld %u %lu %f %Lf\", bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); }", + dinit(CheckOptions, $.portability = true)); + ASSERT_EQUALS("[test.cpp:3]: (portability) %ld in format string (no. 2) requires 'long' but the argument type is 'int32_t {aka signed int}'.\n" + "[test.cpp:3]: (portability) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'int32_t {aka signed int}'.\n" + "[test.cpp:3]: (portability) %lu in format string (no. 4) requires 'unsigned long' but the argument type is 'int32_t {aka signed int}'.\n" + "[test.cpp:3]: (portability) %f in format string (no. 5) requires 'double' but the argument type is 'int32_t {aka signed int}'.\n" + "[test.cpp:3]: (portability) %Lf in format string (no. 6) requires 'long double' but the argument type is 'int32_t {aka signed int}'.\n", errout_str()); // #4984