From 60f6e87c6180fccb2b3b274e560157b45136994a Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 31 Mar 2025 16:05:09 +0200 Subject: [PATCH 1/2] fixed #13745 - platform types incorrectly simplified for 64-bit --- lib/tokenlist.cpp | 6 +++--- test/testtokenize.cpp | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 399d0e5c4d7..79402e5e695 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -2032,10 +2032,10 @@ void TokenList::simplifyPlatformTypes() /** @todo This assumes a flat address space. Not true for segmented address space (FAR *). */ - if (mSettings->platform.sizeof_size_t == mSettings->platform.sizeof_long) - type = isLong; - else if (mSettings->platform.sizeof_size_t == mSettings->platform.sizeof_long_long) + if (mSettings->platform.sizeof_size_t == mSettings->platform.sizeof_long_long) type = isLongLong; + else if (mSettings->platform.sizeof_size_t == mSettings->platform.sizeof_long) + type = isLong; else if (mSettings->platform.sizeof_size_t == mSettings->platform.sizeof_int) type = isInt; else diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 6af2b140989..39fbb67efeb 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -475,6 +475,8 @@ class TestTokenizer : public TestFixture { TEST_CASE(atomicCast); // #12605 TEST_CASE(constFunctionPtrTypedef); // #12135 + + TEST_CASE(simplifyPlatformTypes); } #define tokenizeAndStringify(...) tokenizeAndStringify_(__FILE__, __LINE__, __VA_ARGS__) @@ -8495,6 +8497,24 @@ class TestTokenizer : public TestFixture { ASSERT_NO_THROW(tokenizeAndStringify(code)); ASSERT_EQUALS("void ( * const f ) ( ) ;", tokenizeAndStringify("typedef void (*fp_t)(); fp_t const f;")); } + + void simplifyPlatformTypes() { + { + const char code[] = "size_t f();"; + ASSERT_EQUALS("unsigned long f ( ) ;", tokenizeAndStringify(code, true, Platform::Type::Unix32)); + ASSERT_EQUALS("unsigned long long f ( ) ;", tokenizeAndStringify(code, true, Platform::Type::Unix64)); + } + { + const char code[] = "ssize_t f();"; + ASSERT_EQUALS("long f ( ) ;", tokenizeAndStringify(code, true, Platform::Type::Unix32)); + ASSERT_EQUALS("long long f ( ) ;", tokenizeAndStringify(code, true, Platform::Type::Unix64)); + } + { + const char code[] = "std::ptrdiff_t f();"; + ASSERT_EQUALS("long f ( ) ;", tokenizeAndStringify(code, true, Platform::Type::Unix32)); + ASSERT_EQUALS("long long f ( ) ;", tokenizeAndStringify(code, true, Platform::Type::Unix64)); + } + } }; REGISTER_TEST(TestTokenizer) From ba0e3a85ddcc158f43e71d15977c7a420e44260a Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 31 Mar 2025 16:11:26 +0200 Subject: [PATCH 2/2] testrunner: adjusted some expected results [skip ci] --- test/testtype.cpp | 2 +- test/testvarid.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/testtype.cpp b/test/testtype.cpp index 22323e5206d..d74c819f133 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -472,7 +472,7 @@ class TestType : public TestFixture { check("size_t f(int x, int y) {\n" " return x * y;\n" "}\n", settings); - ASSERT_EQUALS("[test.cpp:2]: (style) int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2]: (style) int result is returned as long value. If the return value is long long to avoid loss of information, then you have loss of information.\n", errout_str()); } // This function ensure that test works with different compilers. Floats can diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 89223842b49..139203fa7f8 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -2787,7 +2787,7 @@ class TestVarID : public TestFixture { void varid_using() { // #3648 const char code[] = "using std::size_t;"; - const char expected[] = "1: using unsigned long ;\n"; + const char expected[] = "1: using unsigned long long ;\n"; ASSERT_EQUALS(expected, tokenize(code)); }