[Lldb-commits] [lldb] f9f49d3 - [lldb][NFC] Return a reference from ClangASTContext::getASTContext and remove dead nullptr checks

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Sat Dec 21 13:54:53 PST 2019


Author: Raphael Isemann
Date: 2019-12-21T22:51:35+01:00
New Revision: f9f49d3594bc7584cc5cb96125ca08f2ad97662c

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

LOG: [lldb][NFC] Return a reference from ClangASTContext::getASTContext and remove dead nullptr checks

ClangASTContext::getASTContext() currently returns a ptr but we have an assert there since a
while that the ASTContext is not a nullptr. This causes that we still have a lot of code
that is doing nullptr checks on the result of getASTContext() which is all unreachable code.

This patch changes the return value to a reference to make it clear this can't be a nullptr
and deletes all the nullptr checks.

Added: 
    

Modified: 
    lldb/include/lldb/Symbol/ClangASTContext.h
    lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
    lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
    lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
    lldb/source/Plugins/Language/ObjC/NSArray.cpp
    lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
    lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
    lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
    lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
    lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
    lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
    lldb/source/Symbol/ClangASTContext.cpp
    lldb/source/Symbol/ClangASTImporter.cpp
    lldb/tools/lldb-test/lldb-test.cpp
    lldb/unittests/Expression/ClangExpressionDeclMapTest.cpp
    lldb/unittests/Symbol/TestClangASTContext.cpp
    lldb/unittests/Symbol/TestClangASTImporter.cpp
    lldb/unittests/TestingSupport/Symbol/ClangTestUtils.h

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Symbol/ClangASTContext.h b/lldb/include/lldb/Symbol/ClangASTContext.h
index e5dc77504afb..e0216cce3e10 100644
--- a/lldb/include/lldb/Symbol/ClangASTContext.h
+++ b/lldb/include/lldb/Symbol/ClangASTContext.h
@@ -100,7 +100,7 @@ class ClangASTContext : public TypeSystem {
     return llvm::dyn_cast<ClangASTContext>(&type_system_or_err.get());
   }
 
-  clang::ASTContext *getASTContext();
+  clang::ASTContext &getASTContext();
 
   clang::MangleContext *getMangleContext();
 
@@ -117,7 +117,7 @@ class ClangASTContext : public TypeSystem {
       llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> &ast_source_up);
 
   bool GetCompleteDecl(clang::Decl *decl) {
-    return ClangASTContext::GetCompleteDecl(getASTContext(), decl);
+    return ClangASTContext::GetCompleteDecl(&getASTContext(), decl);
   }
 
   static void DumpDeclHiearchy(clang::Decl *decl);
@@ -134,14 +134,14 @@ class ClangASTContext : public TypeSystem {
   void SetMetadata(const clang::Decl *object, ClangASTMetadata &meta_data);
   void SetMetadata(const clang::Type *object, ClangASTMetadata &meta_data);
   ClangASTMetadata *GetMetadata(const clang::Decl *object) {
-    return GetMetadata(getASTContext(), object);
+    return GetMetadata(&getASTContext(), object);
   }
 
   static ClangASTMetadata *GetMetadata(clang::ASTContext *ast,
                                        const clang::Decl *object);
 
   ClangASTMetadata *GetMetadata(const clang::Type *object) {
-    return GetMetadata(getASTContext(), object);
+    return GetMetadata(&getASTContext(), object);
   }
 
   static ClangASTMetadata *GetMetadata(clang::ASTContext *ast,
@@ -170,7 +170,7 @@ class ClangASTContext : public TypeSystem {
   static clang::DeclContext *GetTranslationUnitDecl(clang::ASTContext *ast);
 
   clang::DeclContext *GetTranslationUnitDecl() {
-    return GetTranslationUnitDecl(getASTContext());
+    return GetTranslationUnitDecl(&getASTContext());
   }
 
   static clang::Decl *CopyDecl(clang::ASTContext *dest_context,
@@ -193,27 +193,23 @@ class ClangASTContext : public TypeSystem {
     CompilerType compiler_type;
 
     if (type_name.GetLength()) {
-      clang::ASTContext *ast = getASTContext();
-      if (ast) {
-        if (!decl_context)
-          decl_context = ast->getTranslationUnitDecl();
-
-        clang::IdentifierInfo &myIdent =
-            ast->Idents.get(type_name.GetCString());
-        clang::DeclarationName myName =
-            ast->DeclarationNames.getIdentifier(&myIdent);
-
-        clang::DeclContext::lookup_result result =
-            decl_context->lookup(myName);
-
-        if (!result.empty()) {
-          clang::NamedDecl *named_decl = result[0];
-          if (const RecordDeclType *record_decl =
-                  llvm::dyn_cast<RecordDeclType>(named_decl))
-            compiler_type.SetCompilerType(
-                this, clang::QualType(record_decl->getTypeForDecl(), 0)
-                          .getAsOpaquePtr());
-        }
+      clang::ASTContext &ast = getASTContext();
+      if (!decl_context)
+        decl_context = ast.getTranslationUnitDecl();
+
+      clang::IdentifierInfo &myIdent = ast.Idents.get(type_name.GetCString());
+      clang::DeclarationName myName =
+          ast.DeclarationNames.getIdentifier(&myIdent);
+
+      clang::DeclContext::lookup_result result = decl_context->lookup(myName);
+
+      if (!result.empty()) {
+        clang::NamedDecl *named_decl = result[0];
+        if (const RecordDeclType *record_decl =
+                llvm::dyn_cast<RecordDeclType>(named_decl))
+          compiler_type.SetCompilerType(
+              this, clang::QualType(record_decl->getTypeForDecl(), 0)
+                        .getAsOpaquePtr());
       }
     }
 
@@ -355,14 +351,14 @@ class ClangASTContext : public TypeSystem {
                                   const CompilerType *args, unsigned num_args,
                                   bool is_variadic, unsigned type_quals) {
     return ClangASTContext::CreateFunctionType(
-        getASTContext(), result_type, args, num_args, is_variadic, type_quals);
+        &getASTContext(), result_type, args, num_args, is_variadic, type_quals);
   }
 
   CompilerType CreateFunctionType(const CompilerType &result_type,
                                   const CompilerType *args, unsigned num_args,
                                   bool is_variadic, unsigned type_quals,
                                   clang::CallingConv cc) {
-    return ClangASTContext::CreateFunctionType(getASTContext(), result_type,
+    return ClangASTContext::CreateFunctionType(&getASTContext(), result_type,
                                                args, num_args, is_variadic,
                                                type_quals, cc);
   }
@@ -396,7 +392,7 @@ class ClangASTContext : public TypeSystem {
                                             size_t bit_size, bool is_signed);
 
   CompilerType GetPointerSizedIntType(bool is_signed) {
-    return GetPointerSizedIntType(getASTContext(), is_signed);
+    return GetPointerSizedIntType(&getASTContext(), is_signed);
   }
 
   static CompilerType GetPointerSizedIntType(clang::ASTContext *ast,

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
index 6d6830c740d1..1caac9e11cbd 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
@@ -453,7 +453,7 @@ void ASTResultSynthesizer::CommitPersistentDecls() {
     ConstString name_cs(name.str().c_str());
 
     Decl *D_scratch = m_target.GetClangASTImporter()->DeportDecl(
-        ClangASTContext::GetScratch(m_target)->getASTContext(), decl);
+        &ClangASTContext::GetScratch(m_target)->getASTContext(), decl);
 
     if (!D_scratch) {
       Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index e044a4d33b42..ff86f9f818b2 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -57,7 +57,7 @@ ClangASTSource::ClangASTSource(const lldb::TargetSP &target,
 }
 
 void ClangASTSource::InstallASTContext(ClangASTContext &clang_ast_context) {
-  m_ast_context = clang_ast_context.getASTContext();
+  m_ast_context = &clang_ast_context.getASTContext();
   m_clang_ast_context = &clang_ast_context;
   m_file_manager = &m_ast_context->getSourceManager().getFileManager();
   m_ast_importer_sp->InstallMapCompleter(m_ast_context, *this);
@@ -80,14 +80,11 @@ ClangASTSource::~ClangASTSource() {
   if (!scratch_clang_ast_context)
     return;
 
-  clang::ASTContext *scratch_ast_context =
+  clang::ASTContext &scratch_ast_context =
       scratch_clang_ast_context->getASTContext();
 
-  if (!scratch_ast_context)
-    return;
-
-  if (m_ast_context != scratch_ast_context && m_ast_importer_sp)
-    m_ast_importer_sp->ForgetSource(scratch_ast_context, m_ast_context);
+  if (m_ast_context != &scratch_ast_context && m_ast_importer_sp)
+    m_ast_importer_sp->ForgetSource(&scratch_ast_context, m_ast_context);
 }
 
 void ClangASTSource::StartTranslationUnit(ASTConsumer *Consumer) {
@@ -1880,10 +1877,10 @@ clang::NamedDecl *NameSearchContext::AddVarDecl(const CompilerType &type) {
 
   IdentifierInfo *ii = m_decl_name.getAsIdentifierInfo();
 
-  clang::ASTContext *ast = lldb_ast->getASTContext();
+  clang::ASTContext &ast = lldb_ast->getASTContext();
 
   clang::NamedDecl *Decl = VarDecl::Create(
-      *ast, const_cast<DeclContext *>(m_decl_context), SourceLocation(),
+      ast, const_cast<DeclContext *>(m_decl_context), SourceLocation(),
       SourceLocation(), ii, ClangUtil::GetQualType(type), nullptr, SC_Static);
   m_decls.push_back(Decl);
 
@@ -1909,7 +1906,7 @@ clang::NamedDecl *NameSearchContext::AddFunDecl(const CompilerType &type,
 
   QualType qual_type(ClangUtil::GetQualType(type));
 
-  clang::ASTContext *ast = lldb_ast->getASTContext();
+  clang::ASTContext &ast = lldb_ast->getASTContext();
 
   const bool isInlineSpecified = false;
   const bool hasWrittenPrototype = true;
@@ -1919,7 +1916,7 @@ clang::NamedDecl *NameSearchContext::AddFunDecl(const CompilerType &type,
 
   if (extern_c) {
     context = LinkageSpecDecl::Create(
-        *ast, context, SourceLocation(), SourceLocation(),
+        ast, context, SourceLocation(), SourceLocation(),
         clang::LinkageSpecDecl::LanguageIDs::lang_c, false);
   }
 
@@ -1931,7 +1928,7 @@ clang::NamedDecl *NameSearchContext::AddFunDecl(const CompilerType &type,
           : m_decl_name;
 
   clang::FunctionDecl *func_decl = FunctionDecl::Create(
-      *ast, context, SourceLocation(), SourceLocation(), decl_name, qual_type,
+      ast, context, SourceLocation(), SourceLocation(), decl_name, qual_type,
       nullptr, SC_Extern, isInlineSpecified, hasWrittenPrototype,
       isConstexprSpecified ? CSK_constexpr : CSK_unspecified);
 
@@ -1952,7 +1949,7 @@ clang::NamedDecl *NameSearchContext::AddFunDecl(const CompilerType &type,
       QualType arg_qual_type(func_proto_type->getParamType(ArgIndex));
 
       parm_var_decls.push_back(
-          ParmVarDecl::Create(*ast, const_cast<DeclContext *>(context),
+          ParmVarDecl::Create(ast, const_cast<DeclContext *>(context),
                               SourceLocation(), SourceLocation(), nullptr,
                               arg_qual_type, nullptr, SC_Static, nullptr));
     }

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
index 232027668923..e9ba1bffd34e 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -179,7 +179,7 @@ TypeFromUser ClangExpressionDeclMap::DeportType(ClangASTContext &target,
                                                 TypeFromParser parser_type) {
   assert(&target == ClangASTContext::GetScratch(*m_target));
   assert((TypeSystem *)&source == parser_type.GetTypeSystem());
-  assert(source.getASTContext() == m_ast_context);
+  assert(&source.getASTContext() == m_ast_context);
 
   if (m_ast_importer_sp) {
     return TypeFromUser(m_ast_importer_sp->DeportType(target, parser_type));
@@ -741,16 +741,7 @@ clang::NamedDecl *ClangExpressionDeclMap::GetPersistentDecl(ConstString name) {
   if (!target)
     return nullptr;
 
-  ClangASTContext *scratch_clang_ast_context =
-      ClangASTContext::GetScratch(*target);
-
-  if (!scratch_clang_ast_context)
-    return nullptr;
-
-  ASTContext *scratch_ast_context = scratch_clang_ast_context->getASTContext();
-
-  if (!scratch_ast_context)
-    return nullptr;
+  ClangASTContext::GetScratch(*target);
 
   return m_parser_vars->m_persistent_vars->GetPersistentDecl(name);
 }
@@ -1528,15 +1519,6 @@ bool ClangExpressionDeclMap::GetVariableValue(VariableSP &var,
     return false;
   }
 
-  ASTContext *ast = clang_ast->getASTContext();
-
-  if (!ast) {
-    if (log)
-      log->PutCString(
-          "There is no AST context for the current execution context");
-    return false;
-  }
-
   DWARFExpression &var_location_expr = var->LocationExpression();
 
   Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();

diff  --git a/lldb/source/Plugins/Language/ObjC/NSArray.cpp b/lldb/source/Plugins/Language/ObjC/NSArray.cpp
index 3498c9dd23c6..64461fc2bc0f 100644
--- a/lldb/source/Plugins/Language/ObjC/NSArray.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSArray.cpp
@@ -466,7 +466,7 @@ lldb_private::formatters::NSArrayMSyntheticFrontEndBase::NSArrayMSyntheticFrontE
     if (clang_ast_context)
       m_id_type = CompilerType(
           clang_ast_context,
-          clang_ast_context->getASTContext()->ObjCBuiltinIdTy.getAsOpaquePtr());
+          clang_ast_context->getASTContext().ObjCBuiltinIdTy.getAsOpaquePtr());
     if (valobj_sp->GetProcessSP())
       m_ptr_size = valobj_sp->GetProcessSP()->GetAddressByteSize();
   }
@@ -614,7 +614,7 @@ lldb_private::formatters::GenericNSArrayISyntheticFrontEnd<D32, D64, Inline>::
       if (clang_ast_context)
         m_id_type = CompilerType(clang_ast_context,
                                  clang_ast_context->getASTContext()
-                                     ->ObjCBuiltinIdTy.getAsOpaquePtr());
+                                     .ObjCBuiltinIdTy.getAsOpaquePtr());
     }
   }
 }

diff  --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
index 6acd6a6df6b7..aca0b8fddcc5 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
@@ -132,7 +132,7 @@ class lldb_private::AppleObjCExternalASTSource
 
   void StartTranslationUnit(clang::ASTConsumer *Consumer) override {
     clang::TranslationUnitDecl *translation_unit_decl =
-        m_decl_vendor.m_ast_ctx.getASTContext()->getTranslationUnitDecl();
+        m_decl_vendor.m_ast_ctx.getASTContext().getTranslationUnitDecl();
     translation_unit_decl->setHasExternalVisibleStorage();
     translation_unit_decl->setHasExternalLexicalStorage();
   }
@@ -153,7 +153,7 @@ AppleObjCDeclVendor::AppleObjCDeclVendor(ObjCLanguageRuntime &runtime)
   m_external_source = new AppleObjCExternalASTSource(*this);
   llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> external_source_owning_ptr(
       m_external_source);
-  m_ast_ctx.getASTContext()->setExternalSource(external_source_owning_ptr);
+  m_ast_ctx.getASTContext().setExternalSource(external_source_owning_ptr);
 }
 
 clang::ObjCInterfaceDecl *
@@ -163,7 +163,7 @@ AppleObjCDeclVendor::GetDeclForISA(ObjCLanguageRuntime::ObjCISA isa) {
   if (iter != m_isa_to_interface.end())
     return iter->second;
 
-  clang::ASTContext *ast_ctx = m_ast_ctx.getASTContext();
+  clang::ASTContext &ast_ctx = m_ast_ctx.getASTContext();
 
   ObjCLanguageRuntime::ClassDescriptorSP descriptor =
       m_runtime.GetClassDescriptorFromISA(isa);
@@ -174,10 +174,10 @@ AppleObjCDeclVendor::GetDeclForISA(ObjCLanguageRuntime::ObjCISA isa) {
   ConstString name(descriptor->GetClassName());
 
   clang::IdentifierInfo &identifier_info =
-      ast_ctx->Idents.get(name.GetStringRef());
+      ast_ctx.Idents.get(name.GetStringRef());
 
   clang::ObjCInterfaceDecl *new_iface_decl = clang::ObjCInterfaceDecl::Create(
-      *ast_ctx, ast_ctx->getTranslationUnitDecl(), clang::SourceLocation(),
+      ast_ctx, ast_ctx.getTranslationUnitDecl(), clang::SourceLocation(),
       &identifier_info, nullptr, nullptr);
 
   ClangASTMetadata meta_data;
@@ -187,7 +187,7 @@ AppleObjCDeclVendor::GetDeclForISA(ObjCLanguageRuntime::ObjCISA isa) {
   new_iface_decl->setHasExternalVisibleStorage();
   new_iface_decl->setHasExternalLexicalStorage();
 
-  ast_ctx->getTranslationUnitDecl()->addDecl(new_iface_decl);
+  ast_ctx.getTranslationUnitDecl()->addDecl(new_iface_decl);
 
   m_isa_to_interface[isa] = new_iface_decl;
 
@@ -443,9 +443,9 @@ bool AppleObjCDeclVendor::FinishDecl(clang::ObjCInterfaceDecl *interface_decl) {
       return;
 
     FinishDecl(superclass_decl);
-    clang::ASTContext *context = m_ast_ctx.getASTContext();
-    interface_decl->setSuperClass(context->getTrivialTypeSourceInfo(
-        context->getObjCInterfaceType(superclass_decl)));
+    clang::ASTContext &context = m_ast_ctx.getASTContext();
+    interface_decl->setSuperClass(context.getTrivialTypeSourceInfo(
+        context.getObjCInterfaceType(superclass_decl)));
   };
 
   auto instance_method_func =
@@ -503,8 +503,8 @@ bool AppleObjCDeclVendor::FinishDecl(clang::ObjCInterfaceDecl *interface_decl) {
       clang::TypeSourceInfo *const type_source_info = nullptr;
       const bool is_synthesized = false;
       clang::ObjCIvarDecl *ivar_decl = clang::ObjCIvarDecl::Create(
-          *m_ast_ctx.getASTContext(), interface_decl, clang::SourceLocation(),
-          clang::SourceLocation(), &m_ast_ctx.getASTContext()->Idents.get(name),
+          m_ast_ctx.getASTContext(), interface_decl, clang::SourceLocation(),
+          clang::SourceLocation(), &m_ast_ctx.getASTContext().Idents.get(name),
           ClangUtil::GetQualType(ivar_type),
           type_source_info, // TypeSourceInfo *
           clang::ObjCIvarDecl::Public, nullptr, is_synthesized);
@@ -559,22 +559,22 @@ AppleObjCDeclVendor::FindDecls(ConstString name, bool append,
   do {
     // See if the type is already in our ASTContext.
 
-    clang::ASTContext *ast_ctx = m_ast_ctx.getASTContext();
+    clang::ASTContext &ast_ctx = m_ast_ctx.getASTContext();
 
     clang::IdentifierInfo &identifier_info =
-        ast_ctx->Idents.get(name.GetStringRef());
+        ast_ctx.Idents.get(name.GetStringRef());
     clang::DeclarationName decl_name =
-        ast_ctx->DeclarationNames.getIdentifier(&identifier_info);
+        ast_ctx.DeclarationNames.getIdentifier(&identifier_info);
 
     clang::DeclContext::lookup_result lookup_result =
-        ast_ctx->getTranslationUnitDecl()->lookup(decl_name);
+        ast_ctx.getTranslationUnitDecl()->lookup(decl_name);
 
     if (!lookup_result.empty()) {
       if (clang::ObjCInterfaceDecl *result_iface_decl =
               llvm::dyn_cast<clang::ObjCInterfaceDecl>(lookup_result[0])) {
         if (log) {
           clang::QualType result_iface_type =
-              ast_ctx->getObjCInterfaceType(result_iface_decl);
+              ast_ctx.getObjCInterfaceType(result_iface_decl);
 
           uint64_t isa_value = LLDB_INVALID_ADDRESS;
           ClangASTMetadata *metadata =
@@ -625,8 +625,7 @@ AppleObjCDeclVendor::FindDecls(ConstString name, bool append,
     }
 
     if (log) {
-      clang::QualType new_iface_type =
-          ast_ctx->getObjCInterfaceType(iface_decl);
+      clang::QualType new_iface_type = ast_ctx.getObjCInterfaceType(iface_decl);
 
       LLDB_LOG(log, "AOCTV::FT [{0}] Created {1} (isa 0x{2:x})", current_id,
                new_iface_type.getAsString(), (uint64_t)isa);

diff  --git a/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
index 87ae4c2c6c48..399bb120d7a3 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
@@ -315,10 +315,8 @@ ObjCLanguageRuntime::EncodingToType::RealizeType(const char *name,
 
 CompilerType ObjCLanguageRuntime::EncodingToType::RealizeType(
     ClangASTContext &ast_ctx, const char *name, bool for_expression) {
-  clang::ASTContext *clang_ast = ast_ctx.getASTContext();
-  if (!clang_ast)
-    return CompilerType();
-  return RealizeType(*clang_ast, name, for_expression);
+  clang::ASTContext &clang_ast = ast_ctx.getASTContext();
+  return RealizeType(clang_ast, name, for_expression);
 }
 
 ObjCLanguageRuntime::EncodingToType::~EncodingToType() {}

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 136027ee4d55..5a6ce7f926bf 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1909,7 +1909,7 @@ bool DWARFASTParserClang::ParseTemplateDIE(
         }
       }
 
-      clang::ASTContext *ast = m_ast.getASTContext();
+      clang::ASTContext &ast = m_ast.getASTContext();
       if (!clang_type)
         clang_type = m_ast.GetBasicType(eBasicTypeVoid);
 
@@ -1929,7 +1929,7 @@ bool DWARFASTParserClang::ParseTemplateDIE(
             return false;
           llvm::APInt apint(*size, uval64, is_signed);
           template_param_infos.args.push_back(
-              clang::TemplateArgument(*ast, llvm::APSInt(apint, !is_signed),
+              clang::TemplateArgument(ast, llvm::APSInt(apint, !is_signed),
                                       ClangUtil::GetQualType(clang_type)));
         } else {
           template_param_infos.args.push_back(
@@ -3570,18 +3570,20 @@ DWARFASTParserClang::ResolveNamespaceDIE(const DWARFDIE &die) {
         SymbolFileDWARF *dwarf = die.GetDWARF();
         if (namespace_name) {
           dwarf->GetObjectFile()->GetModule()->LogMessage(
-              log, "ASTContext => %p: 0x%8.8" PRIx64
-                   ": DW_TAG_namespace with DW_AT_name(\"%s\") => "
-                   "clang::NamespaceDecl *%p (original = %p)",
-              static_cast<void *>(m_ast.getASTContext()), die.GetID(),
+              log,
+              "ASTContext => %p: 0x%8.8" PRIx64
+              ": DW_TAG_namespace with DW_AT_name(\"%s\") => "
+              "clang::NamespaceDecl *%p (original = %p)",
+              static_cast<void *>(&m_ast.getASTContext()), die.GetID(),
               namespace_name, static_cast<void *>(namespace_decl),
               static_cast<void *>(namespace_decl->getOriginalNamespace()));
         } else {
           dwarf->GetObjectFile()->GetModule()->LogMessage(
-              log, "ASTContext => %p: 0x%8.8" PRIx64
-                   ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p "
-                   "(original = %p)",
-              static_cast<void *>(m_ast.getASTContext()), die.GetID(),
+              log,
+              "ASTContext => %p: 0x%8.8" PRIx64
+              ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p "
+              "(original = %p)",
+              static_cast<void *>(&m_ast.getASTContext()), die.GetID(),
               static_cast<void *>(namespace_decl),
               static_cast<void *>(namespace_decl->getOriginalNamespace()));
         }

diff  --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
index b58550beb04a..2b70f4602b84 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
@@ -655,7 +655,7 @@ bool PdbAstBuilder::CompleteTagDecl(clang::TagDecl &tag) {
 
   lldbassert(IsTagRecord(type_id, m_index.tpi()));
 
-  clang::QualType tag_qt = m_clang.getASTContext()->getTypeDeclType(&tag);
+  clang::QualType tag_qt = m_clang.getASTContext().getTypeDeclType(&tag);
   ClangASTContext::SetHasExternalStorage(tag_qt.getAsOpaquePtr(), false);
 
   TypeIndex tag_ti = type_id.index;
@@ -700,7 +700,7 @@ clang::QualType PdbAstBuilder::CreateSimpleType(TypeIndex ti) {
 
   if (ti.getSimpleMode() != SimpleTypeMode::Direct) {
     clang::QualType direct_type = GetOrCreateType(ti.makeDirect());
-    return m_clang.getASTContext()->getPointerType(direct_type);
+    return m_clang.getASTContext().getPointerType(direct_type);
   }
 
   if (ti.getSimpleKind() == SimpleTypeKind::NotTranslated)
@@ -725,19 +725,17 @@ clang::QualType PdbAstBuilder::CreatePointerType(const PointerRecord &pointer) {
     MemberPointerInfo mpi = pointer.getMemberInfo();
     clang::QualType class_type = GetOrCreateType(mpi.ContainingType);
 
-    return m_clang.getASTContext()->getMemberPointerType(
+    return m_clang.getASTContext().getMemberPointerType(
         pointee_type, class_type.getTypePtr());
   }
 
   clang::QualType pointer_type;
   if (pointer.getMode() == PointerMode::LValueReference)
-    pointer_type =
-        m_clang.getASTContext()->getLValueReferenceType(pointee_type);
+    pointer_type = m_clang.getASTContext().getLValueReferenceType(pointee_type);
   else if (pointer.getMode() == PointerMode::RValueReference)
-    pointer_type =
-        m_clang.getASTContext()->getRValueReferenceType(pointee_type);
+    pointer_type = m_clang.getASTContext().getRValueReferenceType(pointee_type);
   else
-    pointer_type = m_clang.getASTContext()->getPointerType(pointee_type);
+    pointer_type = m_clang.getASTContext().getPointerType(pointee_type);
 
   if ((pointer.getOptions() & PointerOptions::Const) != PointerOptions::None)
     pointer_type.addConst();

diff  --git a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
index 740b39016862..bbbd34151581 100644
--- a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
+++ b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
@@ -103,9 +103,7 @@ static CompilerType
 GetBuiltinTypeForPDBEncodingAndBitSize(ClangASTContext &clang_ast,
                                        const PDBSymbolTypeBuiltin &pdb_type,
                                        Encoding encoding, uint32_t width) {
-  auto *ast = clang_ast.getASTContext();
-  if (!ast)
-    return CompilerType();
+  clang::ASTContext &ast = clang_ast.getASTContext();
 
   switch (pdb_type.getBuiltinType()) {
   default:
@@ -119,32 +117,32 @@ GetBuiltinTypeForPDBEncodingAndBitSize(ClangASTContext &clang_ast,
   case PDB_BuiltinType::Bool:
     return clang_ast.GetBasicType(eBasicTypeBool);
   case PDB_BuiltinType::Long:
-    if (width == ast->getTypeSize(ast->LongTy))
-      return CompilerType(ClangASTContext::GetASTContext(ast),
-                          ast->LongTy.getAsOpaquePtr());
-    if (width == ast->getTypeSize(ast->LongLongTy))
-      return CompilerType(ClangASTContext::GetASTContext(ast),
-                          ast->LongLongTy.getAsOpaquePtr());
+    if (width == ast.getTypeSize(ast.LongTy))
+      return CompilerType(ClangASTContext::GetASTContext(&ast),
+                          ast.LongTy.getAsOpaquePtr());
+    if (width == ast.getTypeSize(ast.LongLongTy))
+      return CompilerType(ClangASTContext::GetASTContext(&ast),
+                          ast.LongLongTy.getAsOpaquePtr());
     break;
   case PDB_BuiltinType::ULong:
-    if (width == ast->getTypeSize(ast->UnsignedLongTy))
-      return CompilerType(ClangASTContext::GetASTContext(ast),
-                          ast->UnsignedLongTy.getAsOpaquePtr());
-    if (width == ast->getTypeSize(ast->UnsignedLongLongTy))
-      return CompilerType(ClangASTContext::GetASTContext(ast),
-                          ast->UnsignedLongLongTy.getAsOpaquePtr());
+    if (width == ast.getTypeSize(ast.UnsignedLongTy))
+      return CompilerType(ClangASTContext::GetASTContext(&ast),
+                          ast.UnsignedLongTy.getAsOpaquePtr());
+    if (width == ast.getTypeSize(ast.UnsignedLongLongTy))
+      return CompilerType(ClangASTContext::GetASTContext(&ast),
+                          ast.UnsignedLongLongTy.getAsOpaquePtr());
     break;
   case PDB_BuiltinType::WCharT:
-    if (width == ast->getTypeSize(ast->WCharTy))
-      return CompilerType(ClangASTContext::GetASTContext(ast),
-                          ast->WCharTy.getAsOpaquePtr());
+    if (width == ast.getTypeSize(ast.WCharTy))
+      return CompilerType(ClangASTContext::GetASTContext(&ast),
+                          ast.WCharTy.getAsOpaquePtr());
     break;
   case PDB_BuiltinType::Char16:
-    return CompilerType(ClangASTContext::GetASTContext(ast),
-                        ast->Char16Ty.getAsOpaquePtr());
+    return CompilerType(ClangASTContext::GetASTContext(&ast),
+                        ast.Char16Ty.getAsOpaquePtr());
   case PDB_BuiltinType::Char32:
-    return CompilerType(ClangASTContext::GetASTContext(ast),
-                        ast->Char32Ty.getAsOpaquePtr());
+    return CompilerType(ClangASTContext::GetASTContext(&ast),
+                        ast.Char32Ty.getAsOpaquePtr());
   case PDB_BuiltinType::Float:
     // Note: types `long double` and `double` have same bit size in MSVC and
     // there is no information in the PDB to distinguish them. So when falling
@@ -428,7 +426,7 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
       m_uid_to_decl[type.getSymIndexId()] = record_decl;
 
       auto inheritance_attr = clang::MSInheritanceAttr::CreateImplicit(
-          *m_ast.getASTContext(), GetMSInheritance(*udt));
+          m_ast.getASTContext(), GetMSInheritance(*udt));
       record_decl->addAttr(inheritance_attr);
 
       ClangASTContext::StartTagDeclarationDefinition(clang_type);
@@ -900,7 +898,7 @@ PDBASTParser::GetDeclForSymbol(const llvm::pdb::PDBSymbol &symbol) {
 
     // Check if the current context already contains the symbol with the name.
     clang::Decl *decl =
-        GetDeclFromContextByName(*m_ast.getASTContext(), *decl_context, name);
+        GetDeclFromContextByName(m_ast.getASTContext(), *decl_context, name);
     if (!decl) {
       auto type = symbol_file->ResolveTypeUID(data->getTypeId());
       if (!type)
@@ -1160,7 +1158,7 @@ bool PDBASTParser::AddEnumValue(CompilerType enum_type,
   }
   CompilerType underlying_type =
       m_ast.GetEnumerationIntegerType(enum_type.GetOpaqueQualType());
-  uint32_t byte_size = m_ast.getASTContext()->getTypeSize(
+  uint32_t byte_size = m_ast.getASTContext().getTypeSize(
       ClangUtil::GetQualType(underlying_type));
   auto enum_constant_decl = m_ast.AddEnumerationValueToEnumerationType(
       enum_type, decl, name.c_str(), raw_value, byte_size * 8);

diff  --git a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
index 08e3737865ab..69a4470c2580 100644
--- a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
+++ b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
@@ -413,8 +413,7 @@ void SystemRuntimeMacOSX::ReadLibdispatchTSDIndexes() {
 
     ClangASTContext *ast_ctx =
         ClangASTContext::GetScratch(m_process->GetTarget());
-    if (ast_ctx->getASTContext() &&
-        m_dispatch_tsd_indexes_addr != LLDB_INVALID_ADDRESS) {
+    if (m_dispatch_tsd_indexes_addr != LLDB_INVALID_ADDRESS) {
       CompilerType uint16 =
           ast_ctx->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 16);
       CompilerType dispatch_tsd_indexes_s = ast_ctx->CreateRecordType(

diff  --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp
index 65b95089b931..66a682c34937 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -649,16 +649,14 @@ void ClangASTContext::SetTargetTriple(llvm::StringRef target_triple) {
 
 void ClangASTContext::SetExternalSource(
     llvm::IntrusiveRefCntPtr<ExternalASTSource> &ast_source_up) {
-  ASTContext *ast = getASTContext();
-  if (ast) {
-    ast->setExternalSource(ast_source_up);
-    ast->getTranslationUnitDecl()->setHasExternalLexicalStorage(true);
-  }
+  ASTContext &ast = getASTContext();
+  ast.setExternalSource(ast_source_up);
+  ast.getTranslationUnitDecl()->setHasExternalLexicalStorage(true);
 }
 
-ASTContext *ClangASTContext::getASTContext() {
+ASTContext &ClangASTContext::getASTContext() {
   assert(m_ast_up);
-  return m_ast_up.get();
+  return *m_ast_up;
 }
 
 class NullDiagnosticConsumer : public DiagnosticConsumer {
@@ -745,7 +743,7 @@ ClangASTContext *ClangASTContext::GetASTContext(clang::ASTContext *ast) {
 
 clang::MangleContext *ClangASTContext::getMangleContext() {
   if (m_mangle_ctx_up == nullptr)
-    m_mangle_ctx_up.reset(getASTContext()->createMangleContext());
+    m_mangle_ctx_up.reset(getASTContext().createMangleContext());
   return m_mangle_ctx_up.get();
 }
 
@@ -762,77 +760,75 @@ TargetInfo *ClangASTContext::getTargetInfo() {
   // target_triple should be something like "x86_64-apple-macosx"
   if (m_target_info_up == nullptr && !m_target_triple.empty())
     m_target_info_up.reset(TargetInfo::CreateTargetInfo(
-        getASTContext()->getDiagnostics(), getTargetOptions()));
+        getASTContext().getDiagnostics(), getTargetOptions()));
   return m_target_info_up.get();
 }
 
 #pragma mark Basic Types
 
 static inline bool QualTypeMatchesBitSize(const uint64_t bit_size,
-                                          ASTContext *ast, QualType qual_type) {
-  uint64_t qual_type_bit_size = ast->getTypeSize(qual_type);
+                                          ASTContext &ast, QualType qual_type) {
+  uint64_t qual_type_bit_size = ast.getTypeSize(qual_type);
   return qual_type_bit_size == bit_size;
 }
 
 CompilerType
 ClangASTContext::GetBuiltinTypeForEncodingAndBitSize(Encoding encoding,
                                                      size_t bit_size) {
-  ASTContext *ast = this->getASTContext();
-  if (!ast)
-    return CompilerType();
+  ASTContext &ast = getASTContext();
   switch (encoding) {
   case eEncodingInvalid:
-    if (QualTypeMatchesBitSize(bit_size, ast, ast->VoidPtrTy))
-      return CompilerType(this, ast->VoidPtrTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.VoidPtrTy))
+      return CompilerType(this, ast.VoidPtrTy.getAsOpaquePtr());
     break;
 
   case eEncodingUint:
-    if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy))
-      return CompilerType(this, ast->UnsignedCharTy.getAsOpaquePtr());
-    if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy))
-      return CompilerType(this, ast->UnsignedShortTy.getAsOpaquePtr());
-    if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedIntTy))
-      return CompilerType(this, ast->UnsignedIntTy.getAsOpaquePtr());
-    if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongTy))
-      return CompilerType(this, ast->UnsignedLongTy.getAsOpaquePtr());
-    if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongLongTy))
-      return CompilerType(this, ast->UnsignedLongLongTy.getAsOpaquePtr());
-    if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedInt128Ty))
-      return CompilerType(this, ast->UnsignedInt128Ty.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedCharTy))
+      return CompilerType(this, ast.UnsignedCharTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedShortTy))
+      return CompilerType(this, ast.UnsignedShortTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedIntTy))
+      return CompilerType(this, ast.UnsignedIntTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongTy))
+      return CompilerType(this, ast.UnsignedLongTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongLongTy))
+      return CompilerType(this, ast.UnsignedLongLongTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedInt128Ty))
+      return CompilerType(this, ast.UnsignedInt128Ty.getAsOpaquePtr());
     break;
 
   case eEncodingSint:
-    if (QualTypeMatchesBitSize(bit_size, ast, ast->SignedCharTy))
-      return CompilerType(this, ast->SignedCharTy.getAsOpaquePtr());
-    if (QualTypeMatchesBitSize(bit_size, ast, ast->ShortTy))
-      return CompilerType(this, ast->ShortTy.getAsOpaquePtr());
-    if (QualTypeMatchesBitSize(bit_size, ast, ast->IntTy))
-      return CompilerType(this, ast->IntTy.getAsOpaquePtr());
-    if (QualTypeMatchesBitSize(bit_size, ast, ast->LongTy))
-      return CompilerType(this, ast->LongTy.getAsOpaquePtr());
-    if (QualTypeMatchesBitSize(bit_size, ast, ast->LongLongTy))
-      return CompilerType(this, ast->LongLongTy.getAsOpaquePtr());
-    if (QualTypeMatchesBitSize(bit_size, ast, ast->Int128Ty))
-      return CompilerType(this, ast->Int128Ty.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.SignedCharTy))
+      return CompilerType(this, ast.SignedCharTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.ShortTy))
+      return CompilerType(this, ast.ShortTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.IntTy))
+      return CompilerType(this, ast.IntTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.LongTy))
+      return CompilerType(this, ast.LongTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.LongLongTy))
+      return CompilerType(this, ast.LongLongTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.Int128Ty))
+      return CompilerType(this, ast.Int128Ty.getAsOpaquePtr());
     break;
 
   case eEncodingIEEE754:
-    if (QualTypeMatchesBitSize(bit_size, ast, ast->FloatTy))
-      return CompilerType(this, ast->FloatTy.getAsOpaquePtr());
-    if (QualTypeMatchesBitSize(bit_size, ast, ast->DoubleTy))
-      return CompilerType(this, ast->DoubleTy.getAsOpaquePtr());
-    if (QualTypeMatchesBitSize(bit_size, ast, ast->LongDoubleTy))
-      return CompilerType(this, ast->LongDoubleTy.getAsOpaquePtr());
-    if (QualTypeMatchesBitSize(bit_size, ast, ast->HalfTy))
-      return CompilerType(this, ast->HalfTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.FloatTy))
+      return CompilerType(this, ast.FloatTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.DoubleTy))
+      return CompilerType(this, ast.DoubleTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.LongDoubleTy))
+      return CompilerType(this, ast.LongDoubleTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.HalfTy))
+      return CompilerType(this, ast.HalfTy.getAsOpaquePtr());
     break;
 
   case eEncodingVector:
     // Sanity check that bit_size is a multiple of 8's.
     if (bit_size && !(bit_size & 0x7u))
-      return CompilerType(
-          this, ast->getExtVectorType(ast->UnsignedCharTy, bit_size / 8)
-                    .getAsOpaquePtr());
+      return CompilerType(this,
+                          ast.getExtVectorType(ast.UnsignedCharTy, bit_size / 8)
+                              .getAsOpaquePtr());
     break;
   }
 
@@ -915,223 +911,221 @@ uint32_t ClangASTContext::GetPointerByteSize() {
 }
 
 CompilerType ClangASTContext::GetBasicType(lldb::BasicType basic_type) {
-  clang::ASTContext *ast = getASTContext();
+  clang::ASTContext &ast = getASTContext();
 
   lldb::opaque_compiler_type_t clang_type =
-      GetOpaqueCompilerType(ast, basic_type);
+      GetOpaqueCompilerType(&ast, basic_type);
 
   if (clang_type)
-    return CompilerType(GetASTContext(ast), clang_type);
+    return CompilerType(GetASTContext(&ast), clang_type);
   return CompilerType();
 }
 
 CompilerType ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize(
     const char *type_name, uint32_t dw_ate, uint32_t bit_size) {
-  ASTContext *ast = getASTContext();
+  ASTContext &ast = getASTContext();
 
 #define streq(a, b) strcmp(a, b) == 0
-  assert(ast != nullptr);
-  if (ast) {
-    switch (dw_ate) {
-    default:
-      break;
 
-    case DW_ATE_address:
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->VoidPtrTy))
-        return CompilerType(this, ast->VoidPtrTy.getAsOpaquePtr());
-      break;
+  switch (dw_ate) {
+  default:
+    break;
 
-    case DW_ATE_boolean:
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->BoolTy))
-        return CompilerType(this, ast->BoolTy.getAsOpaquePtr());
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy))
-        return CompilerType(this, ast->UnsignedCharTy.getAsOpaquePtr());
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy))
-        return CompilerType(this, ast->UnsignedShortTy.getAsOpaquePtr());
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedIntTy))
-        return CompilerType(this, ast->UnsignedIntTy.getAsOpaquePtr());
-      break;
+  case DW_ATE_address:
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.VoidPtrTy))
+      return CompilerType(this, ast.VoidPtrTy.getAsOpaquePtr());
+    break;
 
-    case DW_ATE_lo_user:
-      // This has been seen to mean DW_AT_complex_integer
-      if (type_name) {
-        if (::strstr(type_name, "complex")) {
-          CompilerType complex_int_clang_type =
-              GetBuiltinTypeForDWARFEncodingAndBitSize("int", DW_ATE_signed,
-                                                       bit_size / 2);
-          return CompilerType(
-              this, ast->getComplexType(
-                           ClangUtil::GetQualType(complex_int_clang_type))
-                        .getAsOpaquePtr());
-        }
-      }
-      break;
+  case DW_ATE_boolean:
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.BoolTy))
+      return CompilerType(this, ast.BoolTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedCharTy))
+      return CompilerType(this, ast.UnsignedCharTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedShortTy))
+      return CompilerType(this, ast.UnsignedShortTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedIntTy))
+      return CompilerType(this, ast.UnsignedIntTy.getAsOpaquePtr());
+    break;
 
-    case DW_ATE_complex_float:
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->FloatComplexTy))
-        return CompilerType(this, ast->FloatComplexTy.getAsOpaquePtr());
-      else if (QualTypeMatchesBitSize(bit_size, ast, ast->DoubleComplexTy))
-        return CompilerType(this, ast->DoubleComplexTy.getAsOpaquePtr());
-      else if (QualTypeMatchesBitSize(bit_size, ast, ast->LongDoubleComplexTy))
-        return CompilerType(this, ast->LongDoubleComplexTy.getAsOpaquePtr());
-      else {
-        CompilerType complex_float_clang_type =
-            GetBuiltinTypeForDWARFEncodingAndBitSize("float", DW_ATE_float,
+  case DW_ATE_lo_user:
+    // This has been seen to mean DW_AT_complex_integer
+    if (type_name) {
+      if (::strstr(type_name, "complex")) {
+        CompilerType complex_int_clang_type =
+            GetBuiltinTypeForDWARFEncodingAndBitSize("int", DW_ATE_signed,
                                                      bit_size / 2);
         return CompilerType(
-            this, ast->getComplexType(
-                         ClangUtil::GetQualType(complex_float_clang_type))
-                      .getAsOpaquePtr());
+            this,
+            ast.getComplexType(ClangUtil::GetQualType(complex_int_clang_type))
+                .getAsOpaquePtr());
       }
-      break;
+    }
+    break;
 
-    case DW_ATE_float:
-      if (streq(type_name, "float") &&
-          QualTypeMatchesBitSize(bit_size, ast, ast->FloatTy))
-        return CompilerType(this, ast->FloatTy.getAsOpaquePtr());
-      if (streq(type_name, "double") &&
-          QualTypeMatchesBitSize(bit_size, ast, ast->DoubleTy))
-        return CompilerType(this, ast->DoubleTy.getAsOpaquePtr());
-      if (streq(type_name, "long double") &&
-          QualTypeMatchesBitSize(bit_size, ast, ast->LongDoubleTy))
-        return CompilerType(this, ast->LongDoubleTy.getAsOpaquePtr());
-      // Fall back to not requiring a name match
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->FloatTy))
-        return CompilerType(this, ast->FloatTy.getAsOpaquePtr());
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->DoubleTy))
-        return CompilerType(this, ast->DoubleTy.getAsOpaquePtr());
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->LongDoubleTy))
-        return CompilerType(this, ast->LongDoubleTy.getAsOpaquePtr());
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->HalfTy))
-        return CompilerType(this, ast->HalfTy.getAsOpaquePtr());
-      break;
+  case DW_ATE_complex_float:
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.FloatComplexTy))
+      return CompilerType(this, ast.FloatComplexTy.getAsOpaquePtr());
+    else if (QualTypeMatchesBitSize(bit_size, ast, ast.DoubleComplexTy))
+      return CompilerType(this, ast.DoubleComplexTy.getAsOpaquePtr());
+    else if (QualTypeMatchesBitSize(bit_size, ast, ast.LongDoubleComplexTy))
+      return CompilerType(this, ast.LongDoubleComplexTy.getAsOpaquePtr());
+    else {
+      CompilerType complex_float_clang_type =
+          GetBuiltinTypeForDWARFEncodingAndBitSize("float", DW_ATE_float,
+                                                   bit_size / 2);
+      return CompilerType(
+          this,
+          ast.getComplexType(ClangUtil::GetQualType(complex_float_clang_type))
+              .getAsOpaquePtr());
+    }
+    break;
 
-    case DW_ATE_signed:
-      if (type_name) {
-        if (streq(type_name, "wchar_t") &&
-            QualTypeMatchesBitSize(bit_size, ast, ast->WCharTy) &&
-            (getTargetInfo() &&
-             TargetInfo::isTypeSigned(getTargetInfo()->getWCharType())))
-          return CompilerType(this, ast->WCharTy.getAsOpaquePtr());
-        if (streq(type_name, "void") &&
-            QualTypeMatchesBitSize(bit_size, ast, ast->VoidTy))
-          return CompilerType(this, ast->VoidTy.getAsOpaquePtr());
-        if (strstr(type_name, "long long") &&
-            QualTypeMatchesBitSize(bit_size, ast, ast->LongLongTy))
-          return CompilerType(this, ast->LongLongTy.getAsOpaquePtr());
-        if (strstr(type_name, "long") &&
-            QualTypeMatchesBitSize(bit_size, ast, ast->LongTy))
-          return CompilerType(this, ast->LongTy.getAsOpaquePtr());
-        if (strstr(type_name, "short") &&
-            QualTypeMatchesBitSize(bit_size, ast, ast->ShortTy))
-          return CompilerType(this, ast->ShortTy.getAsOpaquePtr());
-        if (strstr(type_name, "char")) {
-          if (QualTypeMatchesBitSize(bit_size, ast, ast->CharTy))
-            return CompilerType(this, ast->CharTy.getAsOpaquePtr());
-          if (QualTypeMatchesBitSize(bit_size, ast, ast->SignedCharTy))
-            return CompilerType(this, ast->SignedCharTy.getAsOpaquePtr());
-        }
-        if (strstr(type_name, "int")) {
-          if (QualTypeMatchesBitSize(bit_size, ast, ast->IntTy))
-            return CompilerType(this, ast->IntTy.getAsOpaquePtr());
-          if (QualTypeMatchesBitSize(bit_size, ast, ast->Int128Ty))
-            return CompilerType(this, ast->Int128Ty.getAsOpaquePtr());
-        }
-      }
-      // We weren't able to match up a type name, just search by size
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->CharTy))
-        return CompilerType(this, ast->CharTy.getAsOpaquePtr());
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->ShortTy))
-        return CompilerType(this, ast->ShortTy.getAsOpaquePtr());
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->IntTy))
-        return CompilerType(this, ast->IntTy.getAsOpaquePtr());
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->LongTy))
-        return CompilerType(this, ast->LongTy.getAsOpaquePtr());
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->LongLongTy))
-        return CompilerType(this, ast->LongLongTy.getAsOpaquePtr());
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->Int128Ty))
-        return CompilerType(this, ast->Int128Ty.getAsOpaquePtr());
-      break;
+  case DW_ATE_float:
+    if (streq(type_name, "float") &&
+        QualTypeMatchesBitSize(bit_size, ast, ast.FloatTy))
+      return CompilerType(this, ast.FloatTy.getAsOpaquePtr());
+    if (streq(type_name, "double") &&
+        QualTypeMatchesBitSize(bit_size, ast, ast.DoubleTy))
+      return CompilerType(this, ast.DoubleTy.getAsOpaquePtr());
+    if (streq(type_name, "long double") &&
+        QualTypeMatchesBitSize(bit_size, ast, ast.LongDoubleTy))
+      return CompilerType(this, ast.LongDoubleTy.getAsOpaquePtr());
+    // Fall back to not requiring a name match
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.FloatTy))
+      return CompilerType(this, ast.FloatTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.DoubleTy))
+      return CompilerType(this, ast.DoubleTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.LongDoubleTy))
+      return CompilerType(this, ast.LongDoubleTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.HalfTy))
+      return CompilerType(this, ast.HalfTy.getAsOpaquePtr());
+    break;
 
-    case DW_ATE_signed_char:
-      if (ast->getLangOpts().CharIsSigned && type_name &&
-          streq(type_name, "char")) {
-        if (QualTypeMatchesBitSize(bit_size, ast, ast->CharTy))
-          return CompilerType(this, ast->CharTy.getAsOpaquePtr());
+  case DW_ATE_signed:
+    if (type_name) {
+      if (streq(type_name, "wchar_t") &&
+          QualTypeMatchesBitSize(bit_size, ast, ast.WCharTy) &&
+          (getTargetInfo() &&
+           TargetInfo::isTypeSigned(getTargetInfo()->getWCharType())))
+        return CompilerType(this, ast.WCharTy.getAsOpaquePtr());
+      if (streq(type_name, "void") &&
+          QualTypeMatchesBitSize(bit_size, ast, ast.VoidTy))
+        return CompilerType(this, ast.VoidTy.getAsOpaquePtr());
+      if (strstr(type_name, "long long") &&
+          QualTypeMatchesBitSize(bit_size, ast, ast.LongLongTy))
+        return CompilerType(this, ast.LongLongTy.getAsOpaquePtr());
+      if (strstr(type_name, "long") &&
+          QualTypeMatchesBitSize(bit_size, ast, ast.LongTy))
+        return CompilerType(this, ast.LongTy.getAsOpaquePtr());
+      if (strstr(type_name, "short") &&
+          QualTypeMatchesBitSize(bit_size, ast, ast.ShortTy))
+        return CompilerType(this, ast.ShortTy.getAsOpaquePtr());
+      if (strstr(type_name, "char")) {
+        if (QualTypeMatchesBitSize(bit_size, ast, ast.CharTy))
+          return CompilerType(this, ast.CharTy.getAsOpaquePtr());
+        if (QualTypeMatchesBitSize(bit_size, ast, ast.SignedCharTy))
+          return CompilerType(this, ast.SignedCharTy.getAsOpaquePtr());
       }
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->SignedCharTy))
-        return CompilerType(this, ast->SignedCharTy.getAsOpaquePtr());
-      break;
+      if (strstr(type_name, "int")) {
+        if (QualTypeMatchesBitSize(bit_size, ast, ast.IntTy))
+          return CompilerType(this, ast.IntTy.getAsOpaquePtr());
+        if (QualTypeMatchesBitSize(bit_size, ast, ast.Int128Ty))
+          return CompilerType(this, ast.Int128Ty.getAsOpaquePtr());
+      }
+    }
+    // We weren't able to match up a type name, just search by size
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.CharTy))
+      return CompilerType(this, ast.CharTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.ShortTy))
+      return CompilerType(this, ast.ShortTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.IntTy))
+      return CompilerType(this, ast.IntTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.LongTy))
+      return CompilerType(this, ast.LongTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.LongLongTy))
+      return CompilerType(this, ast.LongLongTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.Int128Ty))
+      return CompilerType(this, ast.Int128Ty.getAsOpaquePtr());
+    break;
 
-    case DW_ATE_unsigned:
-      if (type_name) {
-        if (streq(type_name, "wchar_t")) {
-          if (QualTypeMatchesBitSize(bit_size, ast, ast->WCharTy)) {
-            if (!(getTargetInfo() &&
-                  TargetInfo::isTypeSigned(getTargetInfo()->getWCharType())))
-              return CompilerType(this, ast->WCharTy.getAsOpaquePtr());
-          }
-        }
-        if (strstr(type_name, "long long")) {
-          if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongLongTy))
-            return CompilerType(this, ast->UnsignedLongLongTy.getAsOpaquePtr());
-        } else if (strstr(type_name, "long")) {
-          if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongTy))
-            return CompilerType(this, ast->UnsignedLongTy.getAsOpaquePtr());
-        } else if (strstr(type_name, "short")) {
-          if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy))
-            return CompilerType(this, ast->UnsignedShortTy.getAsOpaquePtr());
-        } else if (strstr(type_name, "char")) {
-          if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy))
-            return CompilerType(this, ast->UnsignedCharTy.getAsOpaquePtr());
-        } else if (strstr(type_name, "int")) {
-          if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedIntTy))
-            return CompilerType(this, ast->UnsignedIntTy.getAsOpaquePtr());
-          if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedInt128Ty))
-            return CompilerType(this, ast->UnsignedInt128Ty.getAsOpaquePtr());
+  case DW_ATE_signed_char:
+    if (ast.getLangOpts().CharIsSigned && type_name &&
+        streq(type_name, "char")) {
+      if (QualTypeMatchesBitSize(bit_size, ast, ast.CharTy))
+        return CompilerType(this, ast.CharTy.getAsOpaquePtr());
+    }
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.SignedCharTy))
+      return CompilerType(this, ast.SignedCharTy.getAsOpaquePtr());
+    break;
+
+  case DW_ATE_unsigned:
+    if (type_name) {
+      if (streq(type_name, "wchar_t")) {
+        if (QualTypeMatchesBitSize(bit_size, ast, ast.WCharTy)) {
+          if (!(getTargetInfo() &&
+                TargetInfo::isTypeSigned(getTargetInfo()->getWCharType())))
+            return CompilerType(this, ast.WCharTy.getAsOpaquePtr());
         }
       }
-      // We weren't able to match up a type name, just search by size
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy))
-        return CompilerType(this, ast->UnsignedCharTy.getAsOpaquePtr());
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy))
-        return CompilerType(this, ast->UnsignedShortTy.getAsOpaquePtr());
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedIntTy))
-        return CompilerType(this, ast->UnsignedIntTy.getAsOpaquePtr());
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongTy))
-        return CompilerType(this, ast->UnsignedLongTy.getAsOpaquePtr());
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongLongTy))
-        return CompilerType(this, ast->UnsignedLongLongTy.getAsOpaquePtr());
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedInt128Ty))
-        return CompilerType(this, ast->UnsignedInt128Ty.getAsOpaquePtr());
-      break;
-
-    case DW_ATE_unsigned_char:
-      if (!ast->getLangOpts().CharIsSigned && type_name &&
-          streq(type_name, "char")) {
-        if (QualTypeMatchesBitSize(bit_size, ast, ast->CharTy))
-          return CompilerType(this, ast->CharTy.getAsOpaquePtr());
+      if (strstr(type_name, "long long")) {
+        if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongLongTy))
+          return CompilerType(this, ast.UnsignedLongLongTy.getAsOpaquePtr());
+      } else if (strstr(type_name, "long")) {
+        if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongTy))
+          return CompilerType(this, ast.UnsignedLongTy.getAsOpaquePtr());
+      } else if (strstr(type_name, "short")) {
+        if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedShortTy))
+          return CompilerType(this, ast.UnsignedShortTy.getAsOpaquePtr());
+      } else if (strstr(type_name, "char")) {
+        if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedCharTy))
+          return CompilerType(this, ast.UnsignedCharTy.getAsOpaquePtr());
+      } else if (strstr(type_name, "int")) {
+        if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedIntTy))
+          return CompilerType(this, ast.UnsignedIntTy.getAsOpaquePtr());
+        if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedInt128Ty))
+          return CompilerType(this, ast.UnsignedInt128Ty.getAsOpaquePtr());
       }
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy))
-        return CompilerType(this, ast->UnsignedCharTy.getAsOpaquePtr());
-      if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy))
-        return CompilerType(this, ast->UnsignedShortTy.getAsOpaquePtr());
-      break;
+    }
+    // We weren't able to match up a type name, just search by size
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedCharTy))
+      return CompilerType(this, ast.UnsignedCharTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedShortTy))
+      return CompilerType(this, ast.UnsignedShortTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedIntTy))
+      return CompilerType(this, ast.UnsignedIntTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongTy))
+      return CompilerType(this, ast.UnsignedLongTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedLongLongTy))
+      return CompilerType(this, ast.UnsignedLongLongTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedInt128Ty))
+      return CompilerType(this, ast.UnsignedInt128Ty.getAsOpaquePtr());
+    break;
 
-    case DW_ATE_imaginary_float:
-      break;
+  case DW_ATE_unsigned_char:
+    if (!ast.getLangOpts().CharIsSigned && type_name &&
+        streq(type_name, "char")) {
+      if (QualTypeMatchesBitSize(bit_size, ast, ast.CharTy))
+        return CompilerType(this, ast.CharTy.getAsOpaquePtr());
+    }
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedCharTy))
+      return CompilerType(this, ast.UnsignedCharTy.getAsOpaquePtr());
+    if (QualTypeMatchesBitSize(bit_size, ast, ast.UnsignedShortTy))
+      return CompilerType(this, ast.UnsignedShortTy.getAsOpaquePtr());
+    break;
 
-    case DW_ATE_UTF:
-      if (type_name) {
-        if (streq(type_name, "char16_t"))
-          return CompilerType(this, ast->Char16Ty.getAsOpaquePtr());
-        if (streq(type_name, "char32_t"))
-          return CompilerType(this, ast->Char32Ty.getAsOpaquePtr());
-        if (streq(type_name, "char8_t"))
-          return CompilerType(this, ast->Char8Ty.getAsOpaquePtr());
-      }
-      break;
+  case DW_ATE_imaginary_float:
+    break;
+
+  case DW_ATE_UTF:
+    if (type_name) {
+      if (streq(type_name, "char16_t"))
+        return CompilerType(this, ast.Char16Ty.getAsOpaquePtr());
+      if (streq(type_name, "char32_t"))
+        return CompilerType(this, ast.Char32Ty.getAsOpaquePtr());
+      if (streq(type_name, "char8_t"))
+        return CompilerType(this, ast.Char8Ty.getAsOpaquePtr());
     }
+    break;
   }
   // This assert should fire for anything that we don't catch above so we know
   // to fix any issues we run into.
@@ -1150,13 +1144,13 @@ CompilerType ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize(
 }
 
 CompilerType ClangASTContext::GetCStringType(bool is_const) {
-  ASTContext *ast = getASTContext();
-  QualType char_type(ast->CharTy);
+  ASTContext &ast = getASTContext();
+  QualType char_type(ast.CharTy);
 
   if (is_const)
     char_type.addConst();
 
-  return CompilerType(this, ast->getPointerType(char_type).getAsOpaquePtr());
+  return CompilerType(this, ast.getPointerType(char_type).getAsOpaquePtr());
 }
 
 clang::DeclContext *
@@ -1198,7 +1192,7 @@ bool ClangASTContext::AreTypesSame(CompilerType type1, CompilerType type2,
     type2_qual = type2_qual.getUnqualifiedType();
   }
 
-  return ast->getASTContext()->hasSameType(type1_qual, type2_qual);
+  return ast->getASTContext().hasSameType(type1_qual, type2_qual);
 }
 
 CompilerType ClangASTContext::GetTypeForDecl(void *opaque_decl) {
@@ -1250,11 +1244,10 @@ CompilerType ClangASTContext::CreateRecordType(DeclContext *decl_ctx,
                                                LanguageType language,
                                                ClangASTMetadata *metadata,
                                                bool exports_symbols) {
-  ASTContext *ast = getASTContext();
-  assert(ast != nullptr);
+  ASTContext &ast = getASTContext();
 
   if (decl_ctx == nullptr)
-    decl_ctx = ast->getTranslationUnitDecl();
+    decl_ctx = ast.getTranslationUnitDecl();
 
   if (language == eLanguageTypeObjC ||
       language == eLanguageTypeObjC_plus_plus) {
@@ -1272,8 +1265,8 @@ CompilerType ClangASTContext::CreateRecordType(DeclContext *decl_ctx,
   bool has_name = !name.empty();
 
   CXXRecordDecl *decl = CXXRecordDecl::Create(
-      *ast, (TagDecl::TagKind)kind, decl_ctx, SourceLocation(),
-      SourceLocation(), has_name ?  &ast->Idents.get(name) : nullptr);
+      ast, (TagDecl::TagKind)kind, decl_ctx, SourceLocation(), SourceLocation(),
+      has_name ? &ast.Idents.get(name) : nullptr);
 
   if (!has_name) {
     // In C++ a lambda is also represented as an unnamed class. This is
@@ -1314,7 +1307,7 @@ CompilerType ClangASTContext::CreateRecordType(DeclContext *decl_ctx,
     if (decl_ctx)
       decl_ctx->addDecl(decl);
 
-    return CompilerType(this, ast->getTagDeclType(decl).getAsOpaquePtr());
+    return CompilerType(this, ast.getTagDeclType(decl).getAsOpaquePtr());
   }
   return CompilerType();
 }
@@ -1387,14 +1380,14 @@ clang::FunctionTemplateDecl *ClangASTContext::CreateFunctionTemplateDecl(
     clang::DeclContext *decl_ctx, clang::FunctionDecl *func_decl,
     const char *name, const TemplateParameterInfos &template_param_infos) {
   //    /// Create a function template node.
-  ASTContext *ast = getASTContext();
+  ASTContext &ast = getASTContext();
 
   llvm::SmallVector<NamedDecl *, 8> template_param_decls;
 
   TemplateParameterList *template_param_list = CreateTemplateParameterList(
-      ast, template_param_infos, template_param_decls);
+      &ast, template_param_infos, template_param_decls);
   FunctionTemplateDecl *func_tmpl_decl = FunctionTemplateDecl::Create(
-      *ast, decl_ctx, func_decl->getLocation(), func_decl->getDeclName(),
+      ast, decl_ctx, func_decl->getLocation(), func_decl->getDeclName(),
       template_param_list, func_decl);
 
   for (size_t i = 0, template_param_decl_count = template_param_decls.size();
@@ -1419,13 +1412,13 @@ void ClangASTContext::CreateFunctionTemplateSpecializationInfo(
 ClassTemplateDecl *ClangASTContext::CreateClassTemplateDecl(
     DeclContext *decl_ctx, lldb::AccessType access_type, const char *class_name,
     int kind, const TemplateParameterInfos &template_param_infos) {
-  ASTContext *ast = getASTContext();
+  ASTContext &ast = getASTContext();
 
   ClassTemplateDecl *class_template_decl = nullptr;
   if (decl_ctx == nullptr)
-    decl_ctx = ast->getTranslationUnitDecl();
+    decl_ctx = ast.getTranslationUnitDecl();
 
-  IdentifierInfo &identifier_info = ast->Idents.get(class_name);
+  IdentifierInfo &identifier_info = ast.Idents.get(class_name);
   DeclarationName decl_name(&identifier_info);
 
   clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
@@ -1439,10 +1432,10 @@ ClassTemplateDecl *ClangASTContext::CreateClassTemplateDecl(
   llvm::SmallVector<NamedDecl *, 8> template_param_decls;
 
   TemplateParameterList *template_param_list = CreateTemplateParameterList(
-      ast, template_param_infos, template_param_decls);
+      &ast, template_param_infos, template_param_decls);
 
   CXXRecordDecl *template_cxx_decl = CXXRecordDecl::Create(
-      *ast, (TagDecl::TagKind)kind,
+      ast, (TagDecl::TagKind)kind,
       decl_ctx, // What decl context do we use here? TU? The actual decl
                 // context?
       SourceLocation(), SourceLocation(), &identifier_info);
@@ -1458,7 +1451,7 @@ ClassTemplateDecl *ClangASTContext::CreateClassTemplateDecl(
   // template_cxx_decl->completeDefinition();
 
   class_template_decl = ClassTemplateDecl::Create(
-      *ast,
+      ast,
       decl_ctx, // What decl context do we use here? TU? The actual decl
                 // context?
       SourceLocation(), decl_name, template_param_list, template_cxx_decl);
@@ -1484,23 +1477,23 @@ ClassTemplateDecl *ClangASTContext::CreateClassTemplateDecl(
 
 TemplateTemplateParmDecl *
 ClangASTContext::CreateTemplateTemplateParmDecl(const char *template_name) {
-  ASTContext *ast = getASTContext();
+  ASTContext &ast = getASTContext();
 
-  auto *decl_ctx = ast->getTranslationUnitDecl();
+  auto *decl_ctx = ast.getTranslationUnitDecl();
 
-  IdentifierInfo &identifier_info = ast->Idents.get(template_name);
+  IdentifierInfo &identifier_info = ast.Idents.get(template_name);
   llvm::SmallVector<NamedDecl *, 8> template_param_decls;
 
   ClangASTContext::TemplateParameterInfos template_param_infos;
   TemplateParameterList *template_param_list = CreateTemplateParameterList(
-      ast, template_param_infos, template_param_decls);
+      &ast, template_param_infos, template_param_decls);
 
   // LLDB needs to create those decls only to be able to display a
   // type that includes a template template argument. Only the name matters for
   // this purpose, so we use dummy values for the other characterisitcs of the
   // type.
   return TemplateTemplateParmDecl::Create(
-      *ast, decl_ctx, SourceLocation(),
+      ast, decl_ctx, SourceLocation(),
       /*Depth*/ 0, /*Position*/ 0,
       /*IsParameterPack*/ false, &identifier_info, template_param_list);
 }
@@ -1509,7 +1502,7 @@ ClassTemplateSpecializationDecl *
 ClangASTContext::CreateClassTemplateSpecializationDecl(
     DeclContext *decl_ctx, ClassTemplateDecl *class_template_decl, int kind,
     const TemplateParameterInfos &template_param_infos) {
-  ASTContext *ast = getASTContext();
+  ASTContext &ast = getASTContext();
   llvm::SmallVector<clang::TemplateArgument, 2> args(
       template_param_infos.args.size() +
       (template_param_infos.packed_args ? 1 : 0));
@@ -1517,13 +1510,12 @@ ClangASTContext::CreateClassTemplateSpecializationDecl(
             args.begin());
   if (template_param_infos.packed_args) {
     args[args.size() - 1] = TemplateArgument::CreatePackCopy(
-        *ast, template_param_infos.packed_args->args);
+        ast, template_param_infos.packed_args->args);
   }
   ClassTemplateSpecializationDecl *class_template_specialization_decl =
       ClassTemplateSpecializationDecl::Create(
-          *ast, (TagDecl::TagKind)kind, decl_ctx, SourceLocation(),
-          SourceLocation(), class_template_decl, args,
-          nullptr);
+          ast, (TagDecl::TagKind)kind, decl_ctx, SourceLocation(),
+          SourceLocation(), class_template_decl, args, nullptr);
 
   class_template_specialization_decl->setSpecializationKind(
       TSK_ExplicitSpecialization);
@@ -1534,11 +1526,10 @@ ClangASTContext::CreateClassTemplateSpecializationDecl(
 CompilerType ClangASTContext::CreateClassTemplateSpecializationType(
     ClassTemplateSpecializationDecl *class_template_specialization_decl) {
   if (class_template_specialization_decl) {
-    ASTContext *ast = getASTContext();
-    if (ast)
-      return CompilerType(
-          this, ast->getTagDeclType(class_template_specialization_decl)
-                    .getAsOpaquePtr());
+    ASTContext &ast = getASTContext();
+    return CompilerType(this,
+                        ast.getTagDeclType(class_template_specialization_decl)
+                            .getAsOpaquePtr());
   }
   return CompilerType();
 }
@@ -1603,15 +1594,15 @@ ClangASTContext::UnifyAccessSpecifiers(clang::AccessSpecifier lhs,
 
 bool ClangASTContext::FieldIsBitfield(FieldDecl *field,
                                       uint32_t &bitfield_bit_size) {
-  ASTContext *ast = getASTContext();
-  if (ast == nullptr || field == nullptr)
+  ASTContext &ast = getASTContext();
+  if (field == nullptr)
     return false;
 
   if (field->isBitField()) {
     Expr *bit_width_expr = field->getBitWidth();
     if (bit_width_expr) {
       llvm::APSInt bit_width_apsint;
-      if (bit_width_expr->isIntegerConstantExpr(bit_width_apsint, *ast)) {
+      if (bit_width_expr->isIntegerConstantExpr(bit_width_apsint, ast)) {
         bitfield_bit_size = bit_width_apsint.getLimitedValue(UINT32_MAX);
         return true;
       }
@@ -1650,22 +1641,21 @@ CompilerType ClangASTContext::CreateObjCClass(llvm::StringRef name,
                                               bool isForwardDecl,
                                               bool isInternal,
                                               ClangASTMetadata *metadata) {
-  ASTContext *ast = getASTContext();
-  assert(ast != nullptr);
+  ASTContext &ast = getASTContext();
   assert(!name.empty());
   if (decl_ctx == nullptr)
-    decl_ctx = ast->getTranslationUnitDecl();
+    decl_ctx = ast.getTranslationUnitDecl();
 
   ObjCInterfaceDecl *decl = ObjCInterfaceDecl::Create(
-      *ast, decl_ctx, SourceLocation(), &ast->Idents.get(name), nullptr,
-      nullptr, SourceLocation(),
+      ast, decl_ctx, SourceLocation(), &ast.Idents.get(name), nullptr, nullptr,
+      SourceLocation(),
       /*isForwardDecl,*/
       isInternal);
 
   if (decl && metadata)
     SetMetadata(decl, *metadata);
 
-  return CompilerType(this, ast->getObjCInterfaceType(decl).getAsOpaquePtr());
+  return CompilerType(this, ast.getObjCInterfaceType(decl).getAsOpaquePtr());
 }
 
 static inline bool BaseSpecifierIsEmpty(const CXXBaseSpecifier *b) {
@@ -1700,13 +1690,13 @@ ClangASTContext::GetNumBaseClasses(const CXXRecordDecl *cxx_record_decl,
 NamespaceDecl *ClangASTContext::GetUniqueNamespaceDeclaration(
     const char *name, DeclContext *decl_ctx, bool is_inline) {
   NamespaceDecl *namespace_decl = nullptr;
-  ASTContext *ast = getASTContext();
-  TranslationUnitDecl *translation_unit_decl = ast->getTranslationUnitDecl();
+  ASTContext &ast = getASTContext();
+  TranslationUnitDecl *translation_unit_decl = ast.getTranslationUnitDecl();
   if (decl_ctx == nullptr)
     decl_ctx = translation_unit_decl;
 
   if (name) {
-    IdentifierInfo &identifier_info = ast->Idents.get(name);
+    IdentifierInfo &identifier_info = ast.Idents.get(name);
     DeclarationName decl_name(&identifier_info);
     clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
     for (NamedDecl *decl : result) {
@@ -1716,7 +1706,7 @@ NamespaceDecl *ClangASTContext::GetUniqueNamespaceDeclaration(
     }
 
     namespace_decl =
-        NamespaceDecl::Create(*ast, decl_ctx, is_inline, SourceLocation(),
+        NamespaceDecl::Create(ast, decl_ctx, is_inline, SourceLocation(),
                               SourceLocation(), &identifier_info, nullptr);
 
     decl_ctx->addDecl(namespace_decl);
@@ -1727,7 +1717,7 @@ NamespaceDecl *ClangASTContext::GetUniqueNamespaceDeclaration(
         return namespace_decl;
 
       namespace_decl =
-          NamespaceDecl::Create(*ast, decl_ctx, false, SourceLocation(),
+          NamespaceDecl::Create(ast, decl_ctx, false, SourceLocation(),
                                 SourceLocation(), nullptr, nullptr);
       translation_unit_decl->setAnonymousNamespace(namespace_decl);
       translation_unit_decl->addDecl(namespace_decl);
@@ -1739,7 +1729,7 @@ NamespaceDecl *ClangASTContext::GetUniqueNamespaceDeclaration(
         if (namespace_decl)
           return namespace_decl;
         namespace_decl =
-            NamespaceDecl::Create(*ast, decl_ctx, false, SourceLocation(),
+            NamespaceDecl::Create(ast, decl_ctx, false, SourceLocation(),
                                   SourceLocation(), nullptr, nullptr);
         parent_namespace_decl->setAnonymousNamespace(namespace_decl);
         parent_namespace_decl->addDecl(namespace_decl);
@@ -1760,8 +1750,8 @@ NamespaceDecl *ClangASTContext::GetUniqueNamespaceDeclaration(
 clang::BlockDecl *
 ClangASTContext::CreateBlockDeclaration(clang::DeclContext *ctx) {
   if (ctx != nullptr) {
-    clang::BlockDecl *decl = clang::BlockDecl::Create(*getASTContext(), ctx,
-                                                      clang::SourceLocation());
+    clang::BlockDecl *decl =
+        clang::BlockDecl::Create(getASTContext(), ctx, clang::SourceLocation());
     ctx->addDecl(decl);
     return decl;
   }
@@ -1789,9 +1779,9 @@ clang::UsingDirectiveDecl *ClangASTContext::CreateUsingDirectiveDeclaration(
     clang::DeclContext *decl_ctx, clang::NamespaceDecl *ns_decl) {
   if (decl_ctx != nullptr && ns_decl != nullptr) {
     clang::TranslationUnitDecl *translation_unit =
-        (clang::TranslationUnitDecl *)GetTranslationUnitDecl(getASTContext());
+        (clang::TranslationUnitDecl *)GetTranslationUnitDecl(&getASTContext());
     clang::UsingDirectiveDecl *using_decl = clang::UsingDirectiveDecl::Create(
-        *getASTContext(), decl_ctx, clang::SourceLocation(),
+        getASTContext(), decl_ctx, clang::SourceLocation(),
         clang::SourceLocation(), clang::NestedNameSpecifierLoc(),
         clang::SourceLocation(), ns_decl,
         FindLCABetweenDecls(decl_ctx, ns_decl, translation_unit));
@@ -1806,10 +1796,10 @@ ClangASTContext::CreateUsingDeclaration(clang::DeclContext *current_decl_ctx,
                                         clang::NamedDecl *target) {
   if (current_decl_ctx != nullptr && target != nullptr) {
     clang::UsingDecl *using_decl = clang::UsingDecl::Create(
-        *getASTContext(), current_decl_ctx, clang::SourceLocation(),
+        getASTContext(), current_decl_ctx, clang::SourceLocation(),
         clang::NestedNameSpecifierLoc(), clang::DeclarationNameInfo(), false);
     clang::UsingShadowDecl *shadow_decl = clang::UsingShadowDecl::Create(
-        *getASTContext(), current_decl_ctx, clang::SourceLocation(), using_decl,
+        getASTContext(), current_decl_ctx, clang::SourceLocation(), using_decl,
         target);
     using_decl->addShadowDecl(shadow_decl);
     current_decl_ctx->addDecl(using_decl);
@@ -1822,9 +1812,9 @@ clang::VarDecl *ClangASTContext::CreateVariableDeclaration(
     clang::DeclContext *decl_context, const char *name, clang::QualType type) {
   if (decl_context != nullptr) {
     clang::VarDecl *var_decl = clang::VarDecl::Create(
-        *getASTContext(), decl_context, clang::SourceLocation(),
+        getASTContext(), decl_context, clang::SourceLocation(),
         clang::SourceLocation(),
-        name && name[0] ? &getASTContext()->Idents.getOwn(name) : nullptr, type,
+        name && name[0] ? &getASTContext().Idents.getOwn(name) : nullptr, type,
         nullptr, clang::SC_None);
     var_decl->setAccess(clang::AS_public);
     decl_context->addDecl(var_decl);
@@ -1914,7 +1904,7 @@ ClangASTContext::GetDeclarationName(const char *name,
 
   clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS;
   if (!IsOperator(name, op_kind) || op_kind == clang::NUM_OVERLOADED_OPERATORS)
-    return DeclarationName(&getASTContext()->Idents.get(
+    return DeclarationName(&getASTContext().Idents.get(
         name)); // Not operator, but a regular function.
 
   // Check the number of operator parameters. Sometimes we have seen bad DWARF
@@ -1933,16 +1923,16 @@ ClangASTContext::GetDeclarationName(const char *name,
           is_method, op_kind, num_params))
     return clang::DeclarationName();
 
-  return getASTContext()->DeclarationNames.getCXXOperatorName(op_kind);
+  return getASTContext().DeclarationNames.getCXXOperatorName(op_kind);
 }
 
 FunctionDecl *ClangASTContext::CreateFunctionDeclaration(
     DeclContext *decl_ctx, const char *name,
     const CompilerType &function_clang_type, int storage, bool is_inline) {
   FunctionDecl *func_decl = nullptr;
-  ASTContext *ast = getASTContext();
+  ASTContext &ast = getASTContext();
   if (decl_ctx == nullptr)
-    decl_ctx = ast->getTranslationUnitDecl();
+    decl_ctx = ast.getTranslationUnitDecl();
 
   const bool hasWrittenPrototype = true;
   const bool isConstexprSpecified = false;
@@ -1950,7 +1940,7 @@ FunctionDecl *ClangASTContext::CreateFunctionDeclaration(
   clang::DeclarationName declarationName =
       GetDeclarationName(name, function_clang_type);
   func_decl = FunctionDecl::Create(
-      *ast, decl_ctx, SourceLocation(), SourceLocation(), declarationName,
+      ast, decl_ctx, SourceLocation(), SourceLocation(), declarationName,
       ClangUtil::GetQualType(function_clang_type), nullptr,
       (clang::StorageClass)storage, is_inline, hasWrittenPrototype,
       isConstexprSpecified ? CSK_constexpr : CSK_unspecified);
@@ -2009,11 +1999,10 @@ CompilerType ClangASTContext::CreateFunctionType(
 ParmVarDecl *ClangASTContext::CreateParameterDeclaration(
     clang::DeclContext *decl_ctx, const char *name,
     const CompilerType &param_type, int storage, bool add_decl) {
-  ASTContext *ast = getASTContext();
-  assert(ast != nullptr);
+  ASTContext &ast = getASTContext();
   auto *decl =
-      ParmVarDecl::Create(*ast, decl_ctx, SourceLocation(), SourceLocation(),
-                          name && name[0] ? &ast->Idents.get(name) : nullptr,
+      ParmVarDecl::Create(ast, decl_ctx, SourceLocation(), SourceLocation(),
+                          name && name[0] ? &ast.Idents.get(name) : nullptr,
                           ClangUtil::GetQualType(param_type), nullptr,
                           (clang::StorageClass)storage, nullptr);
   if (add_decl)
@@ -2043,28 +2032,27 @@ CompilerType ClangASTContext::CreateArrayType(const CompilerType &element_type,
                                               size_t element_count,
                                               bool is_vector) {
   if (element_type.IsValid()) {
-    ASTContext *ast = getASTContext();
-    assert(ast != nullptr);
+    ASTContext &ast = getASTContext();
 
     if (is_vector) {
       return CompilerType(
-          this, ast->getExtVectorType(ClangUtil::GetQualType(element_type),
-                                      element_count)
+          this, ast.getExtVectorType(ClangUtil::GetQualType(element_type),
+                                     element_count)
                     .getAsOpaquePtr());
     } else {
 
       llvm::APInt ap_element_count(64, element_count);
       if (element_count == 0) {
-        return CompilerType(this, ast->getIncompleteArrayType(
+        return CompilerType(this, ast.getIncompleteArrayType(
                                          ClangUtil::GetQualType(element_type),
                                          clang::ArrayType::Normal, 0)
                                       .getAsOpaquePtr());
       } else {
-        return CompilerType(this, ast->getConstantArrayType(
-                                         ClangUtil::GetQualType(element_type),
-                                         ap_element_count, nullptr,
-                                         clang::ArrayType::Normal, 0)
-                                      .getAsOpaquePtr());
+        return CompilerType(
+            this, ast.getConstantArrayType(ClangUtil::GetQualType(element_type),
+                                           ap_element_count, nullptr,
+                                           clang::ArrayType::Normal, 0)
+                      .getAsOpaquePtr());
       }
     }
   }
@@ -2117,14 +2105,14 @@ ClangASTContext::CreateEnumerationType(const char *name, DeclContext *decl_ctx,
                                        bool is_scoped) {
   // TODO: Do something intelligent with the Declaration object passed in
   // like maybe filling in the SourceLocation with it...
-  ASTContext *ast = getASTContext();
+  ASTContext &ast = getASTContext();
 
   // TODO: ask about these...
   //    const bool IsFixed = false;
 
   EnumDecl *enum_decl = EnumDecl::Create(
-      *ast, decl_ctx, SourceLocation(), SourceLocation(),
-      name && name[0] ? &ast->Idents.get(name) : nullptr, nullptr,
+      ast, decl_ctx, SourceLocation(), SourceLocation(),
+      name && name[0] ? &ast.Idents.get(name) : nullptr, nullptr,
       is_scoped, // IsScoped
       is_scoped, // IsScopedUsingClassTag
       false);    // IsFixed
@@ -2138,7 +2126,7 @@ ClangASTContext::CreateEnumerationType(const char *name, DeclContext *decl_ctx,
 
     enum_decl->setAccess(AS_public); // TODO respect what's in the debug info
 
-    return CompilerType(this, ast->getTagDeclType(enum_decl).getAsOpaquePtr());
+    return CompilerType(this, ast.getTagDeclType(enum_decl).getAsOpaquePtr());
   }
   return CompilerType();
 }
@@ -2377,14 +2365,14 @@ void ClangASTContext::SetMetadataAsUserID(const clang::Type *type,
 void ClangASTContext::SetMetadata(const clang::Decl *object,
                                   ClangASTMetadata &metadata) {
   if (auto *A = llvm::dyn_cast_or_null<ClangExternalASTSourceCommon>(
-          getASTContext()->getExternalSource()))
+          getASTContext().getExternalSource()))
     A->SetMetadata(object, metadata);
 }
 
 void ClangASTContext::SetMetadata(const clang::Type *object,
                                   ClangASTMetadata &metadata) {
   if (auto *A = llvm::dyn_cast_or_null<ClangExternalASTSourceCommon>(
-          getASTContext()->getExternalSource()))
+          getASTContext().getExternalSource()))
     A->SetMetadata(object, metadata);
 }
 
@@ -2787,8 +2775,9 @@ bool ClangASTContext::IsVectorType(lldb::opaque_compiler_type_t type,
 
 bool ClangASTContext::IsRuntimeGeneratedType(
     lldb::opaque_compiler_type_t type) {
-  clang::DeclContext *decl_ctx = ClangASTContext::GetASTContext(getASTContext())
-                                     ->GetDeclContextForType(GetQualType(type));
+  clang::DeclContext *decl_ctx =
+      ClangASTContext::GetASTContext(&getASTContext())
+          ->GetDeclContextForType(GetQualType(type));
   if (!decl_ctx)
     return false;
 
@@ -2799,7 +2788,7 @@ bool ClangASTContext::IsRuntimeGeneratedType(
       llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl_ctx);
 
   ClangASTMetadata *ast_metadata =
-      ClangASTContext::GetMetadata(getASTContext(), result_iface_decl);
+      ClangASTContext::GetMetadata(&getASTContext(), result_iface_decl);
   if (!ast_metadata)
     return false;
   return (ast_metadata->GetISAPtr() != 0);
@@ -2811,7 +2800,7 @@ bool ClangASTContext::IsCharType(lldb::opaque_compiler_type_t type) {
 
 bool ClangASTContext::IsCompleteType(lldb::opaque_compiler_type_t type) {
   const bool allow_completion = false;
-  return GetCompleteQualType(getASTContext(), GetQualType(type),
+  return GetCompleteQualType(&getASTContext(), GetQualType(type),
                              allow_completion);
 }
 
@@ -2913,7 +2902,7 @@ ClangASTContext::IsHomogeneousAggregate(lldb::opaque_compiler_type_t type,
           for (field_pos = record_decl->field_begin(); field_pos != field_end;
                ++field_pos) {
             clang::QualType field_qual_type = field_pos->getType();
-            uint64_t field_bitwidth = getASTContext()->getTypeSize(qual_type);
+            uint64_t field_bitwidth = getASTContext().getTypeSize(qual_type);
             if (field_qual_type->isFloatingType()) {
               if (field_qual_type->isComplexType())
                 return 0;
@@ -3451,7 +3440,7 @@ bool ClangASTContext::IsPossibleDynamicType(lldb::opaque_compiler_type_t type,
               success = cxx_record_decl->isDynamicClass();
             else {
               ClangASTMetadata *metadata = ClangASTContext::GetMetadata(
-                  getASTContext(), cxx_record_decl);
+                  &getASTContext(), cxx_record_decl);
               if (metadata)
                 success = metadata->GetIsDynamicCXXType();
               else {
@@ -3594,14 +3583,14 @@ bool ClangASTContext::GetCompleteType(lldb::opaque_compiler_type_t type) {
   if (!type)
     return false;
   const bool allow_completion = true;
-  return GetCompleteQualType(getASTContext(), GetQualType(type),
+  return GetCompleteQualType(&getASTContext(), GetQualType(type),
                              allow_completion);
 }
 
 ConstString ClangASTContext::GetTypeName(lldb::opaque_compiler_type_t type) {
   std::string type_name;
   if (type) {
-    clang::PrintingPolicy printing_policy(getASTContext()->getPrintingPolicy());
+    clang::PrintingPolicy printing_policy(getASTContext().getPrintingPolicy());
     clang::QualType qual_type(GetQualType(type));
     printing_policy.SuppressTagKeyword = true;
     const clang::TypedefType *typedef_type =
@@ -3645,14 +3634,14 @@ ClangASTContext::GetTypeInfo(lldb::opaque_compiler_type_t type,
     case clang::BuiltinType::ObjCClass:
       if (pointee_or_element_clang_type)
         pointee_or_element_clang_type->SetCompilerType(
-            this, getASTContext()->ObjCBuiltinClassTy.getAsOpaquePtr());
+            this, getASTContext().ObjCBuiltinClassTy.getAsOpaquePtr());
       builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
       break;
 
     case clang::BuiltinType::ObjCSel:
       if (pointee_or_element_clang_type)
         pointee_or_element_clang_type->SetCompilerType(
-            this, getASTContext()->CharTy.getAsOpaquePtr());
+            this, getASTContext().CharTy.getAsOpaquePtr());
       builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
       break;
 
@@ -3840,7 +3829,7 @@ ClangASTContext::GetMinimumLanguage(lldb::opaque_compiler_type_t type) {
     if (pointee_type->isObjCClassType())
       return lldb::eLanguageTypeObjC;
     if (pointee_type.getTypePtr() ==
-        getASTContext()->ObjCBuiltinIdTy.getTypePtr())
+        getASTContext().ObjCBuiltinIdTy.getTypePtr())
       return lldb::eLanguageTypeObjC;
   } else {
     if (qual_type->isObjCObjectOrInterfaceType())
@@ -4062,22 +4051,21 @@ CompilerType ClangASTContext::GetArrayType(lldb::opaque_compiler_type_t type,
                                            uint64_t size) {
   if (type) {
     clang::QualType qual_type(GetCanonicalQualType(type));
-    if (clang::ASTContext *ast_ctx = getASTContext()) {
-      if (size != 0)
-        return CompilerType(
-            this, ast_ctx
-                      ->getConstantArrayType(
-                          qual_type, llvm::APInt(64, size), nullptr,
-                          clang::ArrayType::ArraySizeModifier::Normal, 0)
-                      .getAsOpaquePtr());
-      else
-        return CompilerType(
-            this,
-            ast_ctx
-                ->getIncompleteArrayType(
-                    qual_type, clang::ArrayType::ArraySizeModifier::Normal, 0)
-                .getAsOpaquePtr());
-    }
+    clang::ASTContext &ast_ctx = getASTContext();
+    if (size != 0)
+      return CompilerType(
+          this, ast_ctx
+                    .getConstantArrayType(
+                        qual_type, llvm::APInt(64, size), nullptr,
+                        clang::ArrayType::ArraySizeModifier::Normal, 0)
+                    .getAsOpaquePtr());
+    else
+      return CompilerType(
+          this,
+          ast_ctx
+              .getIncompleteArrayType(
+                  qual_type, clang::ArrayType::ArraySizeModifier::Normal, 0)
+              .getAsOpaquePtr());
   }
 
   return CompilerType();
@@ -4107,8 +4095,8 @@ CompilerType
 ClangASTContext::GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) {
   if (type)
     return CompilerType(
-        this,
-        GetFullyUnqualifiedType_Impl(getASTContext(), GetQualType(type)).getAsOpaquePtr());
+        this, GetFullyUnqualifiedType_Impl(&getASTContext(), GetQualType(type))
+                  .getAsOpaquePtr());
   return CompilerType();
 }
 
@@ -4156,7 +4144,7 @@ ClangASTContext::GetNumMemberFunctions(lldb::opaque_compiler_type_t type) {
     clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
     switch (qual_type->getTypeClass()) {
     case clang::Type::Record:
-      if (GetCompleteQualType(getASTContext(), qual_type)) {
+      if (GetCompleteQualType(&getASTContext(), qual_type)) {
         const clang::RecordType *record_type =
             llvm::cast<clang::RecordType>(qual_type.getTypePtr());
         const clang::RecordDecl *record_decl = record_type->getDecl();
@@ -4220,7 +4208,7 @@ ClangASTContext::GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type,
     clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
     switch (qual_type->getTypeClass()) {
     case clang::Type::Record:
-      if (GetCompleteQualType(getASTContext(), qual_type)) {
+      if (GetCompleteQualType(&getASTContext(), qual_type)) {
         const clang::RecordType *record_type =
             llvm::cast<clang::RecordType>(qual_type.getTypePtr());
         const clang::RecordDecl *record_decl = record_type->getDecl();
@@ -4343,25 +4331,25 @@ CompilerType ClangASTContext::CreateTypedefType(
         llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
     if (!ast)
       return CompilerType();
-    clang::ASTContext *clang_ast = ast->getASTContext();
+    clang::ASTContext &clang_ast = ast->getASTContext();
     clang::QualType qual_type(ClangUtil::GetQualType(type));
 
     clang::DeclContext *decl_ctx =
         ClangASTContext::DeclContextGetAsDeclContext(compiler_decl_ctx);
     if (decl_ctx == nullptr)
-      decl_ctx = ast->getASTContext()->getTranslationUnitDecl();
+      decl_ctx = ast->getASTContext().getTranslationUnitDecl();
 
     clang::TypedefDecl *decl = clang::TypedefDecl::Create(
-        *clang_ast, decl_ctx, clang::SourceLocation(), clang::SourceLocation(),
-        &clang_ast->Idents.get(typedef_name),
-        clang_ast->getTrivialTypeSourceInfo(qual_type));
+        clang_ast, decl_ctx, clang::SourceLocation(), clang::SourceLocation(),
+        &clang_ast.Idents.get(typedef_name),
+        clang_ast.getTrivialTypeSourceInfo(qual_type));
 
     decl->setAccess(clang::AS_public); // TODO respect proper access specifier
 
     decl_ctx->addDecl(decl);
 
     // Get a uniqued clang::QualType for the typedef decl type
-    return CompilerType(ast, clang_ast->getTypedefType(decl).getAsOpaquePtr());
+    return CompilerType(ast, clang_ast.getTypedefType(decl).getAsOpaquePtr());
   }
   return CompilerType();
 }
@@ -4385,13 +4373,13 @@ ClangASTContext::GetPointerType(lldb::opaque_compiler_type_t type) {
     switch (type_class) {
     case clang::Type::ObjCObject:
     case clang::Type::ObjCInterface:
-      return CompilerType(this, getASTContext()
-                                    ->getObjCObjectPointerType(qual_type)
-                                    .getAsOpaquePtr());
+      return CompilerType(
+          this,
+          getASTContext().getObjCObjectPointerType(qual_type).getAsOpaquePtr());
 
     default:
       return CompilerType(
-          this, getASTContext()->getPointerType(qual_type).getAsOpaquePtr());
+          this, getASTContext().getPointerType(qual_type).getAsOpaquePtr());
     }
   }
   return CompilerType();
@@ -4401,7 +4389,7 @@ CompilerType
 ClangASTContext::GetLValueReferenceType(lldb::opaque_compiler_type_t type) {
   if (type)
     return CompilerType(this, getASTContext()
-                                  ->getLValueReferenceType(GetQualType(type))
+                                  .getLValueReferenceType(GetQualType(type))
                                   .getAsOpaquePtr());
   else
     return CompilerType();
@@ -4411,7 +4399,7 @@ CompilerType
 ClangASTContext::GetRValueReferenceType(lldb::opaque_compiler_type_t type) {
   if (type)
     return CompilerType(this, getASTContext()
-                                  ->getRValueReferenceType(GetQualType(type))
+                                  .getRValueReferenceType(GetQualType(type))
                                   .getAsOpaquePtr());
   else
     return CompilerType();
@@ -4421,7 +4409,7 @@ CompilerType ClangASTContext::GetAtomicType(lldb::opaque_compiler_type_t type) {
   if (!type)
     return CompilerType();
   return CompilerType(
-      this, getASTContext()->getAtomicType(GetQualType(type)).getAsOpaquePtr());
+      this, getASTContext().getAtomicType(GetQualType(type)).getAsOpaquePtr());
 }
 
 CompilerType
@@ -4459,18 +4447,18 @@ ClangASTContext::CreateTypedef(lldb::opaque_compiler_type_t type,
                                const char *typedef_name,
                                const CompilerDeclContext &compiler_decl_ctx) {
   if (type) {
-    clang::ASTContext *clang_ast = getASTContext();
+    clang::ASTContext &clang_ast = getASTContext();
     clang::QualType qual_type(GetQualType(type));
 
     clang::DeclContext *decl_ctx =
         ClangASTContext::DeclContextGetAsDeclContext(compiler_decl_ctx);
     if (decl_ctx == nullptr)
-      decl_ctx = getASTContext()->getTranslationUnitDecl();
+      decl_ctx = getASTContext().getTranslationUnitDecl();
 
     clang::TypedefDecl *decl = clang::TypedefDecl::Create(
-        *clang_ast, decl_ctx, clang::SourceLocation(), clang::SourceLocation(),
-        &clang_ast->Idents.get(typedef_name),
-        clang_ast->getTrivialTypeSourceInfo(qual_type));
+        clang_ast, decl_ctx, clang::SourceLocation(), clang::SourceLocation(),
+        &clang_ast.Idents.get(typedef_name),
+        clang_ast.getTrivialTypeSourceInfo(qual_type));
 
     clang::TagDecl *tdecl = nullptr;
     if (!qual_type.isNull()) {
@@ -4489,7 +4477,7 @@ ClangASTContext::CreateTypedef(lldb::opaque_compiler_type_t type,
     decl->setAccess(clang::AS_public); // TODO respect proper access specifier
 
     // Get a uniqued clang::QualType for the typedef decl type
-    return CompilerType(this, clang_ast->getTypedefType(decl).getAsOpaquePtr());
+    return CompilerType(this, clang_ast.getTypedefType(decl).getAsOpaquePtr());
   }
   return CompilerType();
 }
@@ -4515,17 +4503,16 @@ CompilerType ClangASTContext::GetBasicTypeFromAST(lldb::BasicType basic_type) {
 
 const llvm::fltSemantics &
 ClangASTContext::GetFloatTypeSemantics(size_t byte_size) {
-  if (auto *ast = getASTContext()) {
-    const size_t bit_size = byte_size * 8;
-    if (bit_size == ast->getTypeSize(ast->FloatTy))
-      return ast->getFloatTypeSemantics(ast->FloatTy);
-    else if (bit_size == ast->getTypeSize(ast->DoubleTy))
-      return ast->getFloatTypeSemantics(ast->DoubleTy);
-    else if (bit_size == ast->getTypeSize(ast->LongDoubleTy))
-      return ast->getFloatTypeSemantics(ast->LongDoubleTy);
-    else if (bit_size == ast->getTypeSize(ast->HalfTy))
-      return ast->getFloatTypeSemantics(ast->HalfTy);
-  }
+  clang::ASTContext &ast = getASTContext();
+  const size_t bit_size = byte_size * 8;
+  if (bit_size == ast.getTypeSize(ast.FloatTy))
+    return ast.getFloatTypeSemantics(ast.FloatTy);
+  else if (bit_size == ast.getTypeSize(ast.DoubleTy))
+    return ast.getFloatTypeSemantics(ast.DoubleTy);
+  else if (bit_size == ast.getTypeSize(ast.LongDoubleTy))
+    return ast.getFloatTypeSemantics(ast.LongDoubleTy);
+  else if (bit_size == ast.getTypeSize(ast.HalfTy))
+    return ast.getFloatTypeSemantics(ast.HalfTy);
   return llvm::APFloatBase::Bogus();
 }
 
@@ -4538,7 +4525,7 @@ ClangASTContext::GetBitSize(lldb::opaque_compiler_type_t type,
     switch (type_class) {
     case clang::Type::Record:
       if (GetCompleteType(type))
-        return getASTContext()->getTypeSize(qual_type);
+        return getASTContext().getTypeSize(qual_type);
       else
         return None;
       break;
@@ -4574,17 +4561,16 @@ ClangASTContext::GetBitSize(lldb::opaque_compiler_type_t type,
     }
       LLVM_FALLTHROUGH;
     default:
-      const uint32_t bit_size = getASTContext()->getTypeSize(qual_type);
+      const uint32_t bit_size = getASTContext().getTypeSize(qual_type);
       if (bit_size == 0) {
         if (qual_type->isIncompleteArrayType())
-          return getASTContext()->getTypeSize(
+          return getASTContext().getTypeSize(
               qual_type->getArrayElementTypeNoTypeQual()
                   ->getCanonicalTypeUnqualified());
       }
       if (qual_type->isObjCObjectOrInterfaceType())
         return bit_size +
-               getASTContext()->getTypeSize(
-                   getASTContext()->ObjCBuiltinClassTy);
+               getASTContext().getTypeSize(getASTContext().ObjCBuiltinClassTy);
       // Function types actually have a size of 0, that's not an error.
       if (qual_type->isFunctionProtoType())
         return bit_size;
@@ -4599,7 +4585,7 @@ llvm::Optional<size_t>
 ClangASTContext::GetTypeBitAlign(lldb::opaque_compiler_type_t type,
                                  ExecutionContextScope *exe_scope) {
   if (GetCompleteType(type))
-    return getASTContext()->getTypeAlign(GetQualType(type));
+    return getASTContext().getTypeAlign(GetQualType(type));
   return {};
 }
 
@@ -5053,7 +5039,7 @@ uint32_t ClangASTContext::GetNumChildren(lldb::opaque_compiler_type_t type,
   case clang::Type::Complex:
     return 0;
   case clang::Type::Record:
-    if (GetCompleteQualType(getASTContext(), qual_type)) {
+    if (GetCompleteQualType(&getASTContext(), qual_type)) {
       const clang::RecordType *record_type =
           llvm::cast<clang::RecordType>(qual_type.getTypePtr());
       const clang::RecordDecl *record_decl = record_type->getDecl();
@@ -5097,7 +5083,7 @@ uint32_t ClangASTContext::GetNumChildren(lldb::opaque_compiler_type_t type,
 
   case clang::Type::ObjCObject:
   case clang::Type::ObjCInterface:
-    if (GetCompleteQualType(getASTContext(), qual_type)) {
+    if (GetCompleteQualType(&getASTContext(), qual_type)) {
       const clang::ObjCObjectType *objc_class_type =
           llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
       assert(objc_class_type);
@@ -5444,7 +5430,7 @@ CompilerType ClangASTContext::GetFieldAtIndex(lldb::opaque_compiler_type_t type,
           // alignment (field_type_info.second) from the AST context.
           if (bit_offset_ptr) {
             const clang::ASTRecordLayout &record_layout =
-                getASTContext()->getASTRecordLayout(record_decl);
+                getASTContext().getASTRecordLayout(record_decl);
             *bit_offset_ptr = record_layout.getFieldOffset(field_idx);
           }
 
@@ -5458,7 +5444,7 @@ CompilerType ClangASTContext::GetFieldAtIndex(lldb::opaque_compiler_type_t type,
               clang::Expr::EvalResult result;
               if (bitfield_bit_size_expr &&
                   bitfield_bit_size_expr->EvaluateAsInt(result,
-                                                        *getASTContext())) {
+                                                        getASTContext())) {
                 llvm::APSInt bitfield_apsint = result.Val.getInt();
                 *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
               }
@@ -5485,7 +5471,7 @@ CompilerType ClangASTContext::GetFieldAtIndex(lldb::opaque_compiler_type_t type,
           objc_interface_type->getDecl();
       if (class_interface_decl) {
         return CompilerType(
-            this, GetObjCFieldAtIndex(getASTContext(), class_interface_decl,
+            this, GetObjCFieldAtIndex(&getASTContext(), class_interface_decl,
                                       idx, name, bit_offset_ptr,
                                       bitfield_bit_size_ptr, is_bitfield_ptr));
       }
@@ -5503,7 +5489,7 @@ CompilerType ClangASTContext::GetFieldAtIndex(lldb::opaque_compiler_type_t type,
         clang::ObjCInterfaceDecl *class_interface_decl =
             objc_class_type->getInterface();
         return CompilerType(
-            this, GetObjCFieldAtIndex(getASTContext(), class_interface_decl,
+            this, GetObjCFieldAtIndex(&getASTContext(), class_interface_decl,
                                       idx, name, bit_offset_ptr,
                                       bitfield_bit_size_ptr, is_bitfield_ptr));
       }
@@ -5608,7 +5594,7 @@ CompilerType ClangASTContext::GetDirectBaseClassAtIndex(
           if (curr_idx == idx) {
             if (bit_offset_ptr) {
               const clang::ASTRecordLayout &record_layout =
-                  getASTContext()->getASTRecordLayout(cxx_record_decl);
+                  getASTContext().getASTRecordLayout(cxx_record_decl);
               const clang::CXXRecordDecl *base_class_decl =
                   llvm::cast<clang::CXXRecordDecl>(
                       base_class->getType()
@@ -5649,9 +5635,10 @@ CompilerType ClangASTContext::GetDirectBaseClassAtIndex(
           if (superclass_interface_decl) {
             if (bit_offset_ptr)
               *bit_offset_ptr = 0;
-            return CompilerType(this,
-                                getASTContext()->getObjCInterfaceType(
-                                    superclass_interface_decl).getAsOpaquePtr());
+            return CompilerType(
+                this, getASTContext()
+                          .getObjCInterfaceType(superclass_interface_decl)
+                          .getAsOpaquePtr());
           }
         }
       }
@@ -5673,7 +5660,7 @@ CompilerType ClangASTContext::GetDirectBaseClassAtIndex(
               *bit_offset_ptr = 0;
             return CompilerType(
                 this, getASTContext()
-                          ->getObjCInterfaceType(superclass_interface_decl)
+                          .getObjCInterfaceType(superclass_interface_decl)
                           .getAsOpaquePtr());
           }
         }
@@ -5706,7 +5693,7 @@ CompilerType ClangASTContext::GetVirtualBaseClassAtIndex(
           if (curr_idx == idx) {
             if (bit_offset_ptr) {
               const clang::ASTRecordLayout &record_layout =
-                  getASTContext()->getASTRecordLayout(cxx_record_decl);
+                  getASTContext().getASTRecordLayout(cxx_record_decl);
               const clang::CXXRecordDecl *base_class_decl =
                   llvm::cast<clang::CXXRecordDecl>(
                       base_class->getType()
@@ -5903,10 +5890,10 @@ CompilerType ClangASTContext::GetChildCompilerTypeAtIndex(
       case clang::BuiltinType::ObjCClass:
         child_name = "isa";
         child_byte_size =
-            getASTContext()->getTypeSize(getASTContext()->ObjCBuiltinClassTy) /
+            getASTContext().getTypeSize(getASTContext().ObjCBuiltinClassTy) /
             CHAR_BIT;
         return CompilerType(
-            this, getASTContext()->ObjCBuiltinClassTy.getAsOpaquePtr());
+            this, getASTContext().ObjCBuiltinClassTy.getAsOpaquePtr());
 
       default:
         break;
@@ -5921,7 +5908,7 @@ CompilerType ClangASTContext::GetChildCompilerTypeAtIndex(
       const clang::RecordDecl *record_decl = record_type->getDecl();
       assert(record_decl);
       const clang::ASTRecordLayout &record_layout =
-          getASTContext()->getASTRecordLayout(record_decl);
+          getASTContext().getASTRecordLayout(record_decl);
       uint32_t child_idx = 0;
 
       const clang::CXXRecordDecl *cxx_record_decl =
@@ -5952,7 +5939,7 @@ CompilerType ClangASTContext::GetChildCompilerTypeAtIndex(
               bool handled = false;
               if (valobj) {
                 clang::VTableContextBase *vtable_ctx =
-                    getASTContext()->getVTableContext();
+                    getASTContext().getVTableContext();
                 if (vtable_ctx)
                   handled = GetVBaseBitOffset(*vtable_ctx, *valobj,
                                               record_layout, cxx_record_decl,
@@ -6044,27 +6031,27 @@ CompilerType ClangASTContext::GetChildCompilerTypeAtIndex(
         if (class_interface_decl) {
 
           const clang::ASTRecordLayout &interface_layout =
-              getASTContext()->getASTObjCInterfaceLayout(class_interface_decl);
+              getASTContext().getASTObjCInterfaceLayout(class_interface_decl);
           clang::ObjCInterfaceDecl *superclass_interface_decl =
               class_interface_decl->getSuperClass();
           if (superclass_interface_decl) {
             if (omit_empty_base_classes) {
               CompilerType base_class_clang_type(
                   this, getASTContext()
-                            ->getObjCInterfaceType(superclass_interface_decl)
+                            .getObjCInterfaceType(superclass_interface_decl)
                             .getAsOpaquePtr());
               if (base_class_clang_type.GetNumChildren(omit_empty_base_classes,
                                                        exe_ctx) > 0) {
                 if (idx == 0) {
                   clang::QualType ivar_qual_type(
-                      getASTContext()->getObjCInterfaceType(
+                      getASTContext().getObjCInterfaceType(
                           superclass_interface_decl));
 
                   child_name.assign(
                       superclass_interface_decl->getNameAsString());
 
                   clang::TypeInfo ivar_type_info =
-                      getASTContext()->getTypeInfo(ivar_qual_type.getTypePtr());
+                      getASTContext().getTypeInfo(ivar_qual_type.getTypePtr());
 
                   child_byte_size = ivar_type_info.Width / 8;
                   child_byte_offset = 0;
@@ -6095,7 +6082,7 @@ CompilerType ClangASTContext::GetChildCompilerTypeAtIndex(
                 child_name.assign(ivar_decl->getNameAsString());
 
                 clang::TypeInfo ivar_type_info =
-                    getASTContext()->getTypeInfo(ivar_qual_type.getTypePtr());
+                    getASTContext().getTypeInfo(ivar_qual_type.getTypePtr());
 
                 child_byte_size = ivar_type_info.Width / 8;
 
@@ -6455,7 +6442,7 @@ size_t ClangASTContext::GetIndexOfChildMemberWithName(
           // const Decl *root_cdecl = cxx_record_decl->getCanonicalDecl();
           // Didn't find things easily, lets let clang do its thang...
           clang::IdentifierInfo &ident_ref =
-              getASTContext()->Idents.get(name_sref);
+              getASTContext().Idents.get(name_sref);
           clang::DeclarationName decl_name(&ident_ref);
 
           clang::CXXBasePaths paths;
@@ -6544,7 +6531,7 @@ size_t ClangASTContext::GetIndexOfChildMemberWithName(
 
               CompilerType superclass_clang_type(
                   this, getASTContext()
-                            ->getObjCInterfaceType(superclass_interface_decl)
+                            .getObjCInterfaceType(superclass_interface_decl)
                             .getAsOpaquePtr());
               if (superclass_clang_type.GetIndexOfChildMemberWithName(
                       name, omit_empty_base_classes, child_indexes)) {
@@ -7030,26 +7017,26 @@ clang::FieldDecl *ClangASTContext::AddFieldToRecordType(
       llvm::dyn_cast_or_null<ClangASTContext>(type.GetTypeSystem());
   if (!ast)
     return nullptr;
-  clang::ASTContext *clang_ast = ast->getASTContext();
+  clang::ASTContext &clang_ast = ast->getASTContext();
   clang::IdentifierInfo *ident = nullptr;
   if (!name.empty())
-    ident = &clang_ast->Idents.get(name);
+    ident = &clang_ast.Idents.get(name);
 
   clang::FieldDecl *field = nullptr;
 
   clang::Expr *bit_width = nullptr;
   if (bitfield_bit_size != 0) {
-    llvm::APInt bitfield_bit_size_apint(
-        clang_ast->getTypeSize(clang_ast->IntTy), bitfield_bit_size);
-    bit_width = new (*clang_ast)
-        clang::IntegerLiteral(*clang_ast, bitfield_bit_size_apint,
-                              clang_ast->IntTy, clang::SourceLocation());
+    llvm::APInt bitfield_bit_size_apint(clang_ast.getTypeSize(clang_ast.IntTy),
+                                        bitfield_bit_size);
+    bit_width = new (clang_ast)
+        clang::IntegerLiteral(clang_ast, bitfield_bit_size_apint,
+                              clang_ast.IntTy, clang::SourceLocation());
   }
 
   clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type);
   if (record_decl) {
     field = clang::FieldDecl::Create(
-        *clang_ast, record_decl, clang::SourceLocation(),
+        clang_ast, record_decl, clang::SourceLocation(),
         clang::SourceLocation(),
         ident,                                    // Identifier
         ClangUtil::GetQualType(field_clang_type), // Field type
@@ -7092,7 +7079,7 @@ clang::FieldDecl *ClangASTContext::AddFieldToRecordType(
       field_clang_type.GetCompleteType();
 
       field = clang::ObjCIvarDecl::Create(
-          *clang_ast, class_interface_decl, clang::SourceLocation(),
+          clang_ast, class_interface_decl, clang::SourceLocation(),
           clang::SourceLocation(),
           ident,                                    // Identifier
           ClangUtil::GetQualType(field_clang_type), // Field type
@@ -7154,12 +7141,12 @@ void ClangASTContext::BuildIndirectFields(const CompilerType &type) {
         if (clang::FieldDecl *nested_field_decl =
                 llvm::dyn_cast<clang::FieldDecl>(*di)) {
           clang::NamedDecl **chain =
-              new (*ast->getASTContext()) clang::NamedDecl *[2];
+              new (ast->getASTContext()) clang::NamedDecl *[2];
           chain[0] = *field_pos;
           chain[1] = nested_field_decl;
           clang::IndirectFieldDecl *indirect_field =
               clang::IndirectFieldDecl::Create(
-                  *ast->getASTContext(), record_decl, clang::SourceLocation(),
+                  ast->getASTContext(), record_decl, clang::SourceLocation(),
                   nested_field_decl->getIdentifier(),
                   nested_field_decl->getType(), {chain, 2});
 
@@ -7173,7 +7160,7 @@ void ClangASTContext::BuildIndirectFields(const CompilerType &type) {
                        llvm::dyn_cast<clang::IndirectFieldDecl>(*di)) {
           size_t nested_chain_size =
               nested_indirect_field_decl->getChainingSize();
-          clang::NamedDecl **chain = new (*ast->getASTContext())
+          clang::NamedDecl **chain = new (ast->getASTContext())
               clang::NamedDecl *[nested_chain_size + 1];
           chain[0] = *field_pos;
 
@@ -7188,7 +7175,7 @@ void ClangASTContext::BuildIndirectFields(const CompilerType &type) {
 
           clang::IndirectFieldDecl *indirect_field =
               clang::IndirectFieldDecl::Create(
-                  *ast->getASTContext(), record_decl, clang::SourceLocation(),
+                  ast->getASTContext(), record_decl, clang::SourceLocation(),
                   nested_indirect_field_decl->getIdentifier(),
                   nested_indirect_field_decl->getType(),
                   {chain, nested_chain_size + 1});
@@ -7229,7 +7216,7 @@ void ClangASTContext::SetIsPacked(const CompilerType &type) {
         return;
 
       record_decl->addAttr(
-          clang::PackedAttr::CreateImplicit(*ast->getASTContext()));
+          clang::PackedAttr::CreateImplicit(ast->getASTContext()));
     }
   }
 }
@@ -7251,10 +7238,10 @@ clang::VarDecl *ClangASTContext::AddVariableToRecordType(
   clang::VarDecl *var_decl = nullptr;
   clang::IdentifierInfo *ident = nullptr;
   if (!name.empty())
-    ident = &ast->getASTContext()->Idents.get(name);
+    ident = &ast->getASTContext().Idents.get(name);
 
   var_decl = clang::VarDecl::Create(
-      *ast->getASTContext(),            // ASTContext &
+      ast->getASTContext(),             // ASTContext &
       record_decl,                      // DeclContext *
       clang::SourceLocation(),          // clang::SourceLocation StartLoc
       clang::SourceLocation(),          // clang::SourceLocation IdLoc
@@ -7297,7 +7284,7 @@ clang::CXXMethodDecl *ClangASTContext::AddMethodToCXXRecordType(
 
   clang::CXXMethodDecl *cxx_method_decl = nullptr;
 
-  clang::DeclarationName decl_name(&getASTContext()->Idents.get(name));
+  clang::DeclarationName decl_name(&getASTContext().Idents.get(name));
 
   const clang::FunctionType *function_type =
       llvm::dyn_cast<clang::FunctionType>(method_qual_type.getTypePtr());
@@ -7325,20 +7312,20 @@ clang::CXXMethodDecl *ClangASTContext::AddMethodToCXXRecordType(
                             : clang::ExplicitSpecKind::ResolvedFalse);
   if (name[0] == '~') {
     cxx_dtor_decl = clang::CXXDestructorDecl::Create(
-        *getASTContext(), cxx_record_decl, clang::SourceLocation(),
+        getASTContext(), cxx_record_decl, clang::SourceLocation(),
         clang::DeclarationNameInfo(
-            getASTContext()->DeclarationNames.getCXXDestructorName(
-                getASTContext()->getCanonicalType(record_qual_type)),
+            getASTContext().DeclarationNames.getCXXDestructorName(
+                getASTContext().getCanonicalType(record_qual_type)),
             clang::SourceLocation()),
         method_qual_type, nullptr, is_inline, is_artificial,
-          ConstexprSpecKind::CSK_unspecified);
+        ConstexprSpecKind::CSK_unspecified);
     cxx_method_decl = cxx_dtor_decl;
   } else if (decl_name == cxx_record_decl->getDeclName()) {
     cxx_ctor_decl = clang::CXXConstructorDecl::Create(
-        *getASTContext(), cxx_record_decl, clang::SourceLocation(),
+        getASTContext(), cxx_record_decl, clang::SourceLocation(),
         clang::DeclarationNameInfo(
-            getASTContext()->DeclarationNames.getCXXConstructorName(
-                getASTContext()->getCanonicalType(record_qual_type)),
+            getASTContext().DeclarationNames.getCXXConstructorName(
+                getASTContext().getCanonicalType(record_qual_type)),
             clang::SourceLocation()),
         method_qual_type,
         nullptr, // TypeSourceInfo *
@@ -7359,9 +7346,9 @@ clang::CXXMethodDecl *ClangASTContext::AddMethodToCXXRecordType(
                 is_method, op_kind, num_params))
           return nullptr;
         cxx_method_decl = clang::CXXMethodDecl::Create(
-            *getASTContext(), cxx_record_decl, clang::SourceLocation(),
+            getASTContext(), cxx_record_decl, clang::SourceLocation(),
             clang::DeclarationNameInfo(
-                getASTContext()->DeclarationNames.getCXXOperatorName(op_kind),
+                getASTContext().DeclarationNames.getCXXOperatorName(op_kind),
                 clang::SourceLocation()),
             method_qual_type,
             nullptr, // TypeSourceInfo *
@@ -7369,22 +7356,21 @@ clang::CXXMethodDecl *ClangASTContext::AddMethodToCXXRecordType(
       } else if (num_params == 0) {
         // Conversion operators don't take params...
         cxx_method_decl = clang::CXXConversionDecl::Create(
-            *getASTContext(), cxx_record_decl, clang::SourceLocation(),
+            getASTContext(), cxx_record_decl, clang::SourceLocation(),
             clang::DeclarationNameInfo(
-                getASTContext()->DeclarationNames.getCXXConversionFunctionName(
-                    getASTContext()->getCanonicalType(
+                getASTContext().DeclarationNames.getCXXConversionFunctionName(
+                    getASTContext().getCanonicalType(
                         function_type->getReturnType())),
                 clang::SourceLocation()),
             method_qual_type,
             nullptr, // TypeSourceInfo *
-            is_inline, explicit_spec, CSK_unspecified,
-            clang::SourceLocation());
+            is_inline, explicit_spec, CSK_unspecified, clang::SourceLocation());
       }
     }
 
     if (cxx_method_decl == nullptr) {
       cxx_method_decl = clang::CXXMethodDecl::Create(
-          *getASTContext(), cxx_record_decl, clang::SourceLocation(),
+          getASTContext(), cxx_record_decl, clang::SourceLocation(),
           clang::DeclarationNameInfo(decl_name, clang::SourceLocation()),
           method_qual_type,
           nullptr, // TypeSourceInfo *
@@ -7399,11 +7385,11 @@ clang::CXXMethodDecl *ClangASTContext::AddMethodToCXXRecordType(
   cxx_method_decl->setVirtualAsWritten(is_virtual);
 
   if (is_attr_used)
-    cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(*getASTContext()));
+    cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(getASTContext()));
 
   if (mangled_name != nullptr) {
     cxx_method_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(
-        *getASTContext(), mangled_name, /*literal=*/false));
+        getASTContext(), mangled_name, /*literal=*/false));
   }
 
   // Populate the method decl with parameter decls
@@ -7412,7 +7398,7 @@ clang::CXXMethodDecl *ClangASTContext::AddMethodToCXXRecordType(
 
   for (unsigned param_index = 0; param_index < num_params; ++param_index) {
     params.push_back(clang::ParmVarDecl::Create(
-        *getASTContext(), cxx_method_decl, clang::SourceLocation(),
+        getASTContext(), cxx_method_decl, clang::SourceLocation(),
         clang::SourceLocation(),
         nullptr, // anonymous
         method_function_prototype->getParamType(param_index), nullptr,
@@ -7479,7 +7465,7 @@ ClangASTContext::CreateBaseClassSpecifier(lldb::opaque_compiler_type_t type,
   return std::make_unique<clang::CXXBaseSpecifier>(
       clang::SourceRange(), is_virtual, base_of_class,
       ClangASTContext::ConvertAccessTypeToAccessSpecifier(access),
-      getASTContext()->getTrivialTypeSourceInfo(GetQualType(type)),
+      getASTContext().getTrivialTypeSourceInfo(GetQualType(type)),
       clang::SourceLocation());
 }
 
@@ -7508,7 +7494,7 @@ bool ClangASTContext::SetObjCSuperClass(
       llvm::dyn_cast_or_null<ClangASTContext>(type.GetTypeSystem());
   if (!ast)
     return false;
-  clang::ASTContext *clang_ast = ast->getASTContext();
+  clang::ASTContext &clang_ast = ast->getASTContext();
 
   if (type && superclass_clang_type.IsValid() &&
       superclass_clang_type.GetTypeSystem() == type.GetTypeSystem()) {
@@ -7517,8 +7503,8 @@ bool ClangASTContext::SetObjCSuperClass(
     clang::ObjCInterfaceDecl *super_interface_decl =
         GetAsObjCInterfaceDecl(superclass_clang_type);
     if (class_interface_decl && super_interface_decl) {
-      class_interface_decl->setSuperClass(clang_ast->getTrivialTypeSourceInfo(
-          clang_ast->getObjCInterfaceType(super_interface_decl)));
+      class_interface_decl->setSuperClass(clang_ast.getTrivialTypeSourceInfo(
+          clang_ast.getObjCInterfaceType(super_interface_decl)));
       return true;
     }
   }
@@ -7536,7 +7522,7 @@ bool ClangASTContext::AddObjCClassProperty(
   ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
   if (!ast)
     return false;
-  clang::ASTContext *clang_ast = ast->getASTContext();
+  clang::ASTContext &clang_ast = ast->getASTContext();
 
   clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl(type);
   if (!class_interface_decl)
@@ -7555,16 +7541,15 @@ bool ClangASTContext::AddObjCClassProperty(
 
   clang::TypeSourceInfo *prop_type_source;
   if (ivar_decl)
-    prop_type_source =
-        clang_ast->getTrivialTypeSourceInfo(ivar_decl->getType());
+    prop_type_source = clang_ast.getTrivialTypeSourceInfo(ivar_decl->getType());
   else
-    prop_type_source = clang_ast->getTrivialTypeSourceInfo(
+    prop_type_source = clang_ast.getTrivialTypeSourceInfo(
         ClangUtil::GetQualType(property_clang_type));
 
   clang::ObjCPropertyDecl *property_decl = clang::ObjCPropertyDecl::Create(
-      *clang_ast, class_interface_decl,
+      clang_ast, class_interface_decl,
       clang::SourceLocation(), // Source Location
-      &clang_ast->Idents.get(property_name),
+      &clang_ast.Idents.get(property_name),
       clang::SourceLocation(), // Source Location for AT
       clang::SourceLocation(), // Source location for (
       ivar_decl ? ivar_decl->getType()
@@ -7585,26 +7570,26 @@ bool ClangASTContext::AddObjCClassProperty(
     std::string property_setter_no_colon(property_setter_name,
                                          strlen(property_setter_name) - 1);
     clang::IdentifierInfo *setter_ident =
-        &clang_ast->Idents.get(property_setter_no_colon);
-    setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident);
+        &clang_ast.Idents.get(property_setter_no_colon);
+    setter_sel = clang_ast.Selectors.getSelector(1, &setter_ident);
   } else if (!(property_attributes & DW_APPLE_PROPERTY_readonly)) {
     std::string setter_sel_string("set");
     setter_sel_string.push_back(::toupper(property_name[0]));
     setter_sel_string.append(&property_name[1]);
     clang::IdentifierInfo *setter_ident =
-        &clang_ast->Idents.get(setter_sel_string);
-    setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident);
+        &clang_ast.Idents.get(setter_sel_string);
+    setter_sel = clang_ast.Selectors.getSelector(1, &setter_ident);
   }
   property_decl->setSetterName(setter_sel);
   property_decl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_setter);
 
   if (property_getter_name != nullptr) {
     clang::IdentifierInfo *getter_ident =
-        &clang_ast->Idents.get(property_getter_name);
-    getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident);
+        &clang_ast.Idents.get(property_getter_name);
+    getter_sel = clang_ast.Selectors.getSelector(0, &getter_ident);
   } else {
-    clang::IdentifierInfo *getter_ident = &clang_ast->Idents.get(property_name);
-    getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident);
+    clang::IdentifierInfo *getter_ident = &clang_ast.Idents.get(property_name);
+    getter_sel = clang_ast.Selectors.getSelector(0, &getter_ident);
   }
   property_decl->setGetterName(getter_sel);
   property_decl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_getter);
@@ -7650,18 +7635,17 @@ bool ClangASTContext::AddObjCClassProperty(
     const bool HasRelatedResultType = false;
 
     getter = clang::ObjCMethodDecl::Create(
-        *clang_ast, clang::SourceLocation(), clang::SourceLocation(),
-        getter_sel, ClangUtil::GetQualType(property_clang_type_to_access),
-        nullptr, class_interface_decl, isInstance, isVariadic,
-        isPropertyAccessor, isSynthesizedAccessorStub, isImplicitlyDeclared,
-        isDefined, impControl, HasRelatedResultType);
+        clang_ast, clang::SourceLocation(), clang::SourceLocation(), getter_sel,
+        ClangUtil::GetQualType(property_clang_type_to_access), nullptr,
+        class_interface_decl, isInstance, isVariadic, isPropertyAccessor,
+        isSynthesizedAccessorStub, isImplicitlyDeclared, isDefined, impControl,
+        HasRelatedResultType);
 
     if (getter) {
       if (metadata)
         ast->SetMetadata(getter, *metadata);
 
-      getter->setMethodParams(*clang_ast,
-                              llvm::ArrayRef<clang::ParmVarDecl *>(),
+      getter->setMethodParams(clang_ast, llvm::ArrayRef<clang::ParmVarDecl *>(),
                               llvm::ArrayRef<clang::SourceLocation>());
       class_interface_decl->addDecl(getter);
     }
@@ -7675,7 +7659,7 @@ bool ClangASTContext::AddObjCClassProperty(
     setter = isInstance ? class_interface_decl->lookupInstanceMethod(setter_sel)
                         : class_interface_decl->lookupClassMethod(setter_sel);
   if (!setter_sel.isNull() && !setter) {
-    clang::QualType result_type = clang_ast->VoidTy;
+    clang::QualType result_type = clang_ast.VoidTy;
     const bool isVariadic = false;
     const bool isPropertyAccessor = true;
     const bool isSynthesizedAccessorStub = false;
@@ -7686,10 +7670,10 @@ bool ClangASTContext::AddObjCClassProperty(
     const bool HasRelatedResultType = false;
 
     setter = clang::ObjCMethodDecl::Create(
-        *clang_ast, clang::SourceLocation(), clang::SourceLocation(),
-        setter_sel, result_type, nullptr, class_interface_decl, isInstance,
-        isVariadic, isPropertyAccessor, isSynthesizedAccessorStub,
-        isImplicitlyDeclared, isDefined, impControl, HasRelatedResultType);
+        clang_ast, clang::SourceLocation(), clang::SourceLocation(), setter_sel,
+        result_type, nullptr, class_interface_decl, isInstance, isVariadic,
+        isPropertyAccessor, isSynthesizedAccessorStub, isImplicitlyDeclared,
+        isDefined, impControl, HasRelatedResultType);
 
     if (setter) {
       if (metadata)
@@ -7697,12 +7681,12 @@ bool ClangASTContext::AddObjCClassProperty(
 
       llvm::SmallVector<clang::ParmVarDecl *, 1> params;
       params.push_back(clang::ParmVarDecl::Create(
-          *clang_ast, setter, clang::SourceLocation(), clang::SourceLocation(),
+          clang_ast, setter, clang::SourceLocation(), clang::SourceLocation(),
           nullptr, // anonymous
           ClangUtil::GetQualType(property_clang_type_to_access), nullptr,
           clang::SC_Auto, nullptr));
 
-      setter->setMethodParams(*clang_ast,
+      setter->setMethodParams(clang_ast,
                               llvm::ArrayRef<clang::ParmVarDecl *>(params),
                               llvm::ArrayRef<clang::SourceLocation>());
 
@@ -7743,7 +7727,7 @@ clang::ObjCMethodDecl *ClangASTContext::AddMethodToObjCObjectType(
       llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
   if (lldb_ast == nullptr)
     return nullptr;
-  clang::ASTContext *ast = lldb_ast->getASTContext();
+  clang::ASTContext &ast = lldb_ast->getASTContext();
 
   const char *selector_start = ::strchr(name, ' ');
   if (selector_start == nullptr)
@@ -7763,7 +7747,7 @@ clang::ObjCMethodDecl *ClangASTContext::AddMethodToObjCObjectType(
     bool has_arg = (start[len] == ':');
     if (has_arg)
       ++num_selectors_with_args;
-    selector_idents.push_back(&ast->Idents.get(llvm::StringRef(start, len)));
+    selector_idents.push_back(&ast.Idents.get(llvm::StringRef(start, len)));
     if (has_arg)
       len += 1;
   }
@@ -7771,7 +7755,7 @@ clang::ObjCMethodDecl *ClangASTContext::AddMethodToObjCObjectType(
   if (selector_idents.size() == 0)
     return nullptr;
 
-  clang::Selector method_selector = ast->Selectors.getSelector(
+  clang::Selector method_selector = ast.Selectors.getSelector(
       num_selectors_with_args ? selector_idents.size() : 0,
       selector_idents.data());
 
@@ -7807,12 +7791,12 @@ clang::ObjCMethodDecl *ClangASTContext::AddMethodToObjCObjectType(
                     // deal with it.
 
   clang::ObjCMethodDecl *objc_method_decl = clang::ObjCMethodDecl::Create(
-      *ast,
+      ast,
       clang::SourceLocation(), // beginLoc,
       clang::SourceLocation(), // endLoc,
       method_selector, method_function_prototype->getReturnType(),
       nullptr, // TypeSourceInfo *ResultTInfo,
-      ClangASTContext::GetASTContext(ast)->GetDeclContextForType(
+      ClangASTContext::GetASTContext(&ast)->GetDeclContextForType(
           ClangUtil::GetQualType(type)),
       isInstance, isVariadic, isPropertyAccessor, isSynthesizedAccessorStub,
       isImplicitlyDeclared, isDefined, impControl, HasRelatedResultType);
@@ -7825,7 +7809,7 @@ clang::ObjCMethodDecl *ClangASTContext::AddMethodToObjCObjectType(
 
     for (unsigned param_index = 0; param_index < num_args; ++param_index) {
       params.push_back(clang::ParmVarDecl::Create(
-          *ast, objc_method_decl, clang::SourceLocation(),
+          ast, objc_method_decl, clang::SourceLocation(),
           clang::SourceLocation(),
           nullptr, // anonymous
           method_function_prototype->getParamType(param_index), nullptr,
@@ -7833,7 +7817,7 @@ clang::ObjCMethodDecl *ClangASTContext::AddMethodToObjCObjectType(
     }
 
     objc_method_decl->setMethodParams(
-        *ast, llvm::ArrayRef<clang::ParmVarDecl *>(params),
+        ast, llvm::ArrayRef<clang::ParmVarDecl *>(params),
         llvm::ArrayRef<clang::SourceLocation>());
   }
 
@@ -7841,12 +7825,12 @@ clang::ObjCMethodDecl *ClangASTContext::AddMethodToObjCObjectType(
     // Add a the objc_direct attribute to the declaration we generate that
     // we generate a direct method call for this ObjCMethodDecl.
     objc_method_decl->addAttr(
-        clang::ObjCDirectAttr::CreateImplicit(*ast, SourceLocation()));
+        clang::ObjCDirectAttr::CreateImplicit(ast, SourceLocation()));
     // Usually Sema is creating implicit parameters (e.g., self) when it
     // parses the method. We don't have a parsing Sema when we build our own
     // AST here so we manually need to create these implicit parameters to
     // make the direct call code generation happy.
-    objc_method_decl->createImplicitParams(*ast, class_interface_decl);
+    objc_method_decl->createImplicitParams(ast, class_interface_decl);
   }
 
   class_interface_decl->addDecl(objc_method_decl);
@@ -7972,7 +7956,7 @@ bool ClangASTContext::CompleteTagDeclarationDefinition(
               llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
           if (lldb_ast == nullptr)
             return false;
-          clang::ASTContext *ast = lldb_ast->getASTContext();
+          clang::ASTContext &ast = lldb_ast->getASTContext();
 
           /// TODO This really needs to be fixed.
 
@@ -7984,12 +7968,12 @@ bool ClangASTContext::CompleteTagDeclarationDefinition(
             clang::QualType promotion_qual_type;
             // If the enum integer type is less than an integer in bit width,
             // then we must promote it to an integer size.
-            if (ast->getTypeSize(enum_decl->getIntegerType()) <
-                ast->getTypeSize(ast->IntTy)) {
+            if (ast.getTypeSize(enum_decl->getIntegerType()) <
+                ast.getTypeSize(ast.IntTy)) {
               if (enum_decl->getIntegerType()->isSignedIntegerType())
-                promotion_qual_type = ast->IntTy;
+                promotion_qual_type = ast.IntTy;
               else
-                promotion_qual_type = ast->UnsignedIntTy;
+                promotion_qual_type = ast.UnsignedIntTy;
             } else
               promotion_qual_type = enum_decl->getIntegerType();
 
@@ -8034,8 +8018,8 @@ clang::EnumConstantDecl *ClangASTContext::AddEnumerationValueToEnumerationType(
     return nullptr;
 
   clang::EnumConstantDecl *enumerator_decl = clang::EnumConstantDecl::Create(
-      *getASTContext(), enutype->getDecl(), clang::SourceLocation(),
-      name ? &getASTContext()->Idents.get(name) : nullptr, // Identifier
+      getASTContext(), enutype->getDecl(), clang::SourceLocation(),
+      name ? &getASTContext().Idents.get(name) : nullptr, // Identifier
       clang::QualType(enutype, 0), nullptr, value);
 
   if (!enumerator_decl)
@@ -8090,7 +8074,7 @@ ClangASTContext::CreateMemberPointerType(const CompilerType &type,
     if (!ast)
       return CompilerType();
     return CompilerType(ast, ast->getASTContext()
-                                 ->getMemberPointerType(
+                                 .getMemberPointerType(
                                      ClangUtil::GetQualType(pointee_type),
                                      ClangUtil::GetQualType(type).getTypePtr())
                                  .getAsOpaquePtr());
@@ -8176,7 +8160,7 @@ void ClangASTContext::DumpValue(
       uint32_t field_bit_offset = 0;
       uint32_t field_byte_offset = 0;
       const clang::ASTRecordLayout &record_layout =
-          getASTContext()->getASTRecordLayout(record_decl);
+          getASTContext().getASTRecordLayout(record_decl);
       uint32_t child_idx = 0;
 
       const clang::CXXRecordDecl *cxx_record_decl =
@@ -8220,7 +8204,7 @@ void ClangASTContext::DumpValue(
                     base_class_type_name);
 
           clang::TypeInfo base_class_type_info =
-              getASTContext()->getTypeInfo(base_class_qual_type);
+              getASTContext().getTypeInfo(base_class_qual_type);
 
           // Dump the value of the member
           CompilerType base_clang_type(this,
@@ -8267,7 +8251,7 @@ void ClangASTContext::DumpValue(
         // Figure out the type byte size (field_type_info.first) and alignment
         // (field_type_info.second) from the AST context.
         clang::TypeInfo field_type_info =
-            getASTContext()->getTypeInfo(field_type);
+            getASTContext().getTypeInfo(field_type);
         assert(field_idx < record_layout.getFieldCount());
         // Figure out the field offset within the current struct/union/class
         // type
@@ -8355,7 +8339,7 @@ void ClangASTContext::DumpValue(
     const uint64_t element_count = array->getSize().getLimitedValue();
 
     clang::TypeInfo field_type_info =
-        getASTContext()->getTypeInfo(element_qual_type);
+        getASTContext().getTypeInfo(element_qual_type);
 
     uint32_t element_idx = 0;
     uint32_t element_offset = 0;
@@ -8424,7 +8408,7 @@ void ClangASTContext::DumpValue(
     CompilerType typedef_clang_type(this, typedef_qual_type.getAsOpaquePtr());
     lldb::Format typedef_format = typedef_clang_type.GetFormat();
     clang::TypeInfo typedef_type_info =
-        getASTContext()->getTypeInfo(typedef_qual_type);
+        getASTContext().getTypeInfo(typedef_qual_type);
     uint64_t typedef_byte_size = typedef_type_info.Width / 8;
 
     return typedef_clang_type.DumpValue(
@@ -8450,7 +8434,7 @@ void ClangASTContext::DumpValue(
                                        elaborated_qual_type.getAsOpaquePtr());
     lldb::Format elaborated_format = elaborated_clang_type.GetFormat();
     clang::TypeInfo elaborated_type_info =
-        getASTContext()->getTypeInfo(elaborated_qual_type);
+        getASTContext().getTypeInfo(elaborated_qual_type);
     uint64_t elaborated_byte_size = elaborated_type_info.Width / 8;
 
     return elaborated_clang_type.DumpValue(
@@ -8476,7 +8460,7 @@ void ClangASTContext::DumpValue(
                                        elaborated_qual_type.getAsOpaquePtr());
     lldb::Format elaborated_format = elaborated_clang_type.GetFormat();
     clang::TypeInfo elaborated_type_info =
-        getASTContext()->getTypeInfo(elaborated_qual_type);
+        getASTContext().getTypeInfo(elaborated_qual_type);
     uint64_t elaborated_byte_size = elaborated_type_info.Width / 8;
 
     return elaborated_clang_type.DumpValue(
@@ -8502,7 +8486,7 @@ void ClangASTContext::DumpValue(
 
     lldb::Format desugar_format = desugar_clang_type.GetFormat();
     clang::TypeInfo desugar_type_info =
-        getASTContext()->getTypeInfo(desugar_qual_type);
+        getASTContext().getTypeInfo(desugar_qual_type);
     uint64_t desugar_byte_size = desugar_type_info.Width / 8;
 
     return desugar_clang_type.DumpValue(
@@ -8643,7 +8627,7 @@ bool ClangASTContext::DumpTypeValue(
       if (format == eFormatDefault)
         format = typedef_clang_type.GetFormat();
       clang::TypeInfo typedef_type_info =
-          getASTContext()->getTypeInfo(typedef_qual_type);
+          getASTContext().getTypeInfo(typedef_qual_type);
       uint64_t typedef_byte_size = typedef_type_info.Width / 8;
 
       return typedef_clang_type.DumpTypeValue(
@@ -8788,7 +8772,7 @@ void ClangASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type) {
   CompilerType ct(this, type);
   const clang::Type *clang_type = ClangUtil::GetQualType(ct).getTypePtr();
   ClangASTMetadata *metadata =
-      ClangASTContext::GetMetadata(getASTContext(), clang_type);
+      ClangASTContext::GetMetadata(&getASTContext(), clang_type);
   if (metadata) {
     metadata->Dump(&s);
   }
@@ -8816,7 +8800,7 @@ void ClangASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type,
         clang::ObjCInterfaceDecl *class_interface_decl =
             objc_class_type->getInterface();
         if (class_interface_decl) {
-          clang::PrintingPolicy policy = getASTContext()->getPrintingPolicy();
+          clang::PrintingPolicy policy = getASTContext().getPrintingPolicy();
           class_interface_decl->print(llvm_ostrm, policy, s->GetIndentLevel());
         }
       }
@@ -8846,10 +8830,10 @@ void ClangASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type,
           llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
 
       if (cxx_record_decl)
-        cxx_record_decl->print(llvm_ostrm, getASTContext()->getPrintingPolicy(),
+        cxx_record_decl->print(llvm_ostrm, getASTContext().getPrintingPolicy(),
                                s->GetIndentLevel());
       else
-        record_decl->print(llvm_ostrm, getASTContext()->getPrintingPolicy(),
+        record_decl->print(llvm_ostrm, getASTContext().getPrintingPolicy(),
                            s->GetIndentLevel());
     } break;
 
@@ -9428,7 +9412,7 @@ ClangASTContext::DeclContextGetClangASTContext(const CompilerDeclContext &dc) {
   ClangASTContext *ast =
       llvm::dyn_cast_or_null<ClangASTContext>(dc.GetTypeSystem());
   if (ast)
-    return ast->getASTContext();
+    return &ast->getASTContext();
   return nullptr;
 }
 

diff  --git a/lldb/source/Symbol/ClangASTImporter.cpp b/lldb/source/Symbol/ClangASTImporter.cpp
index 7bdbe2bcc1dc..2f1b350d96e5 100644
--- a/lldb/source/Symbol/ClangASTImporter.cpp
+++ b/lldb/source/Symbol/ClangASTImporter.cpp
@@ -27,26 +27,22 @@ using namespace clang;
 
 CompilerType ClangASTImporter::CopyType(ClangASTContext &dst_ast,
                                         const CompilerType &src_type) {
-  clang::ASTContext *dst_clang_ast = dst_ast.getASTContext();
-  if (!dst_clang_ast)
-    return CompilerType();
+  clang::ASTContext &dst_clang_ast = dst_ast.getASTContext();
 
   ClangASTContext *src_ast =
       llvm::dyn_cast_or_null<ClangASTContext>(src_type.GetTypeSystem());
   if (!src_ast)
     return CompilerType();
 
-  clang::ASTContext *src_clang_ast = src_ast->getASTContext();
-  if (!src_clang_ast)
-    return CompilerType();
+  clang::ASTContext &src_clang_ast = src_ast->getASTContext();
 
   clang::QualType src_qual_type = ClangUtil::GetQualType(src_type);
 
-  ImporterDelegateSP delegate_sp(GetDelegate(dst_clang_ast, src_clang_ast));
+  ImporterDelegateSP delegate_sp(GetDelegate(&dst_clang_ast, &src_clang_ast));
   if (!delegate_sp)
     return CompilerType();
 
-  ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_clang_ast);
+  ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, &dst_clang_ast);
 
   llvm::Expected<QualType> ret_or_error = delegate_sp->Import(src_qual_type);
   if (!ret_or_error) {
@@ -307,15 +303,15 @@ CompilerType ClangASTImporter::DeportType(ClangASTContext &dst,
            "    [ClangASTImporter] DeportType called on ({0}Type*){1:x} "
            "from (ASTContext*){2:x} to (ASTContext*){3:x}",
            src_type.GetTypeName(), src_type.GetOpaqueQualType(),
-           src_ctxt->getASTContext(), dst.getASTContext());
+           &src_ctxt->getASTContext(), &dst.getASTContext());
 
   DeclContextOverride decl_context_override;
 
   if (auto *t = ClangUtil::GetQualType(src_type)->getAs<TagType>())
     decl_context_override.OverrideAllDeclsFromContainingFunction(t->getDecl());
 
-  CompleteTagDeclsScope complete_scope(*this, dst.getASTContext(),
-                                       src_ctxt->getASTContext());
+  CompleteTagDeclsScope complete_scope(*this, &dst.getASTContext(),
+                                       &src_ctxt->getASTContext());
   return CopyType(dst, src_type);
 }
 

diff  --git a/lldb/tools/lldb-test/lldb-test.cpp b/lldb/tools/lldb-test/lldb-test.cpp
index 12e4a5605979..66c9a87301ea 100644
--- a/lldb/tools/lldb-test/lldb-test.cpp
+++ b/lldb/tools/lldb-test/lldb-test.cpp
@@ -603,11 +603,9 @@ Error opts::symbols::dumpAST(lldb_private::Module &Module) {
   if (!clang_ast_ctx)
     return make_string_error("Retrieved TypeSystem was not a ClangASTContext");
 
-  auto ast_ctx = clang_ast_ctx->getASTContext();
-  if (!ast_ctx)
-    return make_string_error("Can't retrieve AST context.");
+  clang::ASTContext &ast_ctx = clang_ast_ctx->getASTContext();
 
-  clang::TranslationUnitDecl *tu = ast_ctx->getTranslationUnitDecl();
+  clang::TranslationUnitDecl *tu = ast_ctx.getTranslationUnitDecl();
   if (!tu)
     return make_string_error("Can't retrieve translation unit declaration.");
 

diff  --git a/lldb/unittests/Expression/ClangExpressionDeclMapTest.cpp b/lldb/unittests/Expression/ClangExpressionDeclMapTest.cpp
index 12ba5fc1592f..299c41f1d33e 100644
--- a/lldb/unittests/Expression/ClangExpressionDeclMapTest.cpp
+++ b/lldb/unittests/Expression/ClangExpressionDeclMapTest.cpp
@@ -33,7 +33,7 @@ struct FakeClangExpressionDeclMap : public ClangExpressionDeclMap {
     // persistent declaration and must be inside the scratch AST context.
     assert(d);
     assert(d->getName().startswith("$"));
-    assert(&d->getASTContext() == m_scratch_context->getASTContext());
+    assert(&d->getASTContext() == &m_scratch_context->getASTContext());
     m_persistent_decls[d->getName()] = d;
   }
 

diff  --git a/lldb/unittests/Symbol/TestClangASTContext.cpp b/lldb/unittests/Symbol/TestClangASTContext.cpp
index 4c9e4d75efd0..9cdcf323429c 100644
--- a/lldb/unittests/Symbol/TestClangASTContext.cpp
+++ b/lldb/unittests/Symbol/TestClangASTContext.cpp
@@ -52,67 +52,66 @@ class TestClangASTContext : public testing::Test {
 };
 
 TEST_F(TestClangASTContext, TestGetBasicTypeFromEnum) {
-  clang::ASTContext *context = m_ast->getASTContext();
+  clang::ASTContext &context = m_ast->getASTContext();
 
   EXPECT_TRUE(
-      context->hasSameType(GetBasicQualType(eBasicTypeBool), context->BoolTy));
+      context.hasSameType(GetBasicQualType(eBasicTypeBool), context.BoolTy));
   EXPECT_TRUE(
-      context->hasSameType(GetBasicQualType(eBasicTypeChar), context->CharTy));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeChar16),
-                                   context->Char16Ty));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeChar32),
-                                   context->Char32Ty));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeDouble),
-                                   context->DoubleTy));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeDoubleComplex),
-                                   context->DoubleComplexTy));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeFloat),
-                                   context->FloatTy));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeFloatComplex),
-                                   context->FloatComplexTy));
+      context.hasSameType(GetBasicQualType(eBasicTypeChar), context.CharTy));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeChar16),
+                                  context.Char16Ty));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeChar32),
+                                  context.Char32Ty));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeDouble),
+                                  context.DoubleTy));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeDoubleComplex),
+                                  context.DoubleComplexTy));
   EXPECT_TRUE(
-      context->hasSameType(GetBasicQualType(eBasicTypeHalf), context->HalfTy));
+      context.hasSameType(GetBasicQualType(eBasicTypeFloat), context.FloatTy));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeFloatComplex),
+                                  context.FloatComplexTy));
   EXPECT_TRUE(
-      context->hasSameType(GetBasicQualType(eBasicTypeInt), context->IntTy));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeInt128),
-                                   context->Int128Ty));
+      context.hasSameType(GetBasicQualType(eBasicTypeHalf), context.HalfTy));
   EXPECT_TRUE(
-      context->hasSameType(GetBasicQualType(eBasicTypeLong), context->LongTy));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeLongDouble),
-                                   context->LongDoubleTy));
+      context.hasSameType(GetBasicQualType(eBasicTypeInt), context.IntTy));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeInt128),
+                                  context.Int128Ty));
   EXPECT_TRUE(
-      context->hasSameType(GetBasicQualType(eBasicTypeLongDoubleComplex),
-                           context->LongDoubleComplexTy));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeLongLong),
-                                   context->LongLongTy));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeNullPtr),
-                                   context->NullPtrTy));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeObjCClass),
-                                   context->getObjCClassType()));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeObjCID),
-                                   context->getObjCIdType()));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeObjCSel),
-                                   context->getObjCSelType()));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeShort),
-                                   context->ShortTy));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeSignedChar),
-                                   context->SignedCharTy));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeUnsignedChar),
-                                   context->UnsignedCharTy));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeUnsignedInt),
-                                   context->UnsignedIntTy));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeUnsignedInt128),
-                                   context->UnsignedInt128Ty));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeUnsignedLong),
-                                   context->UnsignedLongTy));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeUnsignedLongLong),
-                                   context->UnsignedLongLongTy));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeUnsignedShort),
-                                   context->UnsignedShortTy));
+      context.hasSameType(GetBasicQualType(eBasicTypeLong), context.LongTy));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeLongDouble),
+                                  context.LongDoubleTy));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeLongDoubleComplex),
+                                  context.LongDoubleComplexTy));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeLongLong),
+                                  context.LongLongTy));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeNullPtr),
+                                  context.NullPtrTy));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeObjCClass),
+                                  context.getObjCClassType()));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeObjCID),
+                                  context.getObjCIdType()));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeObjCSel),
+                                  context.getObjCSelType()));
   EXPECT_TRUE(
-      context->hasSameType(GetBasicQualType(eBasicTypeVoid), context->VoidTy));
-  EXPECT_TRUE(context->hasSameType(GetBasicQualType(eBasicTypeWChar),
-                                   context->WCharTy));
+      context.hasSameType(GetBasicQualType(eBasicTypeShort), context.ShortTy));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeSignedChar),
+                                  context.SignedCharTy));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeUnsignedChar),
+                                  context.UnsignedCharTy));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeUnsignedInt),
+                                  context.UnsignedIntTy));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeUnsignedInt128),
+                                  context.UnsignedInt128Ty));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeUnsignedLong),
+                                  context.UnsignedLongTy));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeUnsignedLongLong),
+                                  context.UnsignedLongLongTy));
+  EXPECT_TRUE(context.hasSameType(GetBasicQualType(eBasicTypeUnsignedShort),
+                                  context.UnsignedShortTy));
+  EXPECT_TRUE(
+      context.hasSameType(GetBasicQualType(eBasicTypeVoid), context.VoidTy));
+  EXPECT_TRUE(
+      context.hasSameType(GetBasicQualType(eBasicTypeWChar), context.WCharTy));
 }
 
 TEST_F(TestClangASTContext, TestGetBasicTypeFromName) {
@@ -168,7 +167,7 @@ TEST_F(TestClangASTContext, TestGetBasicTypeFromName) {
 
 void VerifyEncodingAndBitSize(ClangASTContext &clang_context,
                               lldb::Encoding encoding, unsigned int bit_size) {
-  clang::ASTContext *context = clang_context.getASTContext();
+  clang::ASTContext &context = clang_context.getASTContext();
 
   CompilerType type =
       clang_context.GetBuiltinTypeForEncodingAndBitSize(encoding, bit_size);
@@ -179,7 +178,7 @@ void VerifyEncodingAndBitSize(ClangASTContext &clang_context,
   if (qtype.isNull())
     return;
 
-  uint64_t actual_size = context->getTypeSize(qtype);
+  uint64_t actual_size = context.getTypeSize(qtype);
   EXPECT_EQ(bit_size, actual_size);
 
   const clang::Type *type_ptr = qtype.getTypePtr();
@@ -229,9 +228,9 @@ TEST_F(TestClangASTContext, TestBuiltinTypeForEncodingAndBitSize) {
 }
 
 TEST_F(TestClangASTContext, TestIsClangType) {
-  clang::ASTContext *context = m_ast->getASTContext();
+  clang::ASTContext &context = m_ast->getASTContext();
   lldb::opaque_compiler_type_t bool_ctype =
-      ClangASTContext::GetOpaqueCompilerType(context, lldb::eBasicTypeBool);
+      ClangASTContext::GetOpaqueCompilerType(&context, lldb::eBasicTypeBool);
   CompilerType bool_type(m_ast.get(), bool_ctype);
   CompilerType record_type = m_ast->CreateRecordType(
       nullptr, lldb::eAccessPublic, "FooRecord", clang::TTK_Struct,
@@ -392,11 +391,11 @@ TEST_F(TestClangASTContext, TestRecordHasFields) {
 TEST_F(TestClangASTContext, TemplateArguments) {
   ClangASTContext::TemplateParameterInfos infos;
   infos.names.push_back("T");
-  infos.args.push_back(TemplateArgument(m_ast->getASTContext()->IntTy));
+  infos.args.push_back(TemplateArgument(m_ast->getASTContext().IntTy));
   infos.names.push_back("I");
   llvm::APSInt arg(llvm::APInt(8, 47));
-  infos.args.push_back(TemplateArgument(*m_ast->getASTContext(), arg,
-                                        m_ast->getASTContext()->IntTy));
+  infos.args.push_back(TemplateArgument(m_ast->getASTContext(), arg,
+                                        m_ast->getASTContext().IntTy));
 
   // template<typename T, int I> struct foo;
   ClassTemplateDecl *decl = m_ast->CreateClassTemplateDecl(
@@ -421,11 +420,12 @@ TEST_F(TestClangASTContext, TemplateArguments) {
   CompilerType auto_type(
       m_ast.get(),
       m_ast->getASTContext()
-          ->getAutoType(ClangUtil::GetCanonicalQualType(typedef_type),
-                        clang::AutoTypeKeyword::Auto, false)
+          .getAutoType(ClangUtil::GetCanonicalQualType(typedef_type),
+                       clang::AutoTypeKeyword::Auto, false)
           .getAsOpaquePtr());
 
-  CompilerType int_type(m_ast.get(), m_ast->getASTContext()->IntTy.getAsOpaquePtr());
+  CompilerType int_type(m_ast.get(),
+                        m_ast->getASTContext().IntTy.getAsOpaquePtr());
   for (CompilerType t : {type, typedef_type, auto_type}) {
     SCOPED_TRACE(t.GetTypeName().AsCString());
 
@@ -454,27 +454,27 @@ static QualType makeConstInt(clang::ASTContext &ctxt) {
 }
 
 TEST_F(TestClangASTContext, TestGetTypeClassDeclType) {
-  clang::ASTContext &ctxt = *m_ast->getASTContext();
+  clang::ASTContext &ctxt = m_ast->getASTContext();
   auto *nullptr_expr = new (ctxt) CXXNullPtrLiteralExpr(ctxt.NullPtrTy, SourceLocation());
   QualType t = ctxt.getDecltypeType(nullptr_expr, makeConstInt(ctxt));
   EXPECT_EQ(lldb::eTypeClassBuiltin, m_ast->GetTypeClass(t.getAsOpaquePtr()));
 }
 
 TEST_F(TestClangASTContext, TestGetTypeClassTypeOf) {
-  clang::ASTContext &ctxt = *m_ast->getASTContext();
+  clang::ASTContext &ctxt = m_ast->getASTContext();
   QualType t = ctxt.getTypeOfType(makeConstInt(ctxt));
   EXPECT_EQ(lldb::eTypeClassBuiltin, m_ast->GetTypeClass(t.getAsOpaquePtr()));
 }
 
 TEST_F(TestClangASTContext, TestGetTypeClassTypeOfExpr) {
-  clang::ASTContext &ctxt = *m_ast->getASTContext();
+  clang::ASTContext &ctxt = m_ast->getASTContext();
   auto *nullptr_expr = new (ctxt) CXXNullPtrLiteralExpr(ctxt.NullPtrTy, SourceLocation());
   QualType t = ctxt.getTypeOfExprType(nullptr_expr);
   EXPECT_EQ(lldb::eTypeClassBuiltin, m_ast->GetTypeClass(t.getAsOpaquePtr()));
 }
 
 TEST_F(TestClangASTContext, TestGetTypeClassNested) {
-  clang::ASTContext &ctxt = *m_ast->getASTContext();
+  clang::ASTContext &ctxt = m_ast->getASTContext();
   QualType t_base = ctxt.getTypeOfType(makeConstInt(ctxt));
   QualType t = ctxt.getTypeOfType(t_base);
   EXPECT_EQ(lldb::eTypeClassBuiltin, m_ast->GetTypeClass(t.getAsOpaquePtr()));

diff  --git a/lldb/unittests/Symbol/TestClangASTImporter.cpp b/lldb/unittests/Symbol/TestClangASTImporter.cpp
index 9a03f854db1a..09e756572b40 100644
--- a/lldb/unittests/Symbol/TestClangASTImporter.cpp
+++ b/lldb/unittests/Symbol/TestClangASTImporter.cpp
@@ -53,7 +53,7 @@ TEST_F(TestClangASTImporter, CopyDeclTagDecl) {
 
   ClangASTImporter importer;
   clang::Decl *imported =
-      importer.CopyDecl(target_ast->getASTContext(), source.record_decl);
+      importer.CopyDecl(&target_ast->getASTContext(), source.record_decl);
   ASSERT_NE(nullptr, imported);
 
   // Check that we got the correct decl by just comparing their qualified name.
@@ -66,7 +66,7 @@ TEST_F(TestClangASTImporter, CopyDeclTagDecl) {
   // Check that origin was set for the imported declaration.
   ClangASTImporter::DeclOrigin origin = importer.GetDeclOrigin(imported);
   EXPECT_TRUE(origin.Valid());
-  EXPECT_EQ(origin.ctx, source.ast->getASTContext());
+  EXPECT_EQ(origin.ctx, &source.ast->getASTContext());
   EXPECT_EQ(origin.decl, source.record_decl);
 }
 
@@ -91,7 +91,7 @@ TEST_F(TestClangASTImporter, CopyTypeTagDecl) {
   ClangASTImporter::DeclOrigin origin =
       importer.GetDeclOrigin(imported_tag_decl);
   EXPECT_TRUE(origin.Valid());
-  EXPECT_EQ(origin.ctx, source.ast->getASTContext());
+  EXPECT_EQ(origin.ctx, &source.ast->getASTContext());
   EXPECT_EQ(origin.decl, source.record_decl);
 }
 
@@ -103,7 +103,7 @@ TEST_F(TestClangASTImporter, DeportDeclTagDecl) {
 
   ClangASTImporter importer;
   clang::Decl *imported =
-      importer.DeportDecl(target_ast->getASTContext(), source.record_decl);
+      importer.DeportDecl(&target_ast->getASTContext(), source.record_decl);
   ASSERT_NE(nullptr, imported);
 
   // Check that we got the correct decl by just comparing their qualified name.
@@ -150,7 +150,7 @@ TEST_F(TestClangASTImporter, MetadataPropagation) {
 
   ClangASTImporter importer;
   clang::Decl *imported =
-      importer.CopyDecl(target_ast->getASTContext(), source.record_decl);
+      importer.CopyDecl(&target_ast->getASTContext(), source.record_decl);
   ASSERT_NE(nullptr, imported);
 
   // Check that we got the same Metadata.
@@ -172,12 +172,12 @@ TEST_F(TestClangASTImporter, MetadataPropagationIndirectImport) {
 
   ClangASTImporter importer;
   clang::Decl *temporary_imported =
-      importer.CopyDecl(temporary_ast->getASTContext(), source.record_decl);
+      importer.CopyDecl(&temporary_ast->getASTContext(), source.record_decl);
   ASSERT_NE(nullptr, temporary_imported);
 
   std::unique_ptr<ClangASTContext> target_ast = clang_utils::createAST();
   clang::Decl *imported =
-      importer.CopyDecl(target_ast->getASTContext(), temporary_imported);
+      importer.CopyDecl(&target_ast->getASTContext(), temporary_imported);
   ASSERT_NE(nullptr, imported);
 
   // Check that we got the same Metadata.
@@ -196,7 +196,7 @@ TEST_F(TestClangASTImporter, MetadataPropagationAfterCopying) {
 
   ClangASTImporter importer;
   clang::Decl *imported =
-      importer.CopyDecl(target_ast->getASTContext(), source.record_decl);
+      importer.CopyDecl(&target_ast->getASTContext(), source.record_decl);
   ASSERT_NE(nullptr, imported);
 
   // The TagDecl has been imported. Now set the metadata of the source and

diff  --git a/lldb/unittests/TestingSupport/Symbol/ClangTestUtils.h b/lldb/unittests/TestingSupport/Symbol/ClangTestUtils.h
index f9590825e075..2c94aa5d01ce 100644
--- a/lldb/unittests/TestingSupport/Symbol/ClangTestUtils.h
+++ b/lldb/unittests/TestingSupport/Symbol/ClangTestUtils.h
@@ -17,8 +17,8 @@ namespace lldb_private {
 namespace clang_utils {
 inline clang::DeclarationName getDeclarationName(ClangASTContext &ast,
                                                  llvm::StringRef name) {
-  clang::IdentifierInfo &II = ast.getASTContext()->Idents.get(name);
-  return ast.getASTContext()->DeclarationNames.getIdentifier(&II);
+  clang::IdentifierInfo &II = ast.getASTContext().Idents.get(name);
+  return ast.getASTContext().DeclarationNames.getIdentifier(&II);
 }
 
 inline std::unique_ptr<ClangASTContext> createAST() {
@@ -26,7 +26,7 @@ inline std::unique_ptr<ClangASTContext> createAST() {
 }
 
 inline CompilerType createRecord(ClangASTContext &ast, llvm::StringRef name) {
-  return ast.CreateRecordType(ast.getASTContext()->getTranslationUnitDecl(),
+  return ast.CreateRecordType(ast.getASTContext().getTranslationUnitDecl(),
                               lldb::AccessType::eAccessPublic, name, 0,
                               lldb::LanguageType::eLanguageTypeC);
 }


        


More information about the lldb-commits mailing list