https://github.com/da-viper updated 
https://github.com/llvm/llvm-project/pull/169652

>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 1/3] [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>>",

>From 8634de5c8647c79f196fbf3b5c7745957bf5d7ae Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <[email protected]>
Date: Wed, 26 Nov 2025 19:56:13 +0000
Subject: [PATCH 2/3] [lldb] add review changes

---
 .../Language/CPlusPlus/CPlusPlusLanguage.cpp  | 20 +++++++++++++------
 .../CPlusPlus/CPlusPlusLanguageTest.cpp       |  3 ++-
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index d347b57996c65..ab9affe438c86 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -208,6 +208,19 @@ static bool IsTrivialBasename(const llvm::StringRef 
&basename) {
   return idx == basename.size();
 }
 
+/// A context is trivial if an only if it matches this pattern.
+/// "^\s*([A-Za-z_:]*)\s*$".
+static bool IsTrivialContext(llvm::StringRef context) {
+  // remove trailing or leading whitespace.
+  context = context.trim();
+
+  const auto iter = context.find_if_not([](char current) {
+    return std::isalnum(static_cast<unsigned char>(current)) ||
+           current == '_' || current == ':';
+  });
+  return iter == llvm::StringRef::npos;
+}
+
 /// Writes out the function name in 'full_name' to 'out_stream'
 /// but replaces each argument type with the variable name
 /// and the corresponding pretty-printed value
@@ -481,12 +494,7 @@ bool 
CPlusPlusLanguage::CxxMethodName::TrySimplifiedParse() {
       m_basename = full.substr(basename_begin, basename_end - basename_begin);
     }
 
-    // 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)) {
+    if (IsTrivialBasename(m_basename) && IsTrivialContext(m_context)) {
       return true;
     }
     // The C++ basename doesn't match our regular expressions so this can't
diff --git a/lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp 
b/lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp
index f0c4b0a83c890..c05418168e62e 100644
--- a/lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp
+++ b/lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp
@@ -30,7 +30,8 @@ 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"},
+      {"std::vector<int>foo::bar()", "std::vector<int>", "foo", "bar", "()", 
"",
+       "foo::bar"},
       {"int foo::bar::func01(int a, double b)", "int", "foo::bar", "func01",
        "(int a, double b)", "", "foo::bar::func01"},
 

>From 48e2ea0bc60e6c4937a4a080fe0ee7dba546a1d2 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <[email protected]>
Date: Thu, 27 Nov 2025 14:50:51 +0000
Subject: [PATCH 3/3] add an example.

---
 lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index ab9affe438c86..a3624accf9b5a 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -209,7 +209,8 @@ static bool IsTrivialBasename(const llvm::StringRef 
&basename) {
 }
 
 /// A context is trivial if an only if it matches this pattern.
-/// "^\s*([A-Za-z_:]*)\s*$".
+/// "^\s*([A-Za-z_:]*)\s*$". for example function `foo::bar::func()`
+/// has a trivial context but. but `foo<int>::bar::func()` doesn't.
 static bool IsTrivialContext(llvm::StringRef context) {
   // remove trailing or leading whitespace.
   context = context.trim();

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to