From 87ce792a3ff0f7a9d54893531179e92f50db6b17 Mon Sep 17 00:00:00 2001 From: swasti16 Date: Mon, 12 Aug 2024 16:03:58 +0530 Subject: [PATCH] Fix 13009: Add valueType-originalTypeName for isCast Tok --- lib/tokenize.cpp | 5 +++-- test/testsymboldatabase.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d9f1131f5197..e4bd55c705d8 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -781,7 +781,8 @@ namespace { const bool isFunctionPointer = Token::Match(mNameToken, "%name% )"); if (isFunctionPointer && isCast(tok->previous())) { tok->insertToken("*"); - insertTokens(tok, std::pair(mRangeType.first, mNameToken->linkAt(1))); + Token* const tok_1 = insertTokens(tok, std::pair(mRangeType.first, mNameToken->linkAt(1))); + tok_1->originalName(tok->str()); tok->deleteThis(); return; } @@ -1041,7 +1042,7 @@ namespace { private: static bool isCast(const Token* tok) { - if (Token::Match(tok, "( %name% ) (|%name%")) + if (Token::Match(tok, "( %name% ) (|%name%|%number%")) return !tok->tokAt(2)->isKeyword(); if (Token::Match(tok, "< %name% > (") && tok->previous() && endsWith(tok->strAt(-1), "_cast", 5)) return true; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 7a4af16df6e5..82d60a5b96ae 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -596,6 +596,7 @@ class TestSymbolDatabase : public TestFixture { TEST_CASE(incomplete_type); // #9255 (infinite recursion) TEST_CASE(exprIds); + TEST_CASE(testValuetypeOriginalName); } void array() { @@ -10821,6 +10822,35 @@ class TestSymbolDatabase : public TestFixture { ASSERT_EQUALS(true, testExprIdNotEqual(code, "(", 3U, "(", 4U)); } } + + void testValuetypeOriginalName() { + { + GET_SYMBOL_DB("typedef void ( *fp16 )( int16_t n );\n" + "typedef void ( *fp32 )( int32_t n );\n" + "extern void f1 ( int16_t n );\n" + "void R_11_1 ( void ) {\n" + " fp16 fp1 = NULL;\n" + " fp32 fp2 = ( fp32) fp1;\n" + "}\n"); + const Token* tok = Token::findsimplematch(tokenizer.tokens(), "( void * )"); + ASSERT_EQUALS(tok->isCast(), true); + ASSERT(tok->valueType()); + ASSERT(tok->valueType()->originalTypeName == "fp32"); + ASSERT(tok->valueType()->pointer == 1); + ASSERT(tok->valueType()->constness == 0); + } + + { + GET_SYMBOL_DB("typedef void ( *fp16 )( int16_t n );\n" + "fp16 fp3 = ( fp16 ) 0x8000;"); + const Token* tok = Token::findsimplematch(tokenizer.tokens(), "( void * )"); + ASSERT_EQUALS(tok->isCast(), true); + ASSERT(tok->valueType()); + ASSERT(tok->valueType()->originalTypeName == "fp16"); + ASSERT(tok->valueType()->pointer == 1); + ASSERT(tok->valueType()->constness == 0); + } + } }; REGISTER_TEST(TestSymbolDatabase)