https://github.com/da-viper created https://github.com/llvm/llvm-project/pull/169652
The simplified parser incorrectly assumes if there is a context, there is no return type. >From a0f2bcd3b3361572d68e11b6ee3b4284bc97679b Mon Sep 17 00:00:00 2001 From: Ebuka Ezike <[email protected]> Date: Wed, 26 Nov 2025 13:52:51 +0000 Subject: [PATCH] [lldb] fix CxxMethodName Parser. The simplified parser incorrectly assumes if there is a context, there is no return type. --- .../Language/CPlusPlus/CPlusPlusLanguage.cpp | 24 +++++++++++-------- .../CPlusPlus/CPlusPlusLanguageTest.cpp | 5 ++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp index 4b66ff814935a..d347b57996c65 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp @@ -481,18 +481,22 @@ bool CPlusPlusLanguage::CxxMethodName::TrySimplifiedParse() { m_basename = full.substr(basename_begin, basename_end - basename_begin); } - if (IsTrivialBasename(m_basename)) { + // if the context has a white space it may have a return type. + // e.g. `int foo::bar::func()` or `Type<int > foo::bar::func(int)` + const bool no_whitespace = + m_context.find_first_of(" \t\n\v\f\r") == llvm::StringRef::npos; + + if (no_whitespace && IsTrivialBasename(m_basename)) { return true; - } else { - // The C++ basename doesn't match our regular expressions so this can't - // be a valid C++ method, clear everything out and indicate an error - m_context = llvm::StringRef(); - m_basename = llvm::StringRef(); - m_arguments = llvm::StringRef(); - m_qualifiers = llvm::StringRef(); - m_return_type = llvm::StringRef(); - return false; } + // The C++ basename doesn't match our regular expressions so this can't + // be a valid C++ method, clear everything out and indicate an error + m_context = llvm::StringRef(); + m_basename = llvm::StringRef(); + m_arguments = llvm::StringRef(); + m_qualifiers = llvm::StringRef(); + m_return_type = llvm::StringRef(); + return false; } return false; } diff --git a/lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp b/lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp index 23f2f4218601a..f0c4b0a83c890 100644 --- a/lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp +++ b/lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp @@ -30,6 +30,9 @@ TEST(CPlusPlusLanguage, MethodNameParsing) { {"foo::~bar(baz)", "", "foo", "~bar", "(baz)", "", "foo::~bar"}, {"a::b::c::d(e,f)", "", "a::b::c", "d", "(e,f)", "", "a::b::c::d"}, {"void f(int)", "void", "", "f", "(int)", "", "f"}, + {"int main()", "int", "", "main", "()", "", "main"}, + {"int foo::bar::func01(int a, double b)", "int", "foo::bar", "func01", + "(int a, double b)", "", "foo::bar::func01"}, // Operators {"std::basic_ostream<char, std::char_traits<char> >& " @@ -101,6 +104,8 @@ TEST(CPlusPlusLanguage, MethodNameParsing) { "std::forward<decltype(nullptr)>"}, // Templates + {"vector<int > foo::bar::func(int)", "vector<int >", "foo::bar", "func", + "(int)", "", "foo::bar::func"}, {"void llvm::PM<llvm::Module, llvm::AM<llvm::Module>>::" "addPass<llvm::VP>(llvm::VP)", "void", "llvm::PM<llvm::Module, llvm::AM<llvm::Module>>", _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
