https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/172520

>From 6094c7a174baa4021677ea6184c7e85c1bcbb562 Mon Sep 17 00:00:00 2001
From: Michael Buch <[email protected]>
Date: Tue, 16 Dec 2025 16:40:28 +0000
Subject: [PATCH 1/2] [lldb][ClangASTSource][NFC] Clean up RegisterNamespaceMap

I've been trying to wrap my head around this code but there's a lot of
action-at-a-distance going on which I'm having trouble following. This
patch cleans up a small part of it.

We were passing the `context`s namespace map as a separate mutable argument. 
But nothing in this function requires it to be mutable (and separate from the 
owning structure). This patch drops the redundant argument and passes the 
shared_ptr by value.
---
 .../ExpressionParser/Clang/ClangASTImporter.cpp      |  4 ++--
 .../ExpressionParser/Clang/ClangASTImporter.h        |  2 +-
 .../ExpressionParser/Clang/ClangASTSource.cpp        | 12 +++++-------
 .../Plugins/ExpressionParser/Clang/ClangASTSource.h  |  3 +--
 4 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
index e3b6ff8f17b4c..0a00335e5c9fb 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -969,10 +969,10 @@ void ClangASTImporter::SetDeclOrigin(const clang::Decl 
*decl,
 }
 
 void ClangASTImporter::RegisterNamespaceMap(const clang::NamespaceDecl *decl,
-                                            NamespaceMapSP &namespace_map) {
+                                            NamespaceMapSP namespace_map) {
   ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
 
-  context_md->m_namespace_maps[decl] = namespace_map;
+  context_md->m_namespace_maps[decl] = std::move(namespace_map);
 }
 
 ClangASTImporter::NamespaceMapSP
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h
index 03d2556ca6f23..f13d8678f22b9 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h
@@ -202,7 +202,7 @@ class ClangASTImporter {
   typedef std::shared_ptr<NamespaceMap> NamespaceMapSP;
 
   void RegisterNamespaceMap(const clang::NamespaceDecl *decl,
-                            NamespaceMapSP &namespace_map);
+                            NamespaceMapSP namespace_map);
 
   NamespaceMapSP GetNamespaceMap(const clang::NamespaceDecl *decl);
 
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index 0efeb2e68decb..d18b02ef03256 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -545,8 +545,7 @@ void 
ClangASTSource::FindExternalVisibleDecls(NameSearchContext &context) {
       LLDB_LOG(log, "  CAS::FEVD Registering namespace map {0:x} ({1} 
entries)",
                context.m_namespace_map.get(), context.m_namespace_map->size());
 
-    NamespaceDecl *clang_namespace_decl =
-        AddNamespace(context, context.m_namespace_map);
+    NamespaceDecl *clang_namespace_decl = AddNamespace(context);
 
     if (clang_namespace_decl)
       clang_namespace_decl->setHasExternalVisibleStorage();
@@ -1433,12 +1432,11 @@ void ClangASTSource::CompleteNamespaceMap(
 }
 
 NamespaceDecl *ClangASTSource::AddNamespace(
-    NameSearchContext &context,
-    ClangASTImporter::NamespaceMapSP &namespace_decls) {
-  if (!namespace_decls)
+    NameSearchContext &context) {
+  if (!context.m_namespace_map)
     return nullptr;
 
-  const CompilerDeclContext &namespace_decl = namespace_decls->begin()->second;
+  const CompilerDeclContext &namespace_decl = 
context.m_namespace_map->begin()->second;
 
   clang::ASTContext *src_ast =
       TypeSystemClang::DeclContextGetTypeSystemClang(namespace_decl);
@@ -1463,7 +1461,7 @@ NamespaceDecl *ClangASTSource::AddNamespace(
   context.m_decls.push_back(copied_namespace_decl);
 
   m_ast_importer_sp->RegisterNamespaceMap(copied_namespace_decl,
-                                          namespace_decls);
+                                          context.m_namespace_map);
 
   return dyn_cast<NamespaceDecl>(copied_decl);
 }
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
index 2450635555eb6..2937a94e62e16 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
@@ -188,8 +188,7 @@ class ClangASTSource : public clang::ExternalASTSource,
   //
 
   clang::NamespaceDecl *
-  AddNamespace(NameSearchContext &context,
-               ClangASTImporter::NamespaceMapSP &namespace_decls);
+  AddNamespace(NameSearchContext &context);
 
   /// The worker function for FindExternalVisibleDeclsByName.
   ///

>From 0c67a924a843d9efa7d83b3d73754f6c4b1274a0 Mon Sep 17 00:00:00 2001
From: Michael Buch <[email protected]>
Date: Tue, 16 Dec 2025 16:46:33 +0000
Subject: [PATCH 2/2] fixup! clang-format

---
 .../Plugins/ExpressionParser/Clang/ClangASTSource.cpp       | 6 +++---
 lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h | 3 +--
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index d18b02ef03256..65c8d3e1305aa 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -1431,12 +1431,12 @@ void ClangASTSource::CompleteNamespaceMap(
   }
 }
 
-NamespaceDecl *ClangASTSource::AddNamespace(
-    NameSearchContext &context) {
+NamespaceDecl *ClangASTSource::AddNamespace(NameSearchContext &context) {
   if (!context.m_namespace_map)
     return nullptr;
 
-  const CompilerDeclContext &namespace_decl = 
context.m_namespace_map->begin()->second;
+  const CompilerDeclContext &namespace_decl =
+      context.m_namespace_map->begin()->second;
 
   clang::ASTContext *src_ast =
       TypeSystemClang::DeclContextGetTypeSystemClang(namespace_decl);
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
index 2937a94e62e16..33edc2d1eecc7 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
@@ -187,8 +187,7 @@ class ClangASTSource : public clang::ExternalASTSource,
   // Helper APIs
   //
 
-  clang::NamespaceDecl *
-  AddNamespace(NameSearchContext &context);
+  clang::NamespaceDecl *AddNamespace(NameSearchContext &context);
 
   /// The worker function for FindExternalVisibleDeclsByName.
   ///

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

Reply via email to