From 28ba40b4e66f6f1ea2a9cc19d3e80614d74e6770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 8 Sep 2025 20:11:53 +0200 Subject: [PATCH 1/4] add test --- test/testsymboldatabase.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 9aaa7359abf..86225ea8e79 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -622,6 +622,8 @@ class TestSymbolDatabase : public TestFixture { TEST_CASE(dumpFriend); // Check if isFriend added to dump file TEST_CASE(smartPointerLookupCtor); // #13719); + + TEST_CASE(userDefinedLiteral); } void array() { @@ -11317,6 +11319,15 @@ class TestSymbolDatabase : public TestFixture { ASSERT(db); } + + void userDefinedLiteral() { + GET_SYMBOL_DB("_ 1p;"); + const Token *x = Token::findsimplematch(tokenizer.tokens(), "1p"); + ASSERT(x); + ASSERT(!x->varId()); + ASSERT(!x->variable()); + } + }; REGISTER_TEST(TestSymbolDatabase) From 6570cfc5b8706acc46adad54ccc6ef3e5a3f6e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 8 Sep 2025 21:03:25 +0200 Subject: [PATCH 2/4] update test --- test/testtoken.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testtoken.cpp b/test/testtoken.cpp index 04a32a81dac..4537defbe3d 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -1303,7 +1303,7 @@ class TestToken : public TestFixture { assert_tok("0.0", Token::Type::eNumber); assert_tok("0x0.3p10", Token::Type::eNumber); assert_tok("0z", Token::Type::eNumber); // TODO: not a valid number - assert_tok("0_km", Token::Type::eName); // user literal + assert_tok("0_km", Token::Type::eLiteral); // user literal assert_tok("=", Token::Type::eAssignmentOp); assert_tok("<<=", Token::Type::eAssignmentOp); assert_tok(">>=", Token::Type::eAssignmentOp); From 3e150c8ec793e00f72bbb1c189ab0dd3b2d345b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 8 Sep 2025 20:03:42 +0200 Subject: [PATCH 3/4] fix #14077 * allow member access on user defined literals * allow (tokens that look like) user defined literals in msvc asm blocks --- lib/token.cpp | 2 +- lib/tokenize.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/token.cpp b/lib/token.cpp index c4967ceb1d5..f975f72b6ec 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -154,7 +154,7 @@ void Token::update_property_info() if ((MathLib::isInt(mStr) || MathLib::isFloat(mStr)) && mStr.find('_') == std::string::npos) tokType(eNumber); else - tokType(eName); // assume it is a user defined literal + tokType(eLiteral); // assume it is a user defined literal } else if (mStr == "=" || mStr == "<<=" || mStr == ">>=" || (mStr.size() == 2U && mStr[1] == '=' && std::strchr("+-*/%&^|", mStr[0]))) tokType(eAssignmentOp); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 166662622a3..ac39c20f570 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8869,6 +8869,7 @@ void Tokenizer::findGarbageCode() const !Token::simpleMatch(tok->previous(), ".") && !Token::simpleMatch(tok->next(), ".") && !Token::Match(tok->previous(), "{|, . %name% =|.|[|{") && + !(tok->previous() && tok->previous()->isLiteral()) && !Token::Match(tok->previous(), ", . %name%")) { if (!Token::Match(tok->previous(), "%name%|)|]|>|}")) syntaxError(tok, tok->strAt(-1) + " " + tok->str() + " " + tok->strAt(1)); @@ -9847,7 +9848,7 @@ void Tokenizer::simplifyAsm() Token *endasm = tok->next(); const Token *firstSemiColon = nullptr; int comment = 0; - while (Token::Match(endasm, "%num%|%name%|,|:|;") || (endasm && endasm->linenr() == comment)) { + while (Token::Match(endasm, "%num%|%name%|,|:|;") || (endasm && (endasm->isLiteral() || endasm->linenr() == comment))) { if (Token::Match(endasm, "_asm|__asm|__endasm")) break; if (endasm->str() == ";") { From b0f2535122d58e56634d78869ce48d242082d5c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 8 Sep 2025 22:19:10 +0200 Subject: [PATCH 4/4] add crash file --- .../fuzz-crash/crash-039028704ca27187fc3228e9fa01ca30a8434e7a | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/cli/fuzz-crash/crash-039028704ca27187fc3228e9fa01ca30a8434e7a diff --git a/test/cli/fuzz-crash/crash-039028704ca27187fc3228e9fa01ca30a8434e7a b/test/cli/fuzz-crash/crash-039028704ca27187fc3228e9fa01ca30a8434e7a new file mode 100644 index 00000000000..7dab9f7d28a --- /dev/null +++ b/test/cli/fuzz-crash/crash-039028704ca27187fc3228e9fa01ca30a8434e7a @@ -0,0 +1 @@ +_ 1p; \ No newline at end of file