Skip to content

Commit 8b7a07a

Browse files
authored
[lldb] Fix abi_tag parsing for operator<< and operator-named tags (#170224)
The parser now correctly handles: - abi_tags attached to operator<<: `operator<<[abi:SOMETAG]` - abi_tags with "operator" as the tag name: `func[abi:operator]`
1 parent 4b0a975 commit 8b7a07a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ bool CPlusPlusNameParser::ConsumeAbiTag() {
315315

316316
// Consume the actual tag string (and allow some special characters)
317317
while (ConsumeToken(tok::raw_identifier, tok::comma, tok::period,
318-
tok::numeric_constant))
318+
tok::numeric_constant, tok::kw_operator))
319319
;
320320

321321
if (!ConsumeToken(tok::r_square))
@@ -420,10 +420,11 @@ bool CPlusPlusNameParser::ConsumeOperator() {
420420
// Make sure we have more tokens before attempting to look ahead one more.
421421
if (m_next_token_index + 1 < m_tokens.size()) {
422422
// Look ahead two tokens.
423-
clang::Token n_token = m_tokens[m_next_token_index + 1];
424-
// If we find ( or < then this is indeed operator<< no need for fix.
425-
if (n_token.getKind() != tok::l_paren && n_token.getKind() != tok::less) {
426-
clang::Token tmp_tok;
423+
const clang::Token n_token = m_tokens[m_next_token_index + 1];
424+
// If we find `(`, `<` or `[` then this is indeed operator<< no need for
425+
// fix.
426+
if (!n_token.isOneOf(tok::l_paren, tok::less, tok::l_square)) {
427+
clang::Token tmp_tok{};
427428
tmp_tok.startToken();
428429
tmp_tok.setLength(1);
429430
tmp_tok.setLocation(token.getLocation().getLocWithOffset(1));

lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ TEST(CPlusPlusLanguage, MethodNameParsing) {
6969
"const",
7070
"std::__1::ranges::__begin::__fn::operator()[abi:v160000]<char const, "
7171
"18ul>"},
72+
{"bool Ball[abi:BALL]<int>::operator<<[abi:operator]<int>(int)", "bool",
73+
"Ball[abi:BALL]<int>", "operator<<[abi:operator]<int>", "(int)", "",
74+
"Ball[abi:BALL]<int>::operator<<[abi:operator]<int>"},
75+
{"bool Ball[abi:BALL]<int>::operator>>[abi:operator]<int>(int)", "bool",
76+
"Ball[abi:BALL]<int>", "operator>>[abi:operator]<int>", "(int)", "",
77+
"Ball[abi:BALL]<int>::operator>>[abi:operator]<int>"},
7278
// Internal classes
7379
{"operator<<(Cls, Cls)::Subclass::function()", "",
7480
"operator<<(Cls, Cls)::Subclass", "function", "()", "",

0 commit comments

Comments
 (0)