From 5d1e96ce8f9cd3565ff584f00052afc960d55881 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 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index d49b3fb5d97..9e7eed4ebdd 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -624,6 +624,8 @@ class TestSymbolDatabase : public TestFixture { TEST_CASE(smartPointerLookupCtor); // #13719); TEST_CASE(stdintFunction); + + TEST_CASE(userDefinedLiteral); } void array() { @@ -11327,6 +11329,14 @@ class TestSymbolDatabase : public TestFixture { ASSERT_EQUALS(tok->next()->valueType()->sign, ValueType::Sign::UNSIGNED); ASSERT_EQUALS(tok->next()->valueType()->type, ValueType::Type::INT); } + + 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 05cdcf17254ce7ead9f35d1879429c8c23ea4d95 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 27b164c03a6c1ad0ced7359d1e14d8203108d0b4 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 35b5a9141b8..f64772b5e7a 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -153,7 +153,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 9f3e25c7d74..51506aae8f2 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)); @@ -9877,7 +9878,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 70cd5a997337087df888461ee715ea55a01ee2e7 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