[Lldb-commits] [lldb] f9568a9 - [lldb][NFC] Make all CompilerDeclContext parameters references instead of pointers

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Mon Feb 17 23:59:06 PST 2020


Author: Raphael Isemann
Date: 2020-02-18T08:58:36+01:00
New Revision: f9568a95493aea3ea813bd37cb8c084ec4294e38

URL: https://github.com/llvm/llvm-project/commit/f9568a95493aea3ea813bd37cb8c084ec4294e38
DIFF: https://github.com/llvm/llvm-project/commit/f9568a95493aea3ea813bd37cb8c084ec4294e38.diff

LOG: [lldb][NFC] Make all CompilerDeclContext parameters references instead of pointers

Summary:
All of our lookup APIs either use `CompilerDeclContext &` or `CompilerDeclContext *` semi-randomly it seems.
This leads to us constantly converting between those two types (and doing nullptr checks when going from
pointer to reference). It also leads to the confusing situation where we have two possible ways to express
that we don't have a CompilerDeclContex: either a nullptr or an invalid CompilerDeclContext (aka a default
constructed CompilerDeclContext).

This moves all APIs to use references and gets rid of all the nullptr checks and conversions.

Reviewers: labath, mib, shafik

Reviewed By: labath, shafik

Subscribers: shafik, arphaman, abidh, JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D74607

Added: 
    

Modified: 
    lldb/include/lldb/Core/Module.h
    lldb/include/lldb/Symbol/SymbolFile.h
    lldb/source/API/SBModule.cpp
    lldb/source/Breakpoint/BreakpointResolverName.cpp
    lldb/source/Commands/CommandObjectTarget.cpp
    lldb/source/Core/AddressResolverName.cpp
    lldb/source/Core/Disassembler.cpp
    lldb/source/Core/Module.cpp
    lldb/source/Core/ModuleList.cpp
    lldb/source/Core/SourceManager.cpp
    lldb/source/Expression/IRExecutionUnit.cpp
    lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
    lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
    lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
    lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
    lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
    lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h
    lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
    lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
    lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
    lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
    lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
    lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
    lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
    lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
    lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
    lldb/source/Symbol/SymbolFile.cpp
    lldb/tools/lldb-test/lldb-test.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h
index a811b77e40c9..4715961eabf1 100644
--- a/lldb/include/lldb/Core/Module.h
+++ b/lldb/include/lldb/Core/Module.h
@@ -302,7 +302,7 @@ class Module : public std::enable_shared_from_this<Module>,
   ///     A symbol context list that gets filled in with all of the
   ///     matches.
   void FindFunctions(ConstString name,
-                     const CompilerDeclContext *parent_decl_ctx,
+                     const CompilerDeclContext &parent_decl_ctx,
                      lldb::FunctionNameType name_type_mask, bool symbols_ok,
                      bool inlines_ok, SymbolContextList &sc_list);
 
@@ -365,7 +365,7 @@ class Module : public std::enable_shared_from_this<Module>,
   ///     A list of variables that gets the matches appended to.
   ///
   void FindGlobalVariables(ConstString name,
-                           const CompilerDeclContext *parent_decl_ctx,
+                           const CompilerDeclContext &parent_decl_ctx,
                            size_t max_matches, VariableList &variable_list);
 
   /// Find global and static variables by regular expression.
@@ -444,7 +444,7 @@ class Module : public std::enable_shared_from_this<Module>,
   /// \param[out] type_list
   ///     A type list gets populated with any matches.
   void FindTypesInNamespace(ConstString type_name,
-                            const CompilerDeclContext *parent_decl_ctx,
+                            const CompilerDeclContext &parent_decl_ctx,
                             size_t max_matches, TypeList &type_list);
 
   /// Get const accessor for the module architecture.
@@ -1037,7 +1037,7 @@ class Module : public std::enable_shared_from_this<Module>,
   Module(); // Only used internally by CreateJITModule ()
 
   void FindTypes_Impl(
-      ConstString name, const CompilerDeclContext *parent_decl_ctx,
+      ConstString name, const CompilerDeclContext &parent_decl_ctx,
       size_t max_matches,
       llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
       TypeMap &types);

diff  --git a/lldb/include/lldb/Symbol/SymbolFile.h b/lldb/include/lldb/Symbol/SymbolFile.h
index ef40332296a9..4dc49cdd0391 100644
--- a/lldb/include/lldb/Symbol/SymbolFile.h
+++ b/lldb/include/lldb/Symbol/SymbolFile.h
@@ -208,21 +208,21 @@ class SymbolFile : public PluginInterface {
                                         SymbolContextList &sc_list);
 
   virtual void DumpClangAST(Stream &s) {}
-  virtual void
-  FindGlobalVariables(ConstString name,
-                      const CompilerDeclContext *parent_decl_ctx,
-                      uint32_t max_matches, VariableList &variables);
+  virtual void FindGlobalVariables(ConstString name,
+                                   const CompilerDeclContext &parent_decl_ctx,
+                                   uint32_t max_matches,
+                                   VariableList &variables);
   virtual void FindGlobalVariables(const RegularExpression &regex,
                                    uint32_t max_matches,
                                    VariableList &variables);
   virtual void FindFunctions(ConstString name,
-                             const CompilerDeclContext *parent_decl_ctx,
+                             const CompilerDeclContext &parent_decl_ctx,
                              lldb::FunctionNameType name_type_mask,
                              bool include_inlines, SymbolContextList &sc_list);
   virtual void FindFunctions(const RegularExpression &regex,
                              bool include_inlines, SymbolContextList &sc_list);
   virtual void
-  FindTypes(ConstString name, const CompilerDeclContext *parent_decl_ctx,
+  FindTypes(ConstString name, const CompilerDeclContext &parent_decl_ctx,
             uint32_t max_matches,
             llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
             TypeMap &types);
@@ -251,8 +251,7 @@ class SymbolFile : public PluginInterface {
   GetTypeSystemForLanguage(lldb::LanguageType language);
 
   virtual CompilerDeclContext
-  FindNamespace(ConstString name,
-                const CompilerDeclContext *parent_decl_ctx) {
+  FindNamespace(ConstString name, const CompilerDeclContext &parent_decl_ctx) {
     return CompilerDeclContext();
   }
 

diff  --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp
index a3a5e6a97d8c..0811a3a9b234 100644
--- a/lldb/source/API/SBModule.cpp
+++ b/lldb/source/API/SBModule.cpp
@@ -401,8 +401,8 @@ lldb::SBSymbolContextList SBModule::FindFunctions(const char *name,
     const bool symbols_ok = true;
     const bool inlines_ok = true;
     FunctionNameType type = static_cast<FunctionNameType>(name_type_mask);
-    module_sp->FindFunctions(ConstString(name), nullptr, type, symbols_ok,
-                             inlines_ok, *sb_sc_list);
+    module_sp->FindFunctions(ConstString(name), CompilerDeclContext(), type,
+                             symbols_ok, inlines_ok, *sb_sc_list);
   }
   return LLDB_RECORD_RESULT(sb_sc_list);
 }
@@ -417,8 +417,8 @@ SBValueList SBModule::FindGlobalVariables(SBTarget &target, const char *name,
   ModuleSP module_sp(GetSP());
   if (name && module_sp) {
     VariableList variable_list;
-    module_sp->FindGlobalVariables(ConstString(name), nullptr, max_matches,
-                                   variable_list);
+    module_sp->FindGlobalVariables(ConstString(name), CompilerDeclContext(),
+                                   max_matches, variable_list);
     for (const VariableSP &var_sp : variable_list) {
       lldb::ValueObjectSP valobj_sp;
       TargetSP target_sp(target.GetSP());

diff  --git a/lldb/source/Breakpoint/BreakpointResolverName.cpp b/lldb/source/Breakpoint/BreakpointResolverName.cpp
index fdf70f1d74aa..8f8c5475313b 100644
--- a/lldb/source/Breakpoint/BreakpointResolverName.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolverName.cpp
@@ -278,8 +278,9 @@ BreakpointResolverName::SearchCallback(SearchFilter &filter,
       for (const auto &lookup : m_lookups) {
         const size_t start_func_idx = func_list.GetSize();
         context.module_sp->FindFunctions(
-            lookup.GetLookupName(), nullptr, lookup.GetNameTypeMask(),
-            include_symbols, include_inlines, func_list);
+            lookup.GetLookupName(), CompilerDeclContext(),
+            lookup.GetNameTypeMask(), include_symbols, include_inlines,
+            func_list);
 
         const size_t end_func_idx = func_list.GetSize();
 

diff  --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 50eb46fafca8..c70117c7a80a 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -1599,8 +1599,9 @@ static size_t LookupFunctionInModule(CommandInterpreter &interpreter,
                             include_inlines, sc_list);
     } else {
       ConstString function_name(name);
-      module->FindFunctions(function_name, nullptr, eFunctionNameTypeAuto,
-                            include_symbols, include_inlines, sc_list);
+      module->FindFunctions(function_name, CompilerDeclContext(),
+                            eFunctionNameTypeAuto, include_symbols,
+                            include_inlines, sc_list);
     }
     num_matches = sc_list.GetSize();
     if (num_matches) {

diff  --git a/lldb/source/Core/AddressResolverName.cpp b/lldb/source/Core/AddressResolverName.cpp
index dea69e0c0903..51ab6435e8fb 100644
--- a/lldb/source/Core/AddressResolverName.cpp
+++ b/lldb/source/Core/AddressResolverName.cpp
@@ -91,7 +91,7 @@ AddressResolverName::SearchCallback(SearchFilter &filter,
     if (context.module_sp) {
       context.module_sp->FindSymbolsWithNameAndType(m_func_name,
                                                     eSymbolTypeCode, sym_list);
-      context.module_sp->FindFunctions(m_func_name, nullptr,
+      context.module_sp->FindFunctions(m_func_name, CompilerDeclContext(),
                                        eFunctionNameTypeAuto, include_symbols,
                                        include_inlines, func_list);
     }

diff  --git a/lldb/source/Core/Disassembler.cpp b/lldb/source/Core/Disassembler.cpp
index 26ff0560440a..60247cfdd99e 100644
--- a/lldb/source/Core/Disassembler.cpp
+++ b/lldb/source/Core/Disassembler.cpp
@@ -173,8 +173,8 @@ bool Disassembler::Disassemble(
   // Find functions matching the given name.
   SymbolContextList sc_list;
   if (module) {
-    module->FindFunctions(name, nullptr, eFunctionNameTypeAuto, include_symbols,
-                          include_inlines, sc_list);
+    module->FindFunctions(name, CompilerDeclContext(), eFunctionNameTypeAuto,
+                          include_symbols, include_inlines, sc_list);
   } else if (exe_ctx.GetTargetPtr()) {
     exe_ctx.GetTargetPtr()->GetImages().FindFunctions(
         name, eFunctionNameTypeAuto, include_symbols, include_inlines, sc_list);

diff  --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index 1dd83a530b91..e61b875c3399 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -595,7 +595,7 @@ uint32_t Module::ResolveSymbolContextsForFileSpec(
 }
 
 void Module::FindGlobalVariables(ConstString name,
-                                 const CompilerDeclContext *parent_decl_ctx,
+                                 const CompilerDeclContext &parent_decl_ctx,
                                  size_t max_matches, VariableList &variables) {
   if (SymbolFile *symbols = GetSymbolFile())
     symbols->FindGlobalVariables(name, parent_decl_ctx, max_matches, variables);
@@ -783,7 +783,7 @@ void Module::LookupInfo::Prune(SymbolContextList &sc_list,
 }
 
 void Module::FindFunctions(ConstString name,
-                           const CompilerDeclContext *parent_decl_ctx,
+                           const CompilerDeclContext &parent_decl_ctx,
                            FunctionNameType name_type_mask,
                            bool include_symbols, bool include_inlines,
                            SymbolContextList &sc_list) {
@@ -920,7 +920,7 @@ void Module::FindAddressesForLine(const lldb::TargetSP target_sp,
 }
 
 void Module::FindTypes_Impl(
-    ConstString name, const CompilerDeclContext *parent_decl_ctx,
+    ConstString name, const CompilerDeclContext &parent_decl_ctx,
     size_t max_matches,
     llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
     TypeMap &types) {
@@ -932,7 +932,7 @@ void Module::FindTypes_Impl(
 }
 
 void Module::FindTypesInNamespace(ConstString type_name,
-                                  const CompilerDeclContext *parent_decl_ctx,
+                                  const CompilerDeclContext &parent_decl_ctx,
                                   size_t max_matches, TypeList &type_list) {
   TypeMap types_map;
   llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
@@ -974,7 +974,7 @@ void Module::FindTypes(
     exact_match = type_scope.consume_front("::");
 
     ConstString type_basename_const_str(type_basename);
-    FindTypes_Impl(type_basename_const_str, nullptr, max_matches,
+    FindTypes_Impl(type_basename_const_str, CompilerDeclContext(), max_matches,
                    searched_symbol_files, typesmap);
     if (typesmap.GetSize())
       typesmap.RemoveMismatchedTypes(std::string(type_scope),
@@ -986,13 +986,14 @@ void Module::FindTypes(
     if (type_class != eTypeClassAny && !type_basename.empty()) {
       // The "type_name_cstr" will have been modified if we have a valid type
       // class prefix (like "struct", "class", "union", "typedef" etc).
-      FindTypes_Impl(ConstString(type_basename), nullptr, UINT_MAX,
-                     searched_symbol_files, typesmap);
+      FindTypes_Impl(ConstString(type_basename), CompilerDeclContext(),
+                     UINT_MAX, searched_symbol_files, typesmap);
       typesmap.RemoveMismatchedTypes(std::string(type_scope),
                                      std::string(type_basename), type_class,
                                      exact_match);
     } else {
-      FindTypes_Impl(name, nullptr, UINT_MAX, searched_symbol_files, typesmap);
+      FindTypes_Impl(name, CompilerDeclContext(), UINT_MAX,
+                     searched_symbol_files, typesmap);
       if (exact_match) {
         std::string name_str(name.AsCString(""));
         typesmap.RemoveMismatchedTypes(std::string(type_scope), name_str,

diff  --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp
index 33f74dd71308..0345678ddaff 100644
--- a/lldb/source/Core/ModuleList.cpp
+++ b/lldb/source/Core/ModuleList.cpp
@@ -363,7 +363,7 @@ void ModuleList::FindFunctions(ConstString name,
     std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
     collection::const_iterator pos, end = m_modules.end();
     for (pos = m_modules.begin(); pos != end; ++pos) {
-      (*pos)->FindFunctions(lookup_info.GetLookupName(), nullptr,
+      (*pos)->FindFunctions(lookup_info.GetLookupName(), CompilerDeclContext(),
                             lookup_info.GetNameTypeMask(), include_symbols,
                             include_inlines, sc_list);
     }
@@ -376,8 +376,8 @@ void ModuleList::FindFunctions(ConstString name,
     std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
     collection::const_iterator pos, end = m_modules.end();
     for (pos = m_modules.begin(); pos != end; ++pos) {
-      (*pos)->FindFunctions(name, nullptr, name_type_mask, include_symbols,
-                            include_inlines, sc_list);
+      (*pos)->FindFunctions(name, CompilerDeclContext(), name_type_mask,
+                            include_symbols, include_inlines, sc_list);
     }
   }
 }
@@ -434,7 +434,8 @@ void ModuleList::FindGlobalVariables(ConstString name, size_t max_matches,
   std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
   collection::const_iterator pos, end = m_modules.end();
   for (pos = m_modules.begin(); pos != end; ++pos) {
-    (*pos)->FindGlobalVariables(name, nullptr, max_matches, variable_list);
+    (*pos)->FindGlobalVariables(name, CompilerDeclContext(), max_matches,
+                                variable_list);
   }
 }
 

diff  --git a/lldb/source/Core/SourceManager.cpp b/lldb/source/Core/SourceManager.cpp
index d6edabd29954..191d0573a490 100644
--- a/lldb/source/Core/SourceManager.cpp
+++ b/lldb/source/Core/SourceManager.cpp
@@ -325,7 +325,7 @@ bool SourceManager::GetDefaultFileAndLine(FileSpec &file_spec, uint32_t &line) {
         ConstString main_name("main");
         bool symbols_okay = false; // Force it to be a debug symbol.
         bool inlines_okay = true;
-        executable_ptr->FindFunctions(main_name, nullptr,
+        executable_ptr->FindFunctions(main_name, CompilerDeclContext(),
                                       lldb::eFunctionNameTypeBase, inlines_okay,
                                       symbols_okay, sc_list);
         size_t num_matches = sc_list.GetSize();

diff  --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp
index dd38e3acdb94..36ac5913abbc 100644
--- a/lldb/source/Expression/IRExecutionUnit.cpp
+++ b/lldb/source/Expression/IRExecutionUnit.cpp
@@ -843,7 +843,7 @@ lldb::addr_t IRExecutionUnit::FindInSymbols(
     };
 
     if (sc.module_sp) {
-      sc.module_sp->FindFunctions(spec.name, nullptr, spec.mask,
+      sc.module_sp->FindFunctions(spec.name, CompilerDeclContext(), spec.mask,
                                   true,  // include_symbols
                                   false, // include_inlines
                                   sc_list);

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index cce3ce67a622..ad1111e1aef9 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -252,7 +252,7 @@ void ClangASTSource::CompleteType(TagDecl *tag_decl) {
 
         ConstString name(tag_decl->getName().str().c_str());
 
-        i->first->FindTypesInNamespace(name, &i->second, UINT32_MAX, types);
+        i->first->FindTypesInNamespace(name, i->second, UINT32_MAX, types);
 
         for (uint32_t ti = 0, te = types.GetSize(); ti != te && !found; ++ti) {
           lldb::TypeSP type = types.GetTypeAtIndex(ti);
@@ -664,7 +664,7 @@ void ClangASTSource::FindExternalVisibleDecls(
     CompilerDeclContext found_namespace_decl;
 
     if (SymbolFile *symbol_file = module_sp->GetSymbolFile()) {
-      found_namespace_decl = symbol_file->FindNamespace(name, &namespace_decl);
+      found_namespace_decl = symbol_file->FindNamespace(name, namespace_decl);
 
       if (found_namespace_decl) {
         context.m_namespace_map->push_back(
@@ -692,7 +692,7 @@ void ClangASTSource::FindExternalVisibleDecls(
       if (!symbol_file)
         continue;
 
-      found_namespace_decl = symbol_file->FindNamespace(name, &namespace_decl);
+      found_namespace_decl = symbol_file->FindNamespace(name, namespace_decl);
 
       if (found_namespace_decl) {
         context.m_namespace_map->push_back(
@@ -713,7 +713,7 @@ void ClangASTSource::FindExternalVisibleDecls(
     const bool exact_match = true;
     llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
     if (module_sp && namespace_decl)
-      module_sp->FindTypesInNamespace(name, &namespace_decl, 1, types);
+      module_sp->FindTypesInNamespace(name, namespace_decl, 1, types);
     else {
       m_target->GetImages().FindTypes(module_sp.get(), name, exact_match, 1,
                                       searched_symbol_files, types);
@@ -1696,7 +1696,7 @@ void ClangASTSource::CompleteNamespaceMap(
         continue;
 
       found_namespace_decl =
-          symbol_file->FindNamespace(name, &module_parent_namespace_decl);
+          symbol_file->FindNamespace(name, module_parent_namespace_decl);
 
       if (!found_namespace_decl)
         continue;
@@ -1727,7 +1727,7 @@ void ClangASTSource::CompleteNamespaceMap(
         continue;
 
       found_namespace_decl =
-          symbol_file->FindNamespace(name, &null_namespace_decl);
+          symbol_file->FindNamespace(name, null_namespace_decl);
 
       if (!found_namespace_decl)
         continue;

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
index 6254080ed5c7..f4c6cb2a79a8 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -597,7 +597,7 @@ lldb::VariableSP ClangExpressionDeclMap::FindGlobalVariable(
   VariableList vars;
 
   if (module && namespace_decl)
-    module->FindGlobalVariables(name, namespace_decl, -1, vars);
+    module->FindGlobalVariables(name, *namespace_decl, -1, vars);
   else
     target.GetImages().FindGlobalVariables(name, -1, vars);
 
@@ -1237,7 +1237,7 @@ void ClangExpressionDeclMap::LookupFunction(NameSearchContext &context,
   if (namespace_decl && module_sp) {
     const bool include_symbols = false;
 
-    module_sp->FindFunctions(name, &namespace_decl, eFunctionNameTypeBase,
+    module_sp->FindFunctions(name, namespace_decl, eFunctionNameTypeBase,
                              include_symbols, include_inlines, sc_list);
   } else if (target && !namespace_decl) {
     const bool include_symbols = true;

diff  --git a/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp b/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
index f4c116e7576c..50f0faefa0f4 100644
--- a/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
+++ b/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
@@ -573,7 +573,7 @@ static void GetSymbolDeclarationFromAddress(ProcessSP process_sp, addr_t addr,
     return;
 
   VariableList var_list;
-  module->FindGlobalVariables(sym_name, nullptr, 1U, var_list);
+  module->FindGlobalVariables(sym_name, CompilerDeclContext(), 1U, var_list);
   if (var_list.GetSize() < 1)
     return;
 

diff  --git a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
index f2b95028f807..3ef6a3f39aab 100644
--- a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
@@ -3943,7 +3943,8 @@ void RSModuleDescriptor::Dump(Stream &strm) const {
 void RSGlobalDescriptor::Dump(Stream &strm) const {
   strm.Indent(m_name.GetStringRef());
   VariableList var_list;
-  m_module->m_module->FindGlobalVariables(m_name, nullptr, 1U, var_list);
+  m_module->m_module->FindGlobalVariables(m_name, CompilerDeclContext(), 1U,
+                                          var_list);
   if (var_list.GetSize() == 1) {
     auto var = var_list.GetVariableAtIndex(0);
     auto type = var->GetType();

diff  --git a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
index fcefb2e059b2..9c2cea4d9727 100644
--- a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
+++ b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
@@ -294,7 +294,7 @@ uint32_t SymbolFileBreakpad::ResolveSymbolContext(
 }
 
 void SymbolFileBreakpad::FindFunctions(
-    ConstString name, const CompilerDeclContext *parent_decl_ctx,
+    ConstString name, const CompilerDeclContext &parent_decl_ctx,
     FunctionNameType name_type_mask, bool include_inlines,
     SymbolContextList &sc_list) {
   // TODO
@@ -307,7 +307,7 @@ void SymbolFileBreakpad::FindFunctions(const RegularExpression &regex,
 }
 
 void SymbolFileBreakpad::FindTypes(
-    ConstString name, const CompilerDeclContext *parent_decl_ctx,
+    ConstString name, const CompilerDeclContext &parent_decl_ctx,
     uint32_t max_matches, llvm::DenseSet<SymbolFile *> &searched_symbol_files,
     TypeMap &types) {}
 

diff  --git a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h
index 2753ee1eb9cb..90dbcc77627a 100644
--- a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h
+++ b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h
@@ -82,7 +82,7 @@ class SymbolFileBreakpad : public SymbolFile {
   size_t ParseBlocksRecursive(Function &func) override { return 0; }
 
   void FindGlobalVariables(ConstString name,
-                           const CompilerDeclContext *parent_decl_ctx,
+                           const CompilerDeclContext &parent_decl_ctx,
                            uint32_t max_matches,
                            VariableList &variables) override {}
 
@@ -110,14 +110,14 @@ class SymbolFileBreakpad : public SymbolFile {
                 TypeList &type_list) override {}
 
   void FindFunctions(ConstString name,
-                     const CompilerDeclContext *parent_decl_ctx,
+                     const CompilerDeclContext &parent_decl_ctx,
                      lldb::FunctionNameType name_type_mask,
                      bool include_inlines, SymbolContextList &sc_list) override;
 
   void FindFunctions(const RegularExpression &regex, bool include_inlines,
                      SymbolContextList &sc_list) override;
 
-  void FindTypes(ConstString name, const CompilerDeclContext *parent_decl_ctx,
+  void FindTypes(ConstString name, const CompilerDeclContext &parent_decl_ctx,
                  uint32_t max_matches,
                  llvm::DenseSet<SymbolFile *> &searched_symbol_files,
                  TypeMap &types) override;
@@ -135,7 +135,7 @@ class SymbolFileBreakpad : public SymbolFile {
 
   CompilerDeclContext
   FindNamespace(ConstString name,
-                const CompilerDeclContext *parent_decl_ctx) override {
+                const CompilerDeclContext &parent_decl_ctx) override {
     return CompilerDeclContext();
   }
 

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
index 7b8e499a27b4..0445fa551639 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
@@ -36,7 +36,7 @@ void DWARFIndex::ProcessFunctionDIE(llvm::StringRef name, DIERef ref,
 
   // Otherwise, we need to also check that the context matches. If it does not
   // match, we do nothing.
-  if (!SymbolFileDWARF::DIEInDeclContext(&parent_decl_ctx, die))
+  if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die))
     return;
 
   // In case of a full match, we just insert everything we find.

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
index c86149d2692e..6480bef29e10 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
@@ -406,7 +406,7 @@ void ManualDWARFIndex::GetFunctions(ConstString name, SymbolFileDWARF &dwarf,
       DWARFDIE die = dwarf.GetDIE(die_ref);
       if (!die)
         continue;
-      if (SymbolFileDWARF::DIEInDeclContext(&parent_decl_ctx, die))
+      if (SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die))
         dies.push_back(die);
     }
   }
@@ -417,7 +417,7 @@ void ManualDWARFIndex::GetFunctions(ConstString name, SymbolFileDWARF &dwarf,
       DWARFDIE die = dwarf.GetDIE(die_ref);
       if (!die)
         continue;
-      if (SymbolFileDWARF::DIEInDeclContext(&parent_decl_ctx, die))
+      if (SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die))
         dies.push_back(die);
     }
     offsets.clear();

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 954f1110ba1e..f288ac97b4f5 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -2004,15 +2004,15 @@ std::recursive_mutex &SymbolFileDWARF::GetModuleMutex() const {
 }
 
 bool SymbolFileDWARF::DeclContextMatchesThisSymbolFile(
-    const lldb_private::CompilerDeclContext *decl_ctx) {
-  if (decl_ctx == nullptr || !decl_ctx->IsValid()) {
+    const lldb_private::CompilerDeclContext &decl_ctx) {
+  if (!decl_ctx.IsValid()) {
     // Invalid namespace decl which means we aren't matching only things in
     // this symbol file, so return true to indicate it matches this symbol
     // file.
     return true;
   }
 
-  TypeSystem *decl_ctx_type_system = decl_ctx->GetTypeSystem();
+  TypeSystem *decl_ctx_type_system = decl_ctx.GetTypeSystem();
   auto type_system_or_err = GetTypeSystemForLanguage(
       decl_ctx_type_system->GetMinimumLanguage(nullptr));
   if (auto err = type_system_or_err.takeError()) {
@@ -2036,7 +2036,7 @@ bool SymbolFileDWARF::DeclContextMatchesThisSymbolFile(
 }
 
 void SymbolFileDWARF::FindGlobalVariables(
-    ConstString name, const CompilerDeclContext *parent_decl_ctx,
+    ConstString name, const CompilerDeclContext &parent_decl_ctx,
     uint32_t max_matches, VariableList &variables) {
   std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
   Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
@@ -2046,7 +2046,7 @@ void SymbolFileDWARF::FindGlobalVariables(
         log,
         "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", "
         "parent_decl_ctx=%p, max_matches=%u, variables)",
-        name.GetCString(), static_cast<const void *>(parent_decl_ctx),
+        name.GetCString(), static_cast<const void *>(&parent_decl_ctx),
         max_matches);
 
   if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
@@ -2104,7 +2104,7 @@ void SymbolFileDWARF::FindGlobalVariables(
               CompilerDeclContext actual_parent_decl_ctx =
                   dwarf_ast->GetDeclContextContainingUIDFromDWARF(die);
               if (!actual_parent_decl_ctx ||
-                  actual_parent_decl_ctx != *parent_decl_ctx)
+                  actual_parent_decl_ctx != parent_decl_ctx)
                 continue;
             }
           }
@@ -2137,7 +2137,7 @@ void SymbolFileDWARF::FindGlobalVariables(
         log,
         "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", "
         "parent_decl_ctx=%p, max_matches=%u, variables) => %u",
-        name.GetCString(), static_cast<const void *>(parent_decl_ctx),
+        name.GetCString(), static_cast<const void *>(&parent_decl_ctx),
         max_matches, num_matches);
   }
 }
@@ -2249,26 +2249,26 @@ bool SymbolFileDWARF::ResolveFunction(const DWARFDIE &orig_die,
   return false;
 }
 
-bool SymbolFileDWARF::DIEInDeclContext(const CompilerDeclContext *decl_ctx,
+bool SymbolFileDWARF::DIEInDeclContext(const CompilerDeclContext &decl_ctx,
                                        const DWARFDIE &die) {
   // If we have no parent decl context to match this DIE matches, and if the
   // parent decl context isn't valid, we aren't trying to look for any
   // particular decl context so any die matches.
-  if (decl_ctx == nullptr || !decl_ctx->IsValid())
+  if (!decl_ctx.IsValid())
     return true;
 
   if (die) {
     if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) {
       if (CompilerDeclContext actual_decl_ctx =
               dwarf_ast->GetDeclContextContainingUIDFromDWARF(die))
-        return decl_ctx->IsContainedInLookup(actual_decl_ctx);
+        return decl_ctx.IsContainedInLookup(actual_decl_ctx);
     }
   }
   return false;
 }
 
 void SymbolFileDWARF::FindFunctions(ConstString name,
-                                    const CompilerDeclContext *parent_decl_ctx,
+                                    const CompilerDeclContext &parent_decl_ctx,
                                     FunctionNameType name_type_mask,
                                     bool include_inlines,
                                     SymbolContextList &sc_list) {
@@ -2304,12 +2304,9 @@ void SymbolFileDWARF::FindFunctions(ConstString name,
 
   llvm::DenseSet<const DWARFDebugInfoEntry *> resolved_dies;
   DIEArray offsets;
-  CompilerDeclContext empty_decl_ctx;
-  if (!parent_decl_ctx)
-    parent_decl_ctx = &empty_decl_ctx;
 
   std::vector<DWARFDIE> dies;
-  m_index->GetFunctions(name, *this, *parent_decl_ctx, name_type_mask, dies);
+  m_index->GetFunctions(name, *this, parent_decl_ctx, name_type_mask, dies);
   for (const DWARFDIE &die : dies) {
     if (resolved_dies.insert(die.GetDIE()).second)
       ResolveFunction(die, include_inlines, sc_list);
@@ -2389,7 +2386,7 @@ void SymbolFileDWARF::GetMangledNamesForFunction(
 }
 
 void SymbolFileDWARF::FindTypes(
-    ConstString name, const CompilerDeclContext *parent_decl_ctx,
+    ConstString name, const CompilerDeclContext &parent_decl_ctx,
     uint32_t max_matches,
     llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
     TypeMap &types) {
@@ -2410,8 +2407,8 @@ void SymbolFileDWARF::FindTypes(
           log,
           "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = "
           "%p (\"%s\"), max_matches=%u, type_list)",
-          name.GetCString(), static_cast<const void *>(parent_decl_ctx),
-          parent_decl_ctx->GetName().AsCString("<NULL>"), max_matches);
+          name.GetCString(), static_cast<const void *>(&parent_decl_ctx),
+          parent_decl_ctx.GetName().AsCString("<NULL>"), max_matches);
     else
       GetObjectFile()->GetModule()->LogMessage(
           log,
@@ -2466,8 +2463,8 @@ void SymbolFileDWARF::FindTypes(
           log,
           "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx "
           "= %p (\"%s\"), max_matches=%u, type_list) => %u",
-          name.GetCString(), static_cast<const void *>(parent_decl_ctx),
-          parent_decl_ctx->GetName().AsCString("<NULL>"), max_matches,
+          name.GetCString(), static_cast<const void *>(&parent_decl_ctx),
+          parent_decl_ctx.GetName().AsCString("<NULL>"), max_matches,
           types.GetSize());
     } else {
       GetObjectFile()->GetModule()->LogMessage(
@@ -2535,7 +2532,7 @@ void SymbolFileDWARF::FindTypes(
 
 CompilerDeclContext
 SymbolFileDWARF::FindNamespace(ConstString name,
-                               const CompilerDeclContext *parent_decl_ctx) {
+                               const CompilerDeclContext &parent_decl_ctx) {
   std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
   Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
 

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
index fd41363a9299..d8165d718499 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -166,7 +166,7 @@ class SymbolFileDWARF : public lldb_private::SymbolFile,
 
   void
   FindGlobalVariables(lldb_private::ConstString name,
-                      const lldb_private::CompilerDeclContext *parent_decl_ctx,
+                      const lldb_private::CompilerDeclContext &parent_decl_ctx,
                       uint32_t max_matches,
                       lldb_private::VariableList &variables) override;
 
@@ -175,7 +175,7 @@ class SymbolFileDWARF : public lldb_private::SymbolFile,
                            lldb_private::VariableList &variables) override;
 
   void FindFunctions(lldb_private::ConstString name,
-                     const lldb_private::CompilerDeclContext *parent_decl_ctx,
+                     const lldb_private::CompilerDeclContext &parent_decl_ctx,
                      lldb::FunctionNameType name_type_mask,
                      bool include_inlines,
                      lldb_private::SymbolContextList &sc_list) override;
@@ -190,7 +190,7 @@ class SymbolFileDWARF : public lldb_private::SymbolFile,
 
   void
   FindTypes(lldb_private::ConstString name,
-            const lldb_private::CompilerDeclContext *parent_decl_ctx,
+            const lldb_private::CompilerDeclContext &parent_decl_ctx,
             uint32_t max_matches,
             llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
             lldb_private::TypeMap &types) override;
@@ -209,7 +209,7 @@ class SymbolFileDWARF : public lldb_private::SymbolFile,
 
   lldb_private::CompilerDeclContext FindNamespace(
       lldb_private::ConstString name,
-      const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
+      const lldb_private::CompilerDeclContext &parent_decl_ctx) override;
 
   void PreloadSymbols() override;
 
@@ -280,7 +280,7 @@ class SymbolFileDWARF : public lldb_private::SymbolFile,
   llvm::Optional<uint64_t> GetDWOId();
 
   static bool
-  DIEInDeclContext(const lldb_private::CompilerDeclContext *parent_decl_ctx,
+  DIEInDeclContext(const lldb_private::CompilerDeclContext &parent_decl_ctx,
                    const DWARFDIE &die);
 
   std::vector<std::unique_ptr<lldb_private::CallEdge>>
@@ -331,7 +331,7 @@ class SymbolFileDWARF : public lldb_private::SymbolFile,
                                lldb_private::DWARFDataExtractor &data);
 
   bool DeclContextMatchesThisSymbolFile(
-      const lldb_private::CompilerDeclContext *decl_ctx);
+      const lldb_private::CompilerDeclContext &decl_ctx);
 
   uint32_t CalculateNumCompileUnits() override;
 

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
index 01e50efdcb5f..a06c40f9b72d 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -824,7 +824,7 @@ uint32_t SymbolFileDWARFDebugMap::ResolveSymbolContext(
 }
 
 void SymbolFileDWARFDebugMap::PrivateFindGlobalVariables(
-    ConstString name, const CompilerDeclContext *parent_decl_ctx,
+    ConstString name, const CompilerDeclContext &parent_decl_ctx,
     const std::vector<uint32_t>
         &indexes, // Indexes into the symbol table that match "name"
     uint32_t max_matches, VariableList &variables) {
@@ -846,7 +846,7 @@ void SymbolFileDWARFDebugMap::PrivateFindGlobalVariables(
 }
 
 void SymbolFileDWARFDebugMap::FindGlobalVariables(
-    ConstString name, const CompilerDeclContext *parent_decl_ctx,
+    ConstString name, const CompilerDeclContext &parent_decl_ctx,
     uint32_t max_matches, VariableList &variables) {
   std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
   uint32_t total_matches = 0;
@@ -1000,7 +1000,7 @@ static void RemoveFunctionsWithModuleNotEqualTo(const ModuleSP &module_sp,
 }
 
 void SymbolFileDWARFDebugMap::FindFunctions(
-    ConstString name, const CompilerDeclContext *parent_decl_ctx,
+    ConstString name, const CompilerDeclContext &parent_decl_ctx,
     FunctionNameType name_type_mask, bool include_inlines,
     SymbolContextList &sc_list) {
   std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
@@ -1170,7 +1170,7 @@ TypeSP SymbolFileDWARFDebugMap::FindCompleteObjCDefinitionTypeForDIE(
 }
 
 void SymbolFileDWARFDebugMap::FindTypes(
-    ConstString name, const CompilerDeclContext *parent_decl_ctx,
+    ConstString name, const CompilerDeclContext &parent_decl_ctx,
     uint32_t max_matches,
     llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
     TypeMap &types) {
@@ -1207,7 +1207,7 @@ void SymbolFileDWARFDebugMap::FindTypes(
 
 CompilerDeclContext SymbolFileDWARFDebugMap::FindNamespace(
     lldb_private::ConstString name,
-    const CompilerDeclContext *parent_decl_ctx) {
+    const CompilerDeclContext &parent_decl_ctx) {
   std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
   CompilerDeclContext matching_namespace;
 

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
index fa8232609b67..fcbb0489b82d 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
@@ -105,14 +105,14 @@ class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile {
                        lldb_private::SymbolContextList &sc_list) override;
   void
   FindGlobalVariables(lldb_private::ConstString name,
-                      const lldb_private::CompilerDeclContext *parent_decl_ctx,
+                      const lldb_private::CompilerDeclContext &parent_decl_ctx,
                       uint32_t max_matches,
                       lldb_private::VariableList &variables) override;
   void FindGlobalVariables(const lldb_private::RegularExpression &regex,
                            uint32_t max_matches,
                            lldb_private::VariableList &variables) override;
   void FindFunctions(lldb_private::ConstString name,
-                     const lldb_private::CompilerDeclContext *parent_decl_ctx,
+                     const lldb_private::CompilerDeclContext &parent_decl_ctx,
                      lldb::FunctionNameType name_type_mask,
                      bool include_inlines,
                      lldb_private::SymbolContextList &sc_list) override;
@@ -121,7 +121,7 @@ class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile {
                      lldb_private::SymbolContextList &sc_list) override;
   void
   FindTypes(lldb_private::ConstString name,
-            const lldb_private::CompilerDeclContext *parent_decl_ctx,
+            const lldb_private::CompilerDeclContext &parent_decl_ctx,
             uint32_t max_matches,
             llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
             lldb_private::TypeMap &types) override;
@@ -132,7 +132,7 @@ class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile {
             lldb_private::TypeMap &types) override;
   lldb_private::CompilerDeclContext FindNamespace(
       lldb_private::ConstString name,
-      const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
+      const lldb_private::CompilerDeclContext &parent_decl_ctx) override;
   void GetTypes(lldb_private::SymbolContextScope *sc_scope,
                 lldb::TypeClass type_mask,
                 lldb_private::TypeList &type_list) override;
@@ -254,7 +254,7 @@ class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile {
 
   void PrivateFindGlobalVariables(
       lldb_private::ConstString name,
-      const lldb_private::CompilerDeclContext *parent_decl_ctx,
+      const lldb_private::CompilerDeclContext &parent_decl_ctx,
       const std::vector<uint32_t> &name_symbol_indexes, uint32_t max_matches,
       lldb_private::VariableList &variables);
 

diff  --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
index 73dec53eda6a..2f8b1dcc9135 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
@@ -1171,7 +1171,7 @@ size_t SymbolFileNativePDB::ParseBlocksRecursive(Function &func) {
 void SymbolFileNativePDB::DumpClangAST(Stream &s) { m_ast->Dump(s); }
 
 void SymbolFileNativePDB::FindGlobalVariables(
-    ConstString name, const CompilerDeclContext *parent_decl_ctx,
+    ConstString name, const CompilerDeclContext &parent_decl_ctx,
     uint32_t max_matches, VariableList &variables) {
   std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
   using SymbolAndOffset = std::pair<uint32_t, llvm::codeview::CVSymbol>;
@@ -1198,7 +1198,7 @@ void SymbolFileNativePDB::FindGlobalVariables(
 }
 
 void SymbolFileNativePDB::FindFunctions(
-    ConstString name, const CompilerDeclContext *parent_decl_ctx,
+    ConstString name, const CompilerDeclContext &parent_decl_ctx,
     FunctionNameType name_type_mask, bool include_inlines,
     SymbolContextList &sc_list) {
   std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
@@ -1236,7 +1236,7 @@ void SymbolFileNativePDB::FindFunctions(const RegularExpression &regex,
                                         SymbolContextList &sc_list) {}
 
 void SymbolFileNativePDB::FindTypes(
-    ConstString name, const CompilerDeclContext *parent_decl_ctx,
+    ConstString name, const CompilerDeclContext &parent_decl_ctx,
     uint32_t max_matches, llvm::DenseSet<SymbolFile *> &searched_symbol_files,
     TypeMap &types) {
   std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
@@ -1563,7 +1563,7 @@ void SymbolFileNativePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope,
 
 CompilerDeclContext
 SymbolFileNativePDB::FindNamespace(ConstString name,
-                                   const CompilerDeclContext *parent_decl_ctx) {
+                                   const CompilerDeclContext &parent_decl_ctx) {
   return {};
 }
 

diff  --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
index 883fd577fffa..bf5718e11a19 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
@@ -100,7 +100,7 @@ class SymbolFileNativePDB : public SymbolFile {
   size_t ParseBlocksRecursive(Function &func) override;
 
   void FindGlobalVariables(ConstString name,
-                           const CompilerDeclContext *parent_decl_ctx,
+                           const CompilerDeclContext &parent_decl_ctx,
                            uint32_t max_matches,
                            VariableList &variables) override;
 
@@ -129,14 +129,14 @@ class SymbolFileNativePDB : public SymbolFile {
                 TypeList &type_list) override;
 
   void FindFunctions(ConstString name,
-                     const CompilerDeclContext *parent_decl_ctx,
+                     const CompilerDeclContext &parent_decl_ctx,
                      lldb::FunctionNameType name_type_mask,
                      bool include_inlines, SymbolContextList &sc_list) override;
 
   void FindFunctions(const RegularExpression &regex, bool include_inlines,
                      SymbolContextList &sc_list) override;
 
-  void FindTypes(ConstString name, const CompilerDeclContext *parent_decl_ctx,
+  void FindTypes(ConstString name, const CompilerDeclContext &parent_decl_ctx,
                  uint32_t max_matches,
                  llvm::DenseSet<SymbolFile *> &searched_symbol_files,
                  TypeMap &types) override;
@@ -150,7 +150,7 @@ class SymbolFileNativePDB : public SymbolFile {
 
   CompilerDeclContext
   FindNamespace(ConstString name,
-                const CompilerDeclContext *parent_decl_ctx) override;
+                const CompilerDeclContext &parent_decl_ctx) override;
 
   ConstString GetPluginName() override;
 

diff  --git a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
index 75f2eb159421..eadd3b2f1642 100644
--- a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
@@ -1098,8 +1098,7 @@ SymbolFilePDB::ParseVariables(const lldb_private::SymbolContext &sc,
 }
 
 void SymbolFilePDB::FindGlobalVariables(
-    lldb_private::ConstString name,
-    const lldb_private::CompilerDeclContext *parent_decl_ctx,
+    lldb_private::ConstString name, const CompilerDeclContext &parent_decl_ctx,
     uint32_t max_matches, lldb_private::VariableList &variables) {
   std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
   if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
@@ -1131,8 +1130,8 @@ void SymbolFilePDB::FindGlobalVariables(
     if (sc.comp_unit == nullptr)
       continue;
 
-    if (parent_decl_ctx && GetDeclContextContainingUID(
-                               result->getSymIndexId()) != *parent_decl_ctx)
+    if (parent_decl_ctx.IsValid() &&
+        GetDeclContextContainingUID(result->getSymIndexId()) != parent_decl_ctx)
       continue;
 
     ParseVariables(sc, *pdb_data, &variables);
@@ -1296,7 +1295,7 @@ void SymbolFilePDB::CacheFunctionNames() {
 
 void SymbolFilePDB::FindFunctions(
     lldb_private::ConstString name,
-    const lldb_private::CompilerDeclContext *parent_decl_ctx,
+    const lldb_private::CompilerDeclContext &parent_decl_ctx,
     FunctionNameType name_type_mask, bool include_inlines,
     lldb_private::SymbolContextList &sc_list) {
   std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
@@ -1325,8 +1324,8 @@ void SymbolFilePDB::FindFunctions(
         if (resolved_ids.find(id) != resolved_ids.end())
           continue;
 
-        if (parent_decl_ctx &&
-            GetDeclContextContainingUID(id) != *parent_decl_ctx)
+        if (parent_decl_ctx.IsValid() &&
+            GetDeclContextContainingUID(id) != parent_decl_ctx)
           continue;
 
         if (ResolveFunction(id, include_inlines, sc_list))
@@ -1424,8 +1423,7 @@ void SymbolFilePDB::AddSymbols(lldb_private::Symtab &symtab) {
 }
 
 void SymbolFilePDB::FindTypes(
-    lldb_private::ConstString name,
-    const lldb_private::CompilerDeclContext *parent_decl_ctx,
+    lldb_private::ConstString name, const CompilerDeclContext &parent_decl_ctx,
     uint32_t max_matches,
     llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
     lldb_private::TypeMap &types) {
@@ -1515,7 +1513,7 @@ void SymbolFilePDB::FindTypesByRegex(
 
 void SymbolFilePDB::FindTypesByName(
     llvm::StringRef name,
-    const lldb_private::CompilerDeclContext *parent_decl_ctx,
+    const lldb_private::CompilerDeclContext &parent_decl_ctx,
     uint32_t max_matches, lldb_private::TypeMap &types) {
   std::unique_ptr<IPDBEnumSymbols> results;
   if (name.empty())
@@ -1550,8 +1548,8 @@ void SymbolFilePDB::FindTypesByName(
     if (!ResolveTypeUID(result->getSymIndexId()))
       continue;
 
-    if (parent_decl_ctx && GetDeclContextContainingUID(
-                               result->getSymIndexId()) != *parent_decl_ctx)
+    if (parent_decl_ctx.IsValid() &&
+        GetDeclContextContainingUID(result->getSymIndexId()) != parent_decl_ctx)
       continue;
 
     auto iter = m_types.find(result->getSymIndexId());
@@ -1672,10 +1670,9 @@ PDBASTParser *SymbolFilePDB::GetPDBAstParser() {
   return clang_type_system->GetPDBParser();
 }
 
-
-lldb_private::CompilerDeclContext SymbolFilePDB::FindNamespace(
-    lldb_private::ConstString name,
-    const lldb_private::CompilerDeclContext *parent_decl_ctx) {
+lldb_private::CompilerDeclContext
+SymbolFilePDB::FindNamespace(lldb_private::ConstString name,
+                             const CompilerDeclContext &parent_decl_ctx) {
   std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
   auto type_system_or_err =
       GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus);
@@ -1698,7 +1695,7 @@ lldb_private::CompilerDeclContext SymbolFilePDB::FindNamespace(
   clang::DeclContext *decl_context = nullptr;
   if (parent_decl_ctx)
     decl_context = static_cast<clang::DeclContext *>(
-        parent_decl_ctx->GetOpaqueDeclContext());
+        parent_decl_ctx.GetOpaqueDeclContext());
 
   auto namespace_decl =
       pdb->FindNamespaceDecl(decl_context, name.GetStringRef());
@@ -1972,11 +1969,11 @@ SymbolFilePDB::GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func) {
 }
 
 bool SymbolFilePDB::DeclContextMatchesThisSymbolFile(
-    const lldb_private::CompilerDeclContext *decl_ctx) {
-  if (decl_ctx == nullptr || !decl_ctx->IsValid())
+    const lldb_private::CompilerDeclContext &decl_ctx) {
+  if (!decl_ctx.IsValid())
     return true;
 
-  TypeSystem *decl_ctx_type_system = decl_ctx->GetTypeSystem();
+  TypeSystem *decl_ctx_type_system = decl_ctx.GetTypeSystem();
   if (!decl_ctx_type_system)
     return false;
   auto type_system_or_err = GetTypeSystemForLanguage(

diff  --git a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
index 05baed4f171d..928cbffc5f63 100644
--- a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
+++ b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
@@ -112,7 +112,7 @@ class SymbolFilePDB : public lldb_private::SymbolFile {
 
   void
   FindGlobalVariables(lldb_private::ConstString name,
-                      const lldb_private::CompilerDeclContext *parent_decl_ctx,
+                      const lldb_private::CompilerDeclContext &parent_decl_ctx,
                       uint32_t max_matches,
                       lldb_private::VariableList &variables) override;
 
@@ -121,7 +121,7 @@ class SymbolFilePDB : public lldb_private::SymbolFile {
                            lldb_private::VariableList &variables) override;
 
   void FindFunctions(lldb_private::ConstString name,
-                     const lldb_private::CompilerDeclContext *parent_decl_ctx,
+                     const lldb_private::CompilerDeclContext &parent_decl_ctx,
                      lldb::FunctionNameType name_type_mask,
                      bool include_inlines,
                      lldb_private::SymbolContextList &sc_list) override;
@@ -138,7 +138,7 @@ class SymbolFilePDB : public lldb_private::SymbolFile {
 
   void
   FindTypes(lldb_private::ConstString name,
-            const lldb_private::CompilerDeclContext *parent_decl_ctx,
+            const lldb_private::CompilerDeclContext &parent_decl_ctx,
             uint32_t max_matches,
             llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
             lldb_private::TypeMap &types) override;
@@ -160,7 +160,7 @@ class SymbolFilePDB : public lldb_private::SymbolFile {
 
   lldb_private::CompilerDeclContext FindNamespace(
       lldb_private::ConstString name,
-      const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
+      const lldb_private::CompilerDeclContext &parent_decl_ctx) override;
 
   lldb_private::ConstString GetPluginName() override;
 
@@ -195,7 +195,7 @@ class SymbolFilePDB : public lldb_private::SymbolFile {
       llvm::DenseMap<uint32_t, uint32_t> &index_map) const;
 
   void FindTypesByName(llvm::StringRef name,
-                       const lldb_private::CompilerDeclContext *parent_decl_ctx,
+                       const lldb_private::CompilerDeclContext &parent_decl_ctx,
                        uint32_t max_matches, lldb_private::TypeMap &types);
 
   std::string GetMangledForPDBData(const llvm::pdb::PDBSymbolData &pdb_data);
@@ -242,7 +242,7 @@ class SymbolFilePDB : public lldb_private::SymbolFile {
   void CacheFunctionNames();
 
   bool DeclContextMatchesThisSymbolFile(
-      const lldb_private::CompilerDeclContext *decl_ctx);
+      const lldb_private::CompilerDeclContext &decl_ctx);
 
   uint32_t GetCompilandId(const llvm::pdb::PDBSymbolData &data);
 

diff  --git a/lldb/source/Symbol/SymbolFile.cpp b/lldb/source/Symbol/SymbolFile.cpp
index 12e284c8c154..3f9cdefc8d41 100644
--- a/lldb/source/Symbol/SymbolFile.cpp
+++ b/lldb/source/Symbol/SymbolFile.cpp
@@ -105,7 +105,7 @@ uint32_t SymbolFile::ResolveSymbolContext(const FileSpec &file_spec,
 }
 
 void SymbolFile::FindGlobalVariables(ConstString name,
-                                     const CompilerDeclContext *parent_decl_ctx,
+                                     const CompilerDeclContext &parent_decl_ctx,
                                      uint32_t max_matches,
                                      VariableList &variables) {}
 
@@ -114,7 +114,7 @@ void SymbolFile::FindGlobalVariables(const RegularExpression &regex,
                                      VariableList &variables) {}
 
 void SymbolFile::FindFunctions(ConstString name,
-                               const CompilerDeclContext *parent_decl_ctx,
+                               const CompilerDeclContext &parent_decl_ctx,
                                lldb::FunctionNameType name_type_mask,
                                bool include_inlines,
                                SymbolContextList &sc_list) {}
@@ -130,7 +130,7 @@ void SymbolFile::GetMangledNamesForFunction(
 }
 
 void SymbolFile::FindTypes(
-    ConstString name, const CompilerDeclContext *parent_decl_ctx,
+    ConstString name, const CompilerDeclContext &parent_decl_ctx,
     uint32_t max_matches,
     llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
     TypeMap &types) {}

diff  --git a/lldb/tools/lldb-test/lldb-test.cpp b/lldb/tools/lldb-test/lldb-test.cpp
index 0bd532fa2945..2e2310a94c74 100644
--- a/lldb/tools/lldb-test/lldb-test.cpp
+++ b/lldb/tools/lldb-test/lldb-test.cpp
@@ -395,7 +395,8 @@ opts::symbols::getDeclContext(SymbolFile &Symfile) {
   if (Context.empty())
     return CompilerDeclContext();
   VariableList List;
-  Symfile.FindGlobalVariables(ConstString(Context), nullptr, UINT32_MAX, List);
+  Symfile.FindGlobalVariables(ConstString(Context), CompilerDeclContext(),
+                              UINT32_MAX, List);
   if (List.Empty())
     return make_string_error("Context search didn't find a match.");
   if (List.GetSize() > 1)
@@ -442,8 +443,8 @@ Error opts::symbols::findFunctions(lldb_private::Module &Module) {
     Expected<CompilerDeclContext> ContextOr = getDeclContext(Symfile);
     if (!ContextOr)
       return ContextOr.takeError();
-    CompilerDeclContext *ContextPtr =
-        ContextOr->IsValid() ? &*ContextOr : nullptr;
+    const CompilerDeclContext &ContextPtr =
+        ContextOr->IsValid() ? *ContextOr : CompilerDeclContext();
 
     List.Clear();
     Symfile.FindFunctions(ConstString(Name), ContextPtr, getFunctionNameFlags(),
@@ -498,8 +499,8 @@ Error opts::symbols::findNamespaces(lldb_private::Module &Module) {
   Expected<CompilerDeclContext> ContextOr = getDeclContext(Symfile);
   if (!ContextOr)
     return ContextOr.takeError();
-  CompilerDeclContext *ContextPtr =
-      ContextOr->IsValid() ? &*ContextOr : nullptr;
+  const CompilerDeclContext &ContextPtr =
+      ContextOr->IsValid() ? *ContextOr : CompilerDeclContext();
 
   CompilerDeclContext Result =
       Symfile.FindNamespace(ConstString(Name), ContextPtr);
@@ -516,8 +517,8 @@ Error opts::symbols::findTypes(lldb_private::Module &Module) {
   Expected<CompilerDeclContext> ContextOr = getDeclContext(Symfile);
   if (!ContextOr)
     return ContextOr.takeError();
-  CompilerDeclContext *ContextPtr =
-      ContextOr->IsValid() ? &*ContextOr : nullptr;
+  const CompilerDeclContext &ContextPtr =
+      ContextOr->IsValid() ? *ContextOr : CompilerDeclContext();
 
   LanguageSet languages;
   if (!Language.empty())
@@ -566,8 +567,8 @@ Error opts::symbols::findVariables(lldb_private::Module &Module) {
     Expected<CompilerDeclContext> ContextOr = getDeclContext(Symfile);
     if (!ContextOr)
       return ContextOr.takeError();
-    CompilerDeclContext *ContextPtr =
-        ContextOr->IsValid() ? &*ContextOr : nullptr;
+    const CompilerDeclContext &ContextPtr =
+        ContextOr->IsValid() ? *ContextOr : CompilerDeclContext();
 
     Symfile.FindGlobalVariables(ConstString(Name), ContextPtr, UINT32_MAX, List);
   }


        


More information about the lldb-commits mailing list