xiaobai created this revision.
xiaobai added reviewers: compnerd, aprantl, JDevlieghere, davide.
Herald added a project: LLDB.
xiaobai added a reviewer: labath.

Ideally CompilerType would have no knowledge of clang or any individual
TypeSystem. Decoupling clang is relatively straightforward.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66102

Files:
  lldb/include/lldb/Symbol/ClangASTContext.h
  lldb/include/lldb/Symbol/CompilerType.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
  lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
  lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.h
  lldb/source/Plugins/Language/ObjC/NSArray.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
  lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
  lldb/source/Symbol/ClangASTContext.cpp
  lldb/source/Symbol/CompilerType.cpp
  lldb/unittests/Symbol/TestClangASTContext.cpp

Index: lldb/unittests/Symbol/TestClangASTContext.cpp
===================================================================
--- lldb/unittests/Symbol/TestClangASTContext.cpp
+++ lldb/unittests/Symbol/TestClangASTContext.cpp
@@ -422,12 +422,14 @@
       type, "foo_def",
       CompilerDeclContext(m_ast.get(), m_ast->GetTranslationUnitDecl()));
 
-  CompilerType auto_type(m_ast->getASTContext(),
-                         m_ast->getASTContext()->getAutoType(
-                             ClangUtil::GetCanonicalQualType(typedef_type),
-                             clang::AutoTypeKeyword::Auto, false));
-
-  CompilerType int_type(m_ast->getASTContext(), m_ast->getASTContext()->IntTy);
+  CompilerType auto_type(
+      m_ast.get(),
+      m_ast->getASTContext()
+          ->getAutoType(ClangUtil::GetCanonicalQualType(typedef_type),
+                        clang::AutoTypeKeyword::Auto, false)
+          .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());
 
Index: lldb/source/Symbol/CompilerType.cpp
===================================================================
--- lldb/source/Symbol/CompilerType.cpp
+++ lldb/source/Symbol/CompilerType.cpp
@@ -10,8 +10,6 @@
 
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/StreamFile.h"
-#include "lldb/Symbol/ClangASTContext.h"
-#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
 #include "lldb/Symbol/Type.h"
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/Process.h"
@@ -32,13 +30,6 @@
                            lldb::opaque_compiler_type_t type)
     : m_type(type), m_type_system(type_system) {}
 
-CompilerType::CompilerType(clang::ASTContext *ast, clang::QualType qual_type)
-    : m_type(qual_type.getAsOpaquePtr()),
-      m_type_system(ClangASTContext::GetASTContext(ast)) {
-  if (m_type)
-    assert(m_type_system != nullptr);
-}
-
 CompilerType::~CompilerType() {}
 
 // Tests
@@ -333,12 +324,6 @@
   m_type = type;
 }
 
-void CompilerType::SetCompilerType(clang::ASTContext *ast,
-                                   clang::QualType qual_type) {
-  m_type_system = ClangASTContext::GetASTContext(ast);
-  m_type = qual_type.getAsOpaquePtr();
-}
-
 unsigned CompilerType::GetTypeQualifiers() const {
   if (IsValid())
     return m_type_system->GetTypeQualifiers(m_type);
Index: lldb/source/Symbol/ClangASTContext.cpp
===================================================================
--- lldb/source/Symbol/ClangASTContext.cpp
+++ lldb/source/Symbol/ClangASTContext.cpp
@@ -1010,60 +1010,71 @@
 
 CompilerType ClangASTContext::GetBuiltinTypeForEncodingAndBitSize(
     ASTContext *ast, Encoding encoding, uint32_t bit_size) {
+  auto *clang_ast_context = ClangASTContext::GetASTContext(ast);
   if (!ast)
     return CompilerType();
   switch (encoding) {
   case eEncodingInvalid:
     if (QualTypeMatchesBitSize(bit_size, ast, ast->VoidPtrTy))
-      return CompilerType(ast, ast->VoidPtrTy);
+      return CompilerType(clang_ast_context, ast->VoidPtrTy.getAsOpaquePtr());
     break;
 
   case eEncodingUint:
     if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy))
-      return CompilerType(ast, ast->UnsignedCharTy);
+      return CompilerType(clang_ast_context,
+                          ast->UnsignedCharTy.getAsOpaquePtr());
     if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy))
-      return CompilerType(ast, ast->UnsignedShortTy);
+      return CompilerType(clang_ast_context,
+                          ast->UnsignedShortTy.getAsOpaquePtr());
     if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedIntTy))
-      return CompilerType(ast, ast->UnsignedIntTy);
+      return CompilerType(clang_ast_context,
+                          ast->UnsignedIntTy.getAsOpaquePtr());
     if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongTy))
-      return CompilerType(ast, ast->UnsignedLongTy);
+      return CompilerType(clang_ast_context,
+                          ast->UnsignedLongTy.getAsOpaquePtr());
     if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongLongTy))
-      return CompilerType(ast, ast->UnsignedLongLongTy);
+      return CompilerType(clang_ast_context,
+                          ast->UnsignedLongLongTy.getAsOpaquePtr());
     if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedInt128Ty))
-      return CompilerType(ast, ast->UnsignedInt128Ty);
+      return CompilerType(clang_ast_context,
+                          ast->UnsignedInt128Ty.getAsOpaquePtr());
     break;
 
   case eEncodingSint:
     if (QualTypeMatchesBitSize(bit_size, ast, ast->SignedCharTy))
-      return CompilerType(ast, ast->SignedCharTy);
+      return CompilerType(clang_ast_context,
+                          ast->SignedCharTy.getAsOpaquePtr());
     if (QualTypeMatchesBitSize(bit_size, ast, ast->ShortTy))
-      return CompilerType(ast, ast->ShortTy);
+      return CompilerType(clang_ast_context, ast->ShortTy.getAsOpaquePtr());
     if (QualTypeMatchesBitSize(bit_size, ast, ast->IntTy))
-      return CompilerType(ast, ast->IntTy);
+      return CompilerType(clang_ast_context, ast->IntTy.getAsOpaquePtr());
     if (QualTypeMatchesBitSize(bit_size, ast, ast->LongTy))
-      return CompilerType(ast, ast->LongTy);
+      return CompilerType(clang_ast_context, ast->LongTy.getAsOpaquePtr());
     if (QualTypeMatchesBitSize(bit_size, ast, ast->LongLongTy))
-      return CompilerType(ast, ast->LongLongTy);
+      return CompilerType(clang_ast_context, ast->LongLongTy.getAsOpaquePtr());
     if (QualTypeMatchesBitSize(bit_size, ast, ast->Int128Ty))
-      return CompilerType(ast, ast->Int128Ty);
+      return CompilerType(clang_ast_context, ast->Int128Ty.getAsOpaquePtr());
     break;
 
   case eEncodingIEEE754:
     if (QualTypeMatchesBitSize(bit_size, ast, ast->FloatTy))
-      return CompilerType(ast, ast->FloatTy);
+      return CompilerType(clang_ast_context, ast->FloatTy.getAsOpaquePtr());
     if (QualTypeMatchesBitSize(bit_size, ast, ast->DoubleTy))
-      return CompilerType(ast, ast->DoubleTy);
+      return CompilerType(clang_ast_context, ast->DoubleTy.getAsOpaquePtr());
     if (QualTypeMatchesBitSize(bit_size, ast, ast->LongDoubleTy))
-      return CompilerType(ast, ast->LongDoubleTy);
+      return CompilerType(clang_ast_context,
+                          ast->LongDoubleTy.getAsOpaquePtr());
     if (QualTypeMatchesBitSize(bit_size, ast, ast->HalfTy))
-      return CompilerType(ast, ast->HalfTy);
+      return CompilerType(clang_ast_context, 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(
-          ast, ast->getExtVectorType(ast->UnsignedCharTy, bit_size / 8));
+          clang_ast_context,
+          ast->getExtVectorType(ast->UnsignedCharTy, bit_size / 8)
+              .getAsOpaquePtr());
     break;
   }
 
@@ -1183,18 +1194,18 @@
 
     case DW_ATE_address:
       if (QualTypeMatchesBitSize(bit_size, ast, ast->VoidPtrTy))
-        return CompilerType(ast, ast->VoidPtrTy);
+        return CompilerType(this, ast->VoidPtrTy.getAsOpaquePtr());
       break;
 
     case DW_ATE_boolean:
       if (QualTypeMatchesBitSize(bit_size, ast, ast->BoolTy))
-        return CompilerType(ast, ast->BoolTy);
+        return CompilerType(this, ast->BoolTy.getAsOpaquePtr());
       if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy))
-        return CompilerType(ast, ast->UnsignedCharTy);
+        return CompilerType(this, ast->UnsignedCharTy.getAsOpaquePtr());
       if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy))
-        return CompilerType(ast, ast->UnsignedShortTy);
+        return CompilerType(this, ast->UnsignedShortTy.getAsOpaquePtr());
       if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedIntTy))
-        return CompilerType(ast, ast->UnsignedIntTy);
+        return CompilerType(this, ast->UnsignedIntTy.getAsOpaquePtr());
       break;
 
     case DW_ATE_lo_user:
@@ -1204,47 +1215,51 @@
           CompilerType complex_int_clang_type =
               GetBuiltinTypeForDWARFEncodingAndBitSize("int", DW_ATE_signed,
                                                        bit_size / 2);
-          return CompilerType(ast, ast->getComplexType(ClangUtil::GetQualType(
-                                       complex_int_clang_type)));
+          return CompilerType(
+              this, ast->getComplexType(
+                           ClangUtil::GetQualType(complex_int_clang_type))
+                        .getAsOpaquePtr());
         }
       }
       break;
 
     case DW_ATE_complex_float:
       if (QualTypeMatchesBitSize(bit_size, ast, ast->FloatComplexTy))
-        return CompilerType(ast, ast->FloatComplexTy);
+        return CompilerType(this, ast->FloatComplexTy.getAsOpaquePtr());
       else if (QualTypeMatchesBitSize(bit_size, ast, ast->DoubleComplexTy))
-        return CompilerType(ast, ast->DoubleComplexTy);
+        return CompilerType(this, ast->DoubleComplexTy.getAsOpaquePtr());
       else if (QualTypeMatchesBitSize(bit_size, ast, ast->LongDoubleComplexTy))
-        return CompilerType(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(ast, ast->getComplexType(ClangUtil::GetQualType(
-                                     complex_float_clang_type)));
+        return CompilerType(
+            this, ast->getComplexType(
+                         ClangUtil::GetQualType(complex_float_clang_type))
+                      .getAsOpaquePtr());
       }
       break;
 
     case DW_ATE_float:
       if (streq(type_name, "float") &&
           QualTypeMatchesBitSize(bit_size, ast, ast->FloatTy))
-        return CompilerType(ast, ast->FloatTy);
+        return CompilerType(this, ast->FloatTy.getAsOpaquePtr());
       if (streq(type_name, "double") &&
           QualTypeMatchesBitSize(bit_size, ast, ast->DoubleTy))
-        return CompilerType(ast, ast->DoubleTy);
+        return CompilerType(this, ast->DoubleTy.getAsOpaquePtr());
       if (streq(type_name, "long double") &&
           QualTypeMatchesBitSize(bit_size, ast, ast->LongDoubleTy))
-        return CompilerType(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(ast, ast->FloatTy);
+        return CompilerType(this, ast->FloatTy.getAsOpaquePtr());
       if (QualTypeMatchesBitSize(bit_size, ast, ast->DoubleTy))
-        return CompilerType(ast, ast->DoubleTy);
+        return CompilerType(this, ast->DoubleTy.getAsOpaquePtr());
       if (QualTypeMatchesBitSize(bit_size, ast, ast->LongDoubleTy))
-        return CompilerType(ast, ast->LongDoubleTy);
+        return CompilerType(this, ast->LongDoubleTy.getAsOpaquePtr());
       if (QualTypeMatchesBitSize(bit_size, ast, ast->HalfTy))
-        return CompilerType(ast, ast->HalfTy);
+        return CompilerType(this, ast->HalfTy.getAsOpaquePtr());
       break;
 
     case DW_ATE_signed:
@@ -1253,55 +1268,55 @@
             QualTypeMatchesBitSize(bit_size, ast, ast->WCharTy) &&
             (getTargetInfo() &&
              TargetInfo::isTypeSigned(getTargetInfo()->getWCharType())))
-          return CompilerType(ast, ast->WCharTy);
+          return CompilerType(this, ast->WCharTy.getAsOpaquePtr());
         if (streq(type_name, "void") &&
             QualTypeMatchesBitSize(bit_size, ast, ast->VoidTy))
-          return CompilerType(ast, ast->VoidTy);
+          return CompilerType(this, ast->VoidTy.getAsOpaquePtr());
         if (strstr(type_name, "long long") &&
             QualTypeMatchesBitSize(bit_size, ast, ast->LongLongTy))
-          return CompilerType(ast, ast->LongLongTy);
+          return CompilerType(this, ast->LongLongTy.getAsOpaquePtr());
         if (strstr(type_name, "long") &&
             QualTypeMatchesBitSize(bit_size, ast, ast->LongTy))
-          return CompilerType(ast, ast->LongTy);
+          return CompilerType(this, ast->LongTy.getAsOpaquePtr());
         if (strstr(type_name, "short") &&
             QualTypeMatchesBitSize(bit_size, ast, ast->ShortTy))
-          return CompilerType(ast, ast->ShortTy);
+          return CompilerType(this, ast->ShortTy.getAsOpaquePtr());
         if (strstr(type_name, "char")) {
           if (QualTypeMatchesBitSize(bit_size, ast, ast->CharTy))
-            return CompilerType(ast, ast->CharTy);
+            return CompilerType(this, ast->CharTy.getAsOpaquePtr());
           if (QualTypeMatchesBitSize(bit_size, ast, ast->SignedCharTy))
-            return CompilerType(ast, ast->SignedCharTy);
+            return CompilerType(this, ast->SignedCharTy.getAsOpaquePtr());
         }
         if (strstr(type_name, "int")) {
           if (QualTypeMatchesBitSize(bit_size, ast, ast->IntTy))
-            return CompilerType(ast, ast->IntTy);
+            return CompilerType(this, ast->IntTy.getAsOpaquePtr());
           if (QualTypeMatchesBitSize(bit_size, ast, ast->Int128Ty))
-            return CompilerType(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(ast, ast->CharTy);
+        return CompilerType(this, ast->CharTy.getAsOpaquePtr());
       if (QualTypeMatchesBitSize(bit_size, ast, ast->ShortTy))
-        return CompilerType(ast, ast->ShortTy);
+        return CompilerType(this, ast->ShortTy.getAsOpaquePtr());
       if (QualTypeMatchesBitSize(bit_size, ast, ast->IntTy))
-        return CompilerType(ast, ast->IntTy);
+        return CompilerType(this, ast->IntTy.getAsOpaquePtr());
       if (QualTypeMatchesBitSize(bit_size, ast, ast->LongTy))
-        return CompilerType(ast, ast->LongTy);
+        return CompilerType(this, ast->LongTy.getAsOpaquePtr());
       if (QualTypeMatchesBitSize(bit_size, ast, ast->LongLongTy))
-        return CompilerType(ast, ast->LongLongTy);
+        return CompilerType(this, ast->LongLongTy.getAsOpaquePtr());
       if (QualTypeMatchesBitSize(bit_size, ast, ast->Int128Ty))
-        return CompilerType(ast, ast->Int128Ty);
+        return CompilerType(this, ast->Int128Ty.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(ast, ast->CharTy);
+          return CompilerType(this, ast->CharTy.getAsOpaquePtr());
       }
       if (QualTypeMatchesBitSize(bit_size, ast, ast->SignedCharTy))
-        return CompilerType(ast, ast->SignedCharTy);
+        return CompilerType(this, ast->SignedCharTy.getAsOpaquePtr());
       break;
 
     case DW_ATE_unsigned:
@@ -1310,53 +1325,53 @@
           if (QualTypeMatchesBitSize(bit_size, ast, ast->WCharTy)) {
             if (!(getTargetInfo() &&
                   TargetInfo::isTypeSigned(getTargetInfo()->getWCharType())))
-              return CompilerType(ast, ast->WCharTy);
+              return CompilerType(this, ast->WCharTy.getAsOpaquePtr());
           }
         }
         if (strstr(type_name, "long long")) {
           if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongLongTy))
-            return CompilerType(ast, ast->UnsignedLongLongTy);
+            return CompilerType(this, ast->UnsignedLongLongTy.getAsOpaquePtr());
         } else if (strstr(type_name, "long")) {
           if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongTy))
-            return CompilerType(ast, ast->UnsignedLongTy);
+            return CompilerType(this, ast->UnsignedLongTy.getAsOpaquePtr());
         } else if (strstr(type_name, "short")) {
           if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy))
-            return CompilerType(ast, ast->UnsignedShortTy);
+            return CompilerType(this, ast->UnsignedShortTy.getAsOpaquePtr());
         } else if (strstr(type_name, "char")) {
           if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy))
-            return CompilerType(ast, ast->UnsignedCharTy);
+            return CompilerType(this, ast->UnsignedCharTy.getAsOpaquePtr());
         } else if (strstr(type_name, "int")) {
           if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedIntTy))
-            return CompilerType(ast, ast->UnsignedIntTy);
+            return CompilerType(this, ast->UnsignedIntTy.getAsOpaquePtr());
           if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedInt128Ty))
-            return CompilerType(ast, ast->UnsignedInt128Ty);
+            return CompilerType(this, ast->UnsignedInt128Ty.getAsOpaquePtr());
         }
       }
       // We weren't able to match up a type name, just search by size
       if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy))
-        return CompilerType(ast, ast->UnsignedCharTy);
+        return CompilerType(this, ast->UnsignedCharTy.getAsOpaquePtr());
       if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy))
-        return CompilerType(ast, ast->UnsignedShortTy);
+        return CompilerType(this, ast->UnsignedShortTy.getAsOpaquePtr());
       if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedIntTy))
-        return CompilerType(ast, ast->UnsignedIntTy);
+        return CompilerType(this, ast->UnsignedIntTy.getAsOpaquePtr());
       if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongTy))
-        return CompilerType(ast, ast->UnsignedLongTy);
+        return CompilerType(this, ast->UnsignedLongTy.getAsOpaquePtr());
       if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongLongTy))
-        return CompilerType(ast, ast->UnsignedLongLongTy);
+        return CompilerType(this, ast->UnsignedLongLongTy.getAsOpaquePtr());
       if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedInt128Ty))
-        return CompilerType(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(ast, ast->CharTy);
+          return CompilerType(this, ast->CharTy.getAsOpaquePtr());
       }
       if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy))
-        return CompilerType(ast, ast->UnsignedCharTy);
+        return CompilerType(this, ast->UnsignedCharTy.getAsOpaquePtr());
       if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy))
-        return CompilerType(ast, ast->UnsignedShortTy);
+        return CompilerType(this, ast->UnsignedShortTy.getAsOpaquePtr());
       break;
 
     case DW_ATE_imaginary_float:
@@ -1365,9 +1380,9 @@
     case DW_ATE_UTF:
       if (type_name) {
         if (streq(type_name, "char16_t")) {
-          return CompilerType(ast, ast->Char16Ty);
+          return CompilerType(this, ast->Char16Ty.getAsOpaquePtr());
         } else if (streq(type_name, "char32_t")) {
-          return CompilerType(ast, ast->Char32Ty);
+          return CompilerType(this, ast->Char32Ty.getAsOpaquePtr());
         }
       }
       break;
@@ -1391,7 +1406,8 @@
 
 CompilerType ClangASTContext::GetUnknownAnyType(clang::ASTContext *ast) {
   if (ast)
-    return CompilerType(ast, ast->UnknownAnyTy);
+    return CompilerType(ClangASTContext::GetASTContext(ast),
+                        ast->UnknownAnyTy.getAsOpaquePtr());
   return CompilerType();
 }
 
@@ -1402,7 +1418,7 @@
   if (is_const)
     char_type.addConst();
 
-  return CompilerType(ast, ast->getPointerType(char_type));
+  return CompilerType(this, ast->getPointerType(char_type).getAsOpaquePtr());
 }
 
 clang::DeclContext *
@@ -1462,7 +1478,8 @@
   // AST if our AST didn't already exist...
   ASTContext *ast = &decl->getASTContext();
   if (ast)
-    return CompilerType(ast, ast->getTagDeclType(decl));
+    return CompilerType(ClangASTContext::GetASTContext(ast),
+                        ast->getTagDeclType(decl).getAsOpaquePtr());
   return CompilerType();
 }
 
@@ -1472,7 +1489,8 @@
   // AST if our AST didn't already exist...
   ASTContext *ast = &decl->getASTContext();
   if (ast)
-    return CompilerType(ast, ast->getObjCInterfaceType(decl));
+    return CompilerType(ClangASTContext::GetASTContext(ast),
+                        ast->getObjCInterfaceType(decl).getAsOpaquePtr());
   return CompilerType();
 }
 
@@ -1521,7 +1539,7 @@
     if (decl_ctx)
       decl_ctx->addDecl(decl);
 
-    return CompilerType(ast, ast->getTagDeclType(decl));
+    return CompilerType(this, ast->getTagDeclType(decl).getAsOpaquePtr());
   }
   return CompilerType();
 }
@@ -1744,7 +1762,8 @@
     ASTContext *ast = getASTContext();
     if (ast)
       return CompilerType(
-          ast, ast->getTagDeclType(class_template_specialization_decl));
+          this, ast->getTagDeclType(class_template_specialization_decl)
+                    .getAsOpaquePtr());
   }
   return CompilerType();
 }
@@ -1875,7 +1894,7 @@
   if (decl && metadata)
     SetMetadata(ast, decl, *metadata);
 
-  return CompilerType(ast, ast->getObjCInterfaceType(decl));
+  return CompilerType(this, ast->getObjCInterfaceType(decl).getAsOpaquePtr());
 }
 
 static inline bool BaseSpecifierIsEmpty(const CXXBaseSpecifier *b) {
@@ -2221,9 +2240,9 @@
   proto_info.TypeQuals = clang::Qualifiers::fromFastMask(type_quals);
   proto_info.RefQualifier = RQ_None;
 
-  return CompilerType(ast,
+  return CompilerType(ClangASTContext::GetASTContext(ast),
                       ast->getFunctionType(ClangUtil::GetQualType(result_type),
-                                           qual_type_args, proto_info));
+                                           qual_type_args, proto_info).getAsOpaquePtr());
 }
 
 ParmVarDecl *ClangASTContext::CreateParameterDeclaration(
@@ -2268,20 +2287,23 @@
 
     if (is_vector) {
       return CompilerType(
-          ast, 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(ast, ast->getIncompleteArrayType(
-                                     ClangUtil::GetQualType(element_type),
-                                     clang::ArrayType::Normal, 0));
+        return CompilerType(this, ast->getIncompleteArrayType(
+                                         ClangUtil::GetQualType(element_type),
+                                         clang::ArrayType::Normal, 0)
+                                      .getAsOpaquePtr());
       } else {
-        return CompilerType(
-            ast, ast->getConstantArrayType(ClangUtil::GetQualType(element_type),
-                                           ap_element_count,
-                                           clang::ArrayType::Normal, 0));
+        return CompilerType(this, ast->getConstantArrayType(
+                                         ClangUtil::GetQualType(element_type),
+                                         ap_element_count,
+                                         clang::ArrayType::Normal, 0)
+                                      .getAsOpaquePtr());
       }
     }
   }
@@ -2355,7 +2377,7 @@
 
     enum_decl->setAccess(AS_public); // TODO respect what's in the debug info
 
-    return CompilerType(ast, ast->getTagDeclType(enum_decl));
+    return CompilerType(this, ast->getTagDeclType(enum_decl).getAsOpaquePtr());
   }
   return CompilerType();
 }
@@ -2364,42 +2386,51 @@
                                                     size_t bit_size,
                                                     bool is_signed) {
   if (ast) {
+    auto *clang_ast_context = ClangASTContext::GetASTContext(ast);
     if (is_signed) {
       if (bit_size == ast->getTypeSize(ast->SignedCharTy))
-        return CompilerType(ast, ast->SignedCharTy);
+        return CompilerType(clang_ast_context,
+                            ast->SignedCharTy.getAsOpaquePtr());
 
       if (bit_size == ast->getTypeSize(ast->ShortTy))
-        return CompilerType(ast, ast->ShortTy);
+        return CompilerType(clang_ast_context, ast->ShortTy.getAsOpaquePtr());
 
       if (bit_size == ast->getTypeSize(ast->IntTy))
-        return CompilerType(ast, ast->IntTy);
+        return CompilerType(clang_ast_context, ast->IntTy.getAsOpaquePtr());
 
       if (bit_size == ast->getTypeSize(ast->LongTy))
-        return CompilerType(ast, ast->LongTy);
+        return CompilerType(clang_ast_context, ast->LongTy.getAsOpaquePtr());
 
       if (bit_size == ast->getTypeSize(ast->LongLongTy))
-        return CompilerType(ast, ast->LongLongTy);
+        return CompilerType(clang_ast_context,
+                            ast->LongLongTy.getAsOpaquePtr());
 
       if (bit_size == ast->getTypeSize(ast->Int128Ty))
-        return CompilerType(ast, ast->Int128Ty);
+        return CompilerType(clang_ast_context, ast->Int128Ty.getAsOpaquePtr());
     } else {
       if (bit_size == ast->getTypeSize(ast->UnsignedCharTy))
-        return CompilerType(ast, ast->UnsignedCharTy);
+        return CompilerType(clang_ast_context,
+                            ast->UnsignedCharTy.getAsOpaquePtr());
 
       if (bit_size == ast->getTypeSize(ast->UnsignedShortTy))
-        return CompilerType(ast, ast->UnsignedShortTy);
+        return CompilerType(clang_ast_context,
+                            ast->UnsignedShortTy.getAsOpaquePtr());
 
       if (bit_size == ast->getTypeSize(ast->UnsignedIntTy))
-        return CompilerType(ast, ast->UnsignedIntTy);
+        return CompilerType(clang_ast_context,
+                            ast->UnsignedIntTy.getAsOpaquePtr());
 
       if (bit_size == ast->getTypeSize(ast->UnsignedLongTy))
-        return CompilerType(ast, ast->UnsignedLongTy);
+        return CompilerType(clang_ast_context,
+                            ast->UnsignedLongTy.getAsOpaquePtr());
 
       if (bit_size == ast->getTypeSize(ast->UnsignedLongLongTy))
-        return CompilerType(ast, ast->UnsignedLongLongTy);
+        return CompilerType(clang_ast_context,
+                            ast->UnsignedLongLongTy.getAsOpaquePtr());
 
       if (bit_size == ast->getTypeSize(ast->UnsignedInt128Ty))
-        return CompilerType(ast, ast->UnsignedInt128Ty);
+        return CompilerType(clang_ast_context,
+                            ast->UnsignedInt128Ty.getAsOpaquePtr());
     }
   }
   return CompilerType();
@@ -2929,8 +2960,9 @@
   case clang::Type::ConstantArray:
     if (element_type_ptr)
       element_type_ptr->SetCompilerType(
-          getASTContext(),
-          llvm::cast<clang::ConstantArrayType>(qual_type)->getElementType());
+          this, llvm::cast<clang::ConstantArrayType>(qual_type)
+                    ->getElementType()
+                    .getAsOpaquePtr());
     if (size)
       *size = llvm::cast<clang::ConstantArrayType>(qual_type)
                   ->getSize()
@@ -2942,8 +2974,9 @@
   case clang::Type::IncompleteArray:
     if (element_type_ptr)
       element_type_ptr->SetCompilerType(
-          getASTContext(),
-          llvm::cast<clang::IncompleteArrayType>(qual_type)->getElementType());
+          this, llvm::cast<clang::IncompleteArrayType>(qual_type)
+                    ->getElementType()
+                    .getAsOpaquePtr());
     if (size)
       *size = 0;
     if (is_incomplete)
@@ -2953,8 +2986,9 @@
   case clang::Type::VariableArray:
     if (element_type_ptr)
       element_type_ptr->SetCompilerType(
-          getASTContext(),
-          llvm::cast<clang::VariableArrayType>(qual_type)->getElementType());
+          this, llvm::cast<clang::VariableArrayType>(qual_type)
+                    ->getElementType()
+                    .getAsOpaquePtr());
     if (size)
       *size = 0;
     if (is_incomplete)
@@ -2964,8 +2998,9 @@
   case clang::Type::DependentSizedArray:
     if (element_type_ptr)
       element_type_ptr->SetCompilerType(
-          getASTContext(), llvm::cast<clang::DependentSizedArrayType>(qual_type)
-                               ->getElementType());
+          this, llvm::cast<clang::DependentSizedArrayType>(qual_type)
+                    ->getElementType()
+                    .getAsOpaquePtr());
     if (size)
       *size = 0;
     if (is_incomplete)
@@ -3016,7 +3051,7 @@
         *size = vector_type->getNumElements();
       if (element_type)
         *element_type =
-            CompilerType(getASTContext(), vector_type->getElementType());
+            CompilerType(this, vector_type->getElementType().getAsOpaquePtr());
     }
     return true;
   } break;
@@ -3028,7 +3063,7 @@
         *size = ext_vector_type->getNumElements();
       if (element_type)
         *element_type =
-            CompilerType(getASTContext(), ext_vector_type->getElementType());
+            CompilerType(this, ext_vector_type->getElementType().getAsOpaquePtr());
     }
     return true;
   }
@@ -3221,7 +3256,7 @@
             ++num_fields;
           }
           if (base_type_ptr)
-            *base_type_ptr = CompilerType(getASTContext(), base_qual_type);
+            *base_type_ptr = CompilerType(this, base_qual_type.getAsOpaquePtr());
           return num_fields;
         }
       }
@@ -3273,7 +3308,7 @@
         llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
     if (func) {
       if (index < func->getNumParams())
-        return CompilerType(getASTContext(), func->getParamType(index));
+        return CompilerType(this, func->getParamType(index).getAsOpaquePtr());
     }
   }
   return CompilerType();
@@ -3333,7 +3368,7 @@
         QualType pointee_type = block_pointer_type->getPointeeType();
         QualType function_pointer_type = m_ast_up->getPointerType(pointee_type);
         *function_pointer_type_ptr =
-            CompilerType(getASTContext(), function_pointer_type);
+            CompilerType(this, function_pointer_type.getAsOpaquePtr());
       }
       return true;
     }
@@ -3430,26 +3465,30 @@
     case clang::Type::ObjCObjectPointer:
       if (pointee_type)
         pointee_type->SetCompilerType(
-            getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type)
-                                 ->getPointeeType());
+            this, llvm::cast<clang::ObjCObjectPointerType>(qual_type)
+                      ->getPointeeType()
+                      .getAsOpaquePtr());
       return true;
     case clang::Type::BlockPointer:
       if (pointee_type)
         pointee_type->SetCompilerType(
-            getASTContext(),
-            llvm::cast<clang::BlockPointerType>(qual_type)->getPointeeType());
+            this, llvm::cast<clang::BlockPointerType>(qual_type)
+                      ->getPointeeType()
+                      .getAsOpaquePtr());
       return true;
     case clang::Type::Pointer:
       if (pointee_type)
-        pointee_type->SetCompilerType(
-            getASTContext(),
-            llvm::cast<clang::PointerType>(qual_type)->getPointeeType());
+        pointee_type->SetCompilerType(this,
+                                      llvm::cast<clang::PointerType>(qual_type)
+                                          ->getPointeeType()
+                                          .getAsOpaquePtr());
       return true;
     case clang::Type::MemberPointer:
       if (pointee_type)
         pointee_type->SetCompilerType(
-            getASTContext(),
-            llvm::cast<clang::MemberPointerType>(qual_type)->getPointeeType());
+            this, llvm::cast<clang::MemberPointerType>(qual_type)
+                      ->getPointeeType()
+                      .getAsOpaquePtr());
       return true;
     case clang::Type::Typedef:
       return IsPointerType(llvm::cast<clang::TypedefType>(qual_type)
@@ -3498,38 +3537,43 @@
     case clang::Type::ObjCObjectPointer:
       if (pointee_type)
         pointee_type->SetCompilerType(
-            getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type)
-                                 ->getPointeeType());
+            this, llvm::cast<clang::ObjCObjectPointerType>(qual_type)
+                                 ->getPointeeType().getAsOpaquePtr());
       return true;
     case clang::Type::BlockPointer:
       if (pointee_type)
         pointee_type->SetCompilerType(
-            getASTContext(),
-            llvm::cast<clang::BlockPointerType>(qual_type)->getPointeeType());
+            this, llvm::cast<clang::BlockPointerType>(qual_type)
+                      ->getPointeeType()
+                      .getAsOpaquePtr());
       return true;
     case clang::Type::Pointer:
       if (pointee_type)
-        pointee_type->SetCompilerType(
-            getASTContext(),
-            llvm::cast<clang::PointerType>(qual_type)->getPointeeType());
+        pointee_type->SetCompilerType(this,
+                                      llvm::cast<clang::PointerType>(qual_type)
+                                          ->getPointeeType()
+                                          .getAsOpaquePtr());
       return true;
     case clang::Type::MemberPointer:
       if (pointee_type)
         pointee_type->SetCompilerType(
-            getASTContext(),
-            llvm::cast<clang::MemberPointerType>(qual_type)->getPointeeType());
+            this, llvm::cast<clang::MemberPointerType>(qual_type)
+                      ->getPointeeType()
+                      .getAsOpaquePtr());
       return true;
     case clang::Type::LValueReference:
       if (pointee_type)
         pointee_type->SetCompilerType(
-            getASTContext(),
-            llvm::cast<clang::LValueReferenceType>(qual_type)->desugar());
+            this, llvm::cast<clang::LValueReferenceType>(qual_type)
+                      ->desugar()
+                      .getAsOpaquePtr());
       return true;
     case clang::Type::RValueReference:
       if (pointee_type)
         pointee_type->SetCompilerType(
-            getASTContext(),
-            llvm::cast<clang::RValueReferenceType>(qual_type)->desugar());
+            this, llvm::cast<clang::RValueReferenceType>(qual_type)
+                      ->desugar()
+                      .getAsOpaquePtr());
       return true;
     case clang::Type::Typedef:
       return IsPointerOrReferenceType(llvm::cast<clang::TypedefType>(qual_type)
@@ -3572,16 +3616,18 @@
     case clang::Type::LValueReference:
       if (pointee_type)
         pointee_type->SetCompilerType(
-            getASTContext(),
-            llvm::cast<clang::LValueReferenceType>(qual_type)->desugar());
+            this, llvm::cast<clang::LValueReferenceType>(qual_type)
+                      ->desugar()
+                      .getAsOpaquePtr());
       if (is_rvalue)
         *is_rvalue = false;
       return true;
     case clang::Type::RValueReference:
       if (pointee_type)
         pointee_type->SetCompilerType(
-            getASTContext(),
-            llvm::cast<clang::RValueReferenceType>(qual_type)->desugar());
+            this, llvm::cast<clang::RValueReferenceType>(qual_type)
+                      ->desugar()
+                      .getAsOpaquePtr());
       if (is_rvalue)
         *is_rvalue = true;
       return true;
@@ -3773,9 +3819,9 @@
         }
         if (dynamic_pointee_type)
           dynamic_pointee_type->SetCompilerType(
-              getASTContext(),
-              llvm::cast<clang::ObjCObjectPointerType>(qual_type)
-                  ->getPointeeType());
+              this, llvm::cast<clang::ObjCObjectPointerType>(qual_type)
+                        ->getPointeeType()
+                        .getAsOpaquePtr());
         return true;
       }
       break;
@@ -3835,8 +3881,8 @@
         case clang::BuiltinType::UnknownAny:
         case clang::BuiltinType::Void:
           if (dynamic_pointee_type)
-            dynamic_pointee_type->SetCompilerType(getASTContext(),
-                                                  pointee_qual_type);
+            dynamic_pointee_type->SetCompilerType(
+                this, pointee_qual_type.getAsOpaquePtr());
           return true;
         default:
           break;
@@ -3858,8 +3904,9 @@
               if (metadata)
                 success = metadata->GetIsDynamicCXXType();
               else {
-                is_complete = CompilerType(getASTContext(), pointee_qual_type)
-                                  .GetCompleteType();
+                is_complete =
+                    CompilerType(this, pointee_qual_type.getAsOpaquePtr())
+                        .GetCompleteType();
                 if (is_complete)
                   success = cxx_record_decl->isDynamicClass();
                 else
@@ -3869,8 +3916,8 @@
 
             if (success) {
               if (dynamic_pointee_type)
-                dynamic_pointee_type->SetCompilerType(getASTContext(),
-                                                      pointee_qual_type);
+                dynamic_pointee_type->SetCompilerType(
+                    this, pointee_qual_type.getAsOpaquePtr());
               return true;
             }
           }
@@ -3881,8 +3928,8 @@
       case clang::Type::ObjCInterface:
         if (check_objc) {
           if (dynamic_pointee_type)
-            dynamic_pointee_type->SetCompilerType(getASTContext(),
-                                                  pointee_qual_type);
+            dynamic_pointee_type->SetCompilerType(
+                this, pointee_qual_type.getAsOpaquePtr());
           return true;
         }
         break;
@@ -4065,14 +4112,14 @@
     case clang::BuiltinType::ObjCClass:
       if (pointee_or_element_clang_type)
         pointee_or_element_clang_type->SetCompilerType(
-            getASTContext(), getASTContext()->ObjCBuiltinClassTy);
+            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(getASTContext(),
-                                                       getASTContext()->CharTy);
+        pointee_or_element_clang_type->SetCompilerType(
+            this, getASTContext()->CharTy.getAsOpaquePtr());
       builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
       break;
 
@@ -4115,7 +4162,7 @@
   case clang::Type::BlockPointer:
     if (pointee_or_element_clang_type)
       pointee_or_element_clang_type->SetCompilerType(
-          getASTContext(), qual_type->getPointeeType());
+          this, qual_type->getPointeeType().getAsOpaquePtr());
     return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock;
 
   case clang::Type::Complex: {
@@ -4139,8 +4186,9 @@
   case clang::Type::VariableArray:
     if (pointee_or_element_clang_type)
       pointee_or_element_clang_type->SetCompilerType(
-          getASTContext(), llvm::cast<clang::ArrayType>(qual_type.getTypePtr())
-                               ->getElementType());
+          this, llvm::cast<clang::ArrayType>(qual_type.getTypePtr())
+                    ->getElementType()
+                    .getAsOpaquePtr());
     return eTypeHasChildren | eTypeIsArray;
 
   case clang::Type::DependentName:
@@ -4150,31 +4198,34 @@
   case clang::Type::DependentTemplateSpecialization:
     return eTypeIsTemplate;
   case clang::Type::Decltype:
-    return CompilerType(
-               getASTContext(),
-               llvm::cast<clang::DecltypeType>(qual_type)->getUnderlyingType())
+    return CompilerType(this, llvm::cast<clang::DecltypeType>(qual_type)
+                                  ->getUnderlyingType()
+                                  .getAsOpaquePtr())
         .GetTypeInfo(pointee_or_element_clang_type);
 
   case clang::Type::Enum:
     if (pointee_or_element_clang_type)
       pointee_or_element_clang_type->SetCompilerType(
-          getASTContext(),
-          llvm::cast<clang::EnumType>(qual_type)->getDecl()->getIntegerType());
+          this, llvm::cast<clang::EnumType>(qual_type)
+                    ->getDecl()
+                    ->getIntegerType()
+                    .getAsOpaquePtr());
     return eTypeIsEnumeration | eTypeHasValue;
 
   case clang::Type::Auto:
-    return CompilerType(
-               getASTContext(),
-               llvm::cast<clang::AutoType>(qual_type)->getDeducedType())
+    return CompilerType(this, llvm::cast<clang::AutoType>(qual_type)
+                                  ->getDeducedType()
+                                  .getAsOpaquePtr())
         .GetTypeInfo(pointee_or_element_clang_type);
   case clang::Type::Elaborated:
-    return CompilerType(
-               getASTContext(),
-               llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())
+    return CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type)
+                                  ->getNamedType()
+                                  .getAsOpaquePtr())
         .GetTypeInfo(pointee_or_element_clang_type);
   case clang::Type::Paren:
-    return CompilerType(getASTContext(),
-                        llvm::cast<clang::ParenType>(qual_type)->desugar())
+    return CompilerType(this, llvm::cast<clang::ParenType>(qual_type)
+                                  ->desugar()
+                                  .getAsOpaquePtr())
         .GetTypeInfo(pointee_or_element_clang_type);
 
   case clang::Type::FunctionProto:
@@ -4188,9 +4239,9 @@
   case clang::Type::RValueReference:
     if (pointee_or_element_clang_type)
       pointee_or_element_clang_type->SetCompilerType(
-          getASTContext(),
-          llvm::cast<clang::ReferenceType>(qual_type.getTypePtr())
-              ->getPointeeType());
+          this, llvm::cast<clang::ReferenceType>(qual_type.getTypePtr())
+                    ->getPointeeType()
+                    .getAsOpaquePtr());
     return eTypeHasChildren | eTypeIsReference | eTypeHasValue;
 
   case clang::Type::MemberPointer:
@@ -4199,7 +4250,7 @@
   case clang::Type::ObjCObjectPointer:
     if (pointee_or_element_clang_type)
       pointee_or_element_clang_type->SetCompilerType(
-          getASTContext(), qual_type->getPointeeType());
+          this, qual_type->getPointeeType().getAsOpaquePtr());
     return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer |
            eTypeHasValue;
 
@@ -4211,7 +4262,7 @@
   case clang::Type::Pointer:
     if (pointee_or_element_clang_type)
       pointee_or_element_clang_type->SetCompilerType(
-          getASTContext(), qual_type->getPointeeType());
+          this, qual_type->getPointeeType().getAsOpaquePtr());
     return eTypeHasChildren | eTypeIsPointer | eTypeHasValue;
 
   case clang::Type::Record:
@@ -4229,21 +4280,21 @@
 
   case clang::Type::Typedef:
     return eTypeIsTypedef |
-           CompilerType(getASTContext(),
-                        llvm::cast<clang::TypedefType>(qual_type)
-                            ->getDecl()
-                            ->getUnderlyingType())
+           CompilerType(this, llvm::cast<clang::TypedefType>(qual_type)
+                                  ->getDecl()
+                                  ->getUnderlyingType()
+                                  .getAsOpaquePtr())
                .GetTypeInfo(pointee_or_element_clang_type);
   case clang::Type::TypeOfExpr:
-    return CompilerType(getASTContext(),
-                        llvm::cast<clang::TypeOfExprType>(qual_type)
-                            ->getUnderlyingExpr()
-                            ->getType())
+    return CompilerType(this, llvm::cast<clang::TypeOfExprType>(qual_type)
+                                  ->getUnderlyingExpr()
+                                  ->getType()
+                                  .getAsOpaquePtr())
         .GetTypeInfo(pointee_or_element_clang_type);
   case clang::Type::TypeOf:
-    return CompilerType(
-               getASTContext(),
-               llvm::cast<clang::TypeOfType>(qual_type)->getUnderlyingType())
+    return CompilerType(this, llvm::cast<clang::TypeOfType>(qual_type)
+                                  ->getUnderlyingType()
+                                  .getAsOpaquePtr())
         .GetTypeInfo(pointee_or_element_clang_type);
   case clang::Type::UnresolvedUsing:
     return 0;
@@ -4342,10 +4393,10 @@
       }
       break;
     case clang::Type::Typedef:
-      return CompilerType(getASTContext(),
-                          llvm::cast<clang::TypedefType>(qual_type)
-                              ->getDecl()
-                              ->getUnderlyingType())
+      return CompilerType(this, llvm::cast<clang::TypedefType>(qual_type)
+                                    ->getDecl()
+                                    ->getUnderlyingType()
+                                    .getAsOpaquePtr())
           .GetMinimumLanguage();
     }
   }
@@ -4423,18 +4474,19 @@
   case clang::Type::UnresolvedUsing:
     break;
   case clang::Type::Paren:
-    return CompilerType(getASTContext(),
-                        llvm::cast<clang::ParenType>(qual_type)->desugar())
+    return CompilerType(this, llvm::cast<clang::ParenType>(qual_type)
+                                  ->desugar()
+                                  .getAsOpaquePtr())
         .GetTypeClass();
   case clang::Type::Auto:
-    return CompilerType(
-               getASTContext(),
-               llvm::cast<clang::AutoType>(qual_type)->getDeducedType())
+    return CompilerType(this, llvm::cast<clang::AutoType>(qual_type)
+                                  ->getDeducedType()
+                                  .getAsOpaquePtr())
         .GetTypeClass();
   case clang::Type::Elaborated:
-    return CompilerType(
-               getASTContext(),
-               llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())
+    return CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type)
+                                  ->getNamedType()
+                                  .getAsOpaquePtr())
         .GetTypeClass();
 
   case clang::Type::Attributed:
@@ -4455,20 +4507,20 @@
     break;
 
   case clang::Type::TypeOfExpr:
-    return CompilerType(getASTContext(),
-                        llvm::cast<clang::TypeOfExprType>(qual_type)
-                            ->getUnderlyingExpr()
-                            ->getType())
+    return CompilerType(this, llvm::cast<clang::TypeOfExprType>(qual_type)
+                                  ->getUnderlyingExpr()
+                                  ->getType()
+                                  .getAsOpaquePtr())
         .GetTypeClass();
   case clang::Type::TypeOf:
-    return CompilerType(
-               getASTContext(),
-               llvm::cast<clang::TypeOfType>(qual_type)->getUnderlyingType())
+    return CompilerType(this, llvm::cast<clang::TypeOfType>(qual_type)
+                                  ->getUnderlyingType()
+                                  .getAsOpaquePtr())
         .GetTypeClass();
   case clang::Type::Decltype:
-    return CompilerType(
-               getASTContext(),
-               llvm::cast<clang::TypeOfType>(qual_type)->getUnderlyingType())
+    return CompilerType(this, llvm::cast<clang::TypeOfType>(qual_type)
+                                  ->getUnderlyingType()
+                                  .getAsOpaquePtr())
         .GetTypeClass();
   case clang::Type::TemplateSpecialization:
     break;
@@ -4516,8 +4568,8 @@
     if (!array_eletype)
       return CompilerType();
 
-    CompilerType element_type(getASTContext(),
-                              array_eletype->getCanonicalTypeUnqualified());
+    CompilerType element_type(
+        this, array_eletype->getCanonicalTypeUnqualified().getAsOpaquePtr());
 
     // TODO: the real stride will be >= this value.. find the real one!
     if (stride)
@@ -4536,14 +4588,18 @@
     if (clang::ASTContext *ast_ctx = getASTContext()) {
       if (size != 0)
         return CompilerType(
-            ast_ctx, ast_ctx->getConstantArrayType(
-                         qual_type, llvm::APInt(64, size),
-                         clang::ArrayType::ArraySizeModifier::Normal, 0));
+            this, ast_ctx
+                      ->getConstantArrayType(
+                          qual_type, llvm::APInt(64, size),
+                          clang::ArrayType::ArraySizeModifier::Normal, 0)
+                      .getAsOpaquePtr());
       else
         return CompilerType(
-            ast_ctx,
-            ast_ctx->getIncompleteArrayType(
-                qual_type, clang::ArrayType::ArraySizeModifier::Normal, 0));
+            this,
+            ast_ctx
+                ->getIncompleteArrayType(
+                    qual_type, clang::ArrayType::ArraySizeModifier::Normal, 0)
+                .getAsOpaquePtr());
     }
   }
 
@@ -4553,7 +4609,7 @@
 CompilerType
 ClangASTContext::GetCanonicalType(lldb::opaque_compiler_type_t type) {
   if (type)
-    return CompilerType(getASTContext(), GetCanonicalQualType(type));
+    return CompilerType(this, GetCanonicalQualType(type).getAsOpaquePtr());
   return CompilerType();
 }
 
@@ -4574,8 +4630,8 @@
 ClangASTContext::GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) {
   if (type)
     return CompilerType(
-        getASTContext(),
-        GetFullyUnqualifiedType_Impl(getASTContext(), GetQualType(type)));
+        this,
+        GetFullyUnqualifiedType_Impl(getASTContext(), GetQualType(type)).getAsOpaquePtr());
   return CompilerType();
 }
 
@@ -4598,7 +4654,7 @@
     if (func) {
       const uint32_t num_args = func->getNumParams();
       if (idx < num_args)
-        return CompilerType(getASTContext(), func->getParamType(idx));
+        return CompilerType(this, func->getParamType(idx).getAsOpaquePtr());
     }
   }
   return CompilerType();
@@ -4611,7 +4667,7 @@
     const clang::FunctionProtoType *func =
         llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
     if (func)
-      return CompilerType(getASTContext(), func->getReturnType());
+      return CompilerType(this, func->getReturnType().getAsOpaquePtr());
   }
   return CompilerType();
 }
@@ -4670,27 +4726,28 @@
       break;
 
     case clang::Type::Typedef:
-      return CompilerType(getASTContext(),
-                          llvm::cast<clang::TypedefType>(qual_type)
-                              ->getDecl()
-                              ->getUnderlyingType())
+      return CompilerType(this, llvm::cast<clang::TypedefType>(qual_type)
+                                    ->getDecl()
+                                    ->getUnderlyingType()
+                                    .getAsOpaquePtr())
           .GetNumMemberFunctions();
 
     case clang::Type::Auto:
-      return CompilerType(
-                 getASTContext(),
-                 llvm::cast<clang::AutoType>(qual_type)->getDeducedType())
+      return CompilerType(this, llvm::cast<clang::AutoType>(qual_type)
+                                    ->getDeducedType()
+                                    .getAsOpaquePtr())
           .GetNumMemberFunctions();
 
     case clang::Type::Elaborated:
-      return CompilerType(
-                 getASTContext(),
-                 llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())
+      return CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type)
+                                    ->getNamedType()
+                                    .getAsOpaquePtr())
           .GetNumMemberFunctions();
 
     case clang::Type::Paren:
-      return CompilerType(getASTContext(),
-                          llvm::cast<clang::ParenType>(qual_type)->desugar())
+      return CompilerType(this, llvm::cast<clang::ParenType>(qual_type)
+                                    ->desugar()
+                                    .getAsOpaquePtr())
           .GetNumMemberFunctions();
 
     default:
@@ -4846,8 +4903,8 @@
 CompilerType
 ClangASTContext::GetNonReferenceType(lldb::opaque_compiler_type_t type) {
   if (type)
-    return CompilerType(getASTContext(),
-                        GetQualType(type).getNonReferenceType());
+    return CompilerType(
+        this, GetQualType(type).getNonReferenceType().getAsOpaquePtr());
   return CompilerType();
 }
 
@@ -4877,7 +4934,7 @@
     decl_ctx->addDecl(decl);
 
     // Get a uniqued clang::QualType for the typedef decl type
-    return CompilerType(clang_ast, clang_ast->getTypedefType(decl));
+    return CompilerType(ast, clang_ast->getTypedefType(decl).getAsOpaquePtr());
   }
   return CompilerType();
 }
@@ -4886,8 +4943,8 @@
 ClangASTContext::GetPointeeType(lldb::opaque_compiler_type_t type) {
   if (type) {
     clang::QualType qual_type(GetQualType(type));
-    return CompilerType(getASTContext(),
-                        qual_type.getTypePtr()->getPointeeType());
+    return CompilerType(
+        this, qual_type.getTypePtr()->getPointeeType().getAsOpaquePtr());
   }
   return CompilerType();
 }
@@ -4901,12 +4958,13 @@
     switch (type_class) {
     case clang::Type::ObjCObject:
     case clang::Type::ObjCInterface:
-      return CompilerType(getASTContext(),
-                          getASTContext()->getObjCObjectPointerType(qual_type));
+      return CompilerType(this, getASTContext()
+                                    ->getObjCObjectPointerType(qual_type)
+                                    .getAsOpaquePtr());
 
     default:
-      return CompilerType(getASTContext(),
-                          getASTContext()->getPointerType(qual_type));
+      return CompilerType(
+          this, getASTContext()->getPointerType(qual_type).getAsOpaquePtr());
     }
   }
   return CompilerType();
@@ -5008,8 +5066,8 @@
     const clang::TypedefType *typedef_type =
         llvm::dyn_cast<clang::TypedefType>(GetQualType(type));
     if (typedef_type)
-      return CompilerType(getASTContext(),
-                          typedef_type->getDecl()->getUnderlyingType());
+      return CompilerType(
+          this, typedef_type->getDecl()->getUnderlyingType().getAsOpaquePtr());
   }
   return CompilerType();
 }
@@ -5044,7 +5102,7 @@
         if (objc_runtime) {
           uint64_t bit_size = 0;
           if (objc_runtime->GetTypeBitSize(
-                  CompilerType(getASTContext(), qual_type), bit_size))
+                  CompilerType(this, qual_type.getAsOpaquePtr()), bit_size))
             return bit_size;
         }
       } else {
@@ -5291,8 +5349,9 @@
       const clang::ComplexType *complex_type =
           qual_type->getAsComplexIntegerType();
       if (complex_type)
-        encoding = CompilerType(getASTContext(), complex_type->getElementType())
-                       .GetEncoding(count);
+        encoding =
+            CompilerType(this, complex_type->getElementType().getAsOpaquePtr())
+                .GetEncoding(count);
       else
         encoding = lldb::eEncodingSint;
     }
@@ -5307,43 +5366,44 @@
   case clang::Type::Enum:
     return lldb::eEncodingSint;
   case clang::Type::Typedef:
-    return CompilerType(getASTContext(),
-                        llvm::cast<clang::TypedefType>(qual_type)
-                            ->getDecl()
-                            ->getUnderlyingType())
+    return CompilerType(this, llvm::cast<clang::TypedefType>(qual_type)
+                                  ->getDecl()
+                                  ->getUnderlyingType()
+                                  .getAsOpaquePtr())
         .GetEncoding(count);
 
   case clang::Type::Auto:
-    return CompilerType(
-               getASTContext(),
-               llvm::cast<clang::AutoType>(qual_type)->getDeducedType())
+    return CompilerType(this, llvm::cast<clang::AutoType>(qual_type)
+                                  ->getDeducedType()
+                                  .getAsOpaquePtr())
         .GetEncoding(count);
 
   case clang::Type::Elaborated:
-    return CompilerType(
-               getASTContext(),
-               llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())
+    return CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type)
+                                  ->getNamedType()
+                                  .getAsOpaquePtr())
         .GetEncoding(count);
 
   case clang::Type::Paren:
-    return CompilerType(getASTContext(),
-                        llvm::cast<clang::ParenType>(qual_type)->desugar())
+    return CompilerType(this, llvm::cast<clang::ParenType>(qual_type)
+                                  ->desugar()
+                                  .getAsOpaquePtr())
         .GetEncoding(count);
   case clang::Type::TypeOfExpr:
-    return CompilerType(getASTContext(),
-                        llvm::cast<clang::TypeOfExprType>(qual_type)
-                            ->getUnderlyingExpr()
-                            ->getType())
+    return CompilerType(this, llvm::cast<clang::TypeOfExprType>(qual_type)
+                                  ->getUnderlyingExpr()
+                                  ->getType()
+                                  .getAsOpaquePtr())
         .GetEncoding(count);
   case clang::Type::TypeOf:
-    return CompilerType(
-               getASTContext(),
-               llvm::cast<clang::TypeOfType>(qual_type)->getUnderlyingType())
+    return CompilerType(this, llvm::cast<clang::TypeOfType>(qual_type)
+                                  ->getUnderlyingType()
+                                  .getAsOpaquePtr())
         .GetEncoding(count);
   case clang::Type::Decltype:
-    return CompilerType(
-               getASTContext(),
-               llvm::cast<clang::DecltypeType>(qual_type)->getUnderlyingType())
+    return CompilerType(this, llvm::cast<clang::DecltypeType>(qual_type)
+                                  ->getUnderlyingType()
+                                  .getAsOpaquePtr())
         .GetEncoding(count);
   case clang::Type::DependentSizedArray:
   case clang::Type::DependentSizedExtVector:
@@ -5480,39 +5540,41 @@
   case clang::Type::Enum:
     return lldb::eFormatEnum;
   case clang::Type::Typedef:
-    return CompilerType(getASTContext(),
-                        llvm::cast<clang::TypedefType>(qual_type)
-                            ->getDecl()
-                            ->getUnderlyingType())
+    return CompilerType(this, llvm::cast<clang::TypedefType>(qual_type)
+                                  ->getDecl()
+                                  ->getUnderlyingType()
+                                  .getAsOpaquePtr())
         .GetFormat();
   case clang::Type::Auto:
-    return CompilerType(getASTContext(),
-                        llvm::cast<clang::AutoType>(qual_type)->desugar())
+    return CompilerType(this, llvm::cast<clang::AutoType>(qual_type)
+                                  ->desugar()
+                                  .getAsOpaquePtr())
         .GetFormat();
   case clang::Type::Paren:
-    return CompilerType(getASTContext(),
-                        llvm::cast<clang::ParenType>(qual_type)->desugar())
+    return CompilerType(this, llvm::cast<clang::ParenType>(qual_type)
+                                  ->desugar()
+                                  .getAsOpaquePtr())
         .GetFormat();
   case clang::Type::Elaborated:
-    return CompilerType(
-               getASTContext(),
-               llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())
+    return CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type)
+                                  ->getNamedType()
+                                  .getAsOpaquePtr())
         .GetFormat();
   case clang::Type::TypeOfExpr:
-    return CompilerType(getASTContext(),
-                        llvm::cast<clang::TypeOfExprType>(qual_type)
-                            ->getUnderlyingExpr()
-                            ->getType())
+    return CompilerType(this, llvm::cast<clang::TypeOfExprType>(qual_type)
+                                  ->getUnderlyingExpr()
+                                  ->getType()
+                                  .getAsOpaquePtr())
         .GetFormat();
   case clang::Type::TypeOf:
-    return CompilerType(
-               getASTContext(),
-               llvm::cast<clang::TypeOfType>(qual_type)->getUnderlyingType())
+    return CompilerType(this, llvm::cast<clang::TypeOfType>(qual_type)
+                                  ->getUnderlyingType()
+                                  .getAsOpaquePtr())
         .GetFormat();
   case clang::Type::Decltype:
-    return CompilerType(
-               getASTContext(),
-               llvm::cast<clang::DecltypeType>(qual_type)->getUnderlyingType())
+    return CompilerType(this, llvm::cast<clang::DecltypeType>(qual_type)
+                                  ->getUnderlyingType()
+                                  .getAsOpaquePtr())
         .GetFormat();
   case clang::Type::DependentSizedArray:
   case clang::Type::DependentSizedExtVector:
@@ -5674,7 +5736,7 @@
         llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr());
     clang::QualType pointee_type = pointer_type->getPointeeType();
     uint32_t num_pointee_children =
-        CompilerType(getASTContext(), pointee_type)
+        CompilerType(this, pointee_type.getAsOpaquePtr())
             .GetNumChildren(omit_empty_base_classes, exe_ctx);
     // If this type points to a simple type, then it has 1 child
     if (num_pointee_children == 0)
@@ -5708,7 +5770,7 @@
         llvm::cast<clang::PointerType>(qual_type.getTypePtr());
     clang::QualType pointee_type(pointer_type->getPointeeType());
     uint32_t num_pointee_children =
-        CompilerType(getASTContext(), pointee_type)
+        CompilerType(this, pointee_type.getAsOpaquePtr())
       .GetNumChildren(omit_empty_base_classes, exe_ctx);
     if (num_pointee_children == 0) {
       // We have a pointer to a pointee type that claims it has no children. We
@@ -5724,7 +5786,7 @@
         llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
     clang::QualType pointee_type = reference_type->getPointeeType();
     uint32_t num_pointee_children =
-        CompilerType(getASTContext(), pointee_type)
+        CompilerType(this, pointee_type.getAsOpaquePtr())
             .GetNumChildren(omit_empty_base_classes, exe_ctx);
     // If this type points to a simple type, then it has 1 child
     if (num_pointee_children == 0)
@@ -5734,32 +5796,33 @@
   } break;
 
   case clang::Type::Typedef:
-    num_children =
-        CompilerType(getASTContext(), llvm::cast<clang::TypedefType>(qual_type)
+    num_children = CompilerType(this, llvm::cast<clang::TypedefType>(qual_type)
                                           ->getDecl()
-                                          ->getUnderlyingType())
-            .GetNumChildren(omit_empty_base_classes, exe_ctx);
+                                          ->getUnderlyingType()
+                                          .getAsOpaquePtr())
+                       .GetNumChildren(omit_empty_base_classes, exe_ctx);
     break;
 
   case clang::Type::Auto:
-    num_children =
-        CompilerType(getASTContext(),
-                     llvm::cast<clang::AutoType>(qual_type)->getDeducedType())
-            .GetNumChildren(omit_empty_base_classes, exe_ctx);
+    num_children = CompilerType(this, llvm::cast<clang::AutoType>(qual_type)
+                                          ->getDeducedType()
+                                          .getAsOpaquePtr())
+                       .GetNumChildren(omit_empty_base_classes, exe_ctx);
     break;
 
   case clang::Type::Elaborated:
     num_children =
-        CompilerType(
-            getASTContext(),
-            llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())
+        CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type)
+                               ->getNamedType()
+                               .getAsOpaquePtr())
             .GetNumChildren(omit_empty_base_classes, exe_ctx);
     break;
 
   case clang::Type::Paren:
     num_children =
-        CompilerType(getASTContext(),
-                     llvm::cast<clang::ParenType>(qual_type)->desugar())
+        CompilerType(
+            this,
+            llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr())
             .GetNumChildren(omit_empty_base_classes, exe_ctx);
     break;
   default:
@@ -5900,31 +5963,33 @@
     break;
 
   case clang::Type::Typedef:
-    count =
-        CompilerType(getASTContext(), llvm::cast<clang::TypedefType>(qual_type)
-                                          ->getDecl()
-                                          ->getUnderlyingType())
-            .GetNumFields();
+    count = CompilerType(this, llvm::cast<clang::TypedefType>(qual_type)
+                                   ->getDecl()
+                                   ->getUnderlyingType()
+                                   .getAsOpaquePtr())
+                .GetNumFields();
     break;
 
   case clang::Type::Auto:
-    count =
-        CompilerType(getASTContext(),
-                     llvm::cast<clang::AutoType>(qual_type)->getDeducedType())
-            .GetNumFields();
+    count = CompilerType(this, llvm::cast<clang::AutoType>(qual_type)
+                                   ->getDeducedType()
+                                   .getAsOpaquePtr())
+                .GetNumFields();
     break;
 
   case clang::Type::Elaborated:
-    count = CompilerType(
-                getASTContext(),
-                llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())
+    count = CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type)
+                                   ->getNamedType()
+                                   .getAsOpaquePtr())
                 .GetNumFields();
     break;
 
   case clang::Type::Paren:
-    count = CompilerType(getASTContext(),
-                         llvm::cast<clang::ParenType>(qual_type)->desugar())
-                .GetNumFields();
+    count =
+        CompilerType(
+            this,
+            llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr())
+            .GetNumFields();
     break;
 
   case clang::Type::ObjCObjectPointer: {
@@ -6070,7 +6135,7 @@
           if (is_bitfield_ptr)
             *is_bitfield_ptr = is_bitfield;
 
-          return CompilerType(getASTContext(), field->getType());
+          return CompilerType(this, field->getType().getAsOpaquePtr());
         }
       }
     }
@@ -6114,30 +6179,31 @@
     break;
 
   case clang::Type::Typedef:
-    return CompilerType(getASTContext(),
-                        llvm::cast<clang::TypedefType>(qual_type)
-                            ->getDecl()
-                            ->getUnderlyingType())
+    return CompilerType(this, llvm::cast<clang::TypedefType>(qual_type)
+                                  ->getDecl()
+                                  ->getUnderlyingType()
+                                  .getAsOpaquePtr())
         .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr,
                          is_bitfield_ptr);
 
   case clang::Type::Auto:
-    return CompilerType(
-               getASTContext(),
-               llvm::cast<clang::AutoType>(qual_type)->getDeducedType())
+    return CompilerType(this, llvm::cast<clang::AutoType>(qual_type)
+                                  ->getDeducedType()
+                                  .getAsOpaquePtr())
         .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr,
                          is_bitfield_ptr);
 
   case clang::Type::Elaborated:
-    return CompilerType(
-               getASTContext(),
-               llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())
+    return CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type)
+                                  ->getNamedType()
+                                  .getAsOpaquePtr())
         .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr,
                          is_bitfield_ptr);
 
   case clang::Type::Paren:
-    return CompilerType(getASTContext(),
-                        llvm::cast<clang::ParenType>(qual_type)->desugar())
+    return CompilerType(this, llvm::cast<clang::ParenType>(qual_type)
+                                  ->desugar()
+                                  .getAsOpaquePtr())
         .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr,
                          is_bitfield_ptr);
 
@@ -6328,9 +6394,9 @@
           if (superclass_interface_decl) {
             if (bit_offset_ptr)
               *bit_offset_ptr = 0;
-            return CompilerType(getASTContext(),
+            return CompilerType(this,
                                 getASTContext()->getObjCInterfaceType(
-                                    superclass_interface_decl));
+                                    superclass_interface_decl).getAsOpaquePtr());
           }
         }
       }
@@ -6350,9 +6416,10 @@
           if (superclass_interface_decl) {
             if (bit_offset_ptr)
               *bit_offset_ptr = 0;
-            return CompilerType(getASTContext(),
-                                getASTContext()->getObjCInterfaceType(
-                                    superclass_interface_decl));
+            return CompilerType(
+                this, getASTContext()
+                          ->getObjCInterfaceType(superclass_interface_decl)
+                          .getAsOpaquePtr());
           }
         }
       }
@@ -6655,8 +6722,8 @@
         child_byte_size =
             getASTContext()->getTypeSize(getASTContext()->ObjCBuiltinClassTy) /
             CHAR_BIT;
-        return CompilerType(getASTContext(),
-                            getASTContext()->ObjCBuiltinClassTy);
+        return CompilerType(
+            this, getASTContext()->ObjCBuiltinClassTy.getAsOpaquePtr());
 
       default:
         break;
@@ -6719,8 +6786,8 @@
 
             // Base classes should be a multiple of 8 bits in size
             child_byte_offset = bit_offset / 8;
-            CompilerType base_class_clang_type(getASTContext(),
-                                               base_class->getType());
+            CompilerType base_class_clang_type(
+                this, base_class->getType().getAsOpaquePtr());
             child_name = base_class_clang_type.GetTypeName().AsCString("");
             Optional<uint64_t> size =
                 base_class_clang_type.GetBitSize(get_exe_scope());
@@ -6752,7 +6819,8 @@
 
           // Figure out the type byte size (field_type_info.first) and
           // alignment (field_type_info.second) from the AST context.
-          CompilerType field_clang_type(getASTContext(), field->getType());
+          CompilerType field_clang_type(this,
+                                        field->getType().getAsOpaquePtr());
           assert(field_idx < record_layout.getFieldCount());
           Optional<uint64_t> size =
               field_clang_type.GetByteSize(get_exe_scope());
@@ -6800,8 +6868,9 @@
           if (superclass_interface_decl) {
             if (omit_empty_base_classes) {
               CompilerType base_class_clang_type(
-                  getASTContext(), getASTContext()->getObjCInterfaceType(
-                                       superclass_interface_decl));
+                  this, getASTContext()
+                            ->getObjCInterfaceType(superclass_interface_decl)
+                            .getAsOpaquePtr());
               if (base_class_clang_type.GetNumChildren(omit_empty_base_classes,
                                                        exe_ctx) > 0) {
                 if (idx == 0) {
@@ -6819,7 +6888,7 @@
                   child_byte_offset = 0;
                   child_is_base_class = true;
 
-                  return CompilerType(getASTContext(), ivar_qual_type);
+                  return CompilerType(this, ivar_qual_type.getAsOpaquePtr());
                 }
 
                 ++child_idx;
@@ -6863,8 +6932,8 @@
                   ObjCLanguageRuntime *objc_runtime =
                       ObjCLanguageRuntime::Get(*process);
                   if (objc_runtime != nullptr) {
-                    CompilerType parent_ast_type(getASTContext(),
-                                                 parent_qual_type);
+                    CompilerType parent_ast_type(
+                        this, parent_qual_type.getAsOpaquePtr());
                     child_byte_offset = objc_runtime->GetByteOffsetForIvar(
                         parent_ast_type, ivar_decl->getNameAsString().c_str());
                   }
@@ -6895,7 +6964,7 @@
 
                   child_bitfield_bit_offset = bit_offset % 8;
                 }
-                return CompilerType(getASTContext(), ivar_qual_type);
+                return CompilerType(this, ivar_qual_type.getAsOpaquePtr());
               }
               ++child_idx;
             }
@@ -6946,7 +7015,8 @@
       const clang::VectorType *array =
           llvm::cast<clang::VectorType>(parent_qual_type.getTypePtr());
       if (array) {
-        CompilerType element_type(getASTContext(), array->getElementType());
+        CompilerType element_type(this,
+                                  array->getElementType().getAsOpaquePtr());
         if (element_type.GetCompleteType()) {
           char element_name[64];
           ::snprintf(element_name, sizeof(element_name), "[%" PRIu64 "]",
@@ -6968,7 +7038,8 @@
     if (ignore_array_bounds || idx_is_valid) {
       const clang::ArrayType *array = GetQualType(type)->getAsArrayTypeUnsafe();
       if (array) {
-        CompilerType element_type(getASTContext(), array->getElementType());
+        CompilerType element_type(this,
+                                  array->getElementType().getAsOpaquePtr());
         if (element_type.GetCompleteType()) {
           child_name = llvm::formatv("[{0}]", idx);
           if (Optional<uint64_t> size =
@@ -7026,8 +7097,8 @@
     if (idx_is_valid) {
       const clang::ReferenceType *reference_type =
           llvm::cast<clang::ReferenceType>(parent_qual_type.getTypePtr());
-      CompilerType pointee_clang_type(getASTContext(),
-                                      reference_type->getPointeeType());
+      CompilerType pointee_clang_type(
+          this, reference_type->getPointeeType().getAsOpaquePtr());
       if (transparent_pointers && pointee_clang_type.IsAggregateType()) {
         child_is_deref_of_parent = false;
         bool tmp_child_is_deref_of_parent = false;
@@ -7060,9 +7131,10 @@
 
   case clang::Type::Typedef: {
     CompilerType typedefed_clang_type(
-        getASTContext(), llvm::cast<clang::TypedefType>(parent_qual_type)
-                             ->getDecl()
-                             ->getUnderlyingType());
+        this, llvm::cast<clang::TypedefType>(parent_qual_type)
+                  ->getDecl()
+                  ->getUnderlyingType()
+                  .getAsOpaquePtr());
     return typedefed_clang_type.GetChildCompilerTypeAtIndex(
         exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
         ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
@@ -7072,8 +7144,9 @@
 
   case clang::Type::Auto: {
     CompilerType elaborated_clang_type(
-        getASTContext(),
-        llvm::cast<clang::AutoType>(parent_qual_type)->getDeducedType());
+        this, llvm::cast<clang::AutoType>(parent_qual_type)
+                  ->getDeducedType()
+                  .getAsOpaquePtr());
     return elaborated_clang_type.GetChildCompilerTypeAtIndex(
         exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
         ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
@@ -7083,8 +7156,9 @@
 
   case clang::Type::Elaborated: {
     CompilerType elaborated_clang_type(
-        getASTContext(),
-        llvm::cast<clang::ElaboratedType>(parent_qual_type)->getNamedType());
+        this, llvm::cast<clang::ElaboratedType>(parent_qual_type)
+                  ->getNamedType()
+                  .getAsOpaquePtr());
     return elaborated_clang_type.GetChildCompilerTypeAtIndex(
         exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
         ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
@@ -7093,9 +7167,10 @@
   }
 
   case clang::Type::Paren: {
-    CompilerType paren_clang_type(
-        getASTContext(),
-        llvm::cast<clang::ParenType>(parent_qual_type)->desugar());
+    CompilerType paren_clang_type(this,
+                                  llvm::cast<clang::ParenType>(parent_qual_type)
+                                      ->desugar()
+                                      .getAsOpaquePtr());
     return paren_clang_type.GetChildCompilerTypeAtIndex(
         exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
         ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
@@ -7224,7 +7299,7 @@
              field != field_end; ++field, ++child_idx) {
           llvm::StringRef field_name = field->getName();
           if (field_name.empty()) {
-            CompilerType field_type(getASTContext(), field->getType());
+            CompilerType field_type(this, field->getType().getAsOpaquePtr());
             child_indexes.push_back(child_idx);
             if (field_type.GetIndexOfChildMemberWithName(
                     name, omit_empty_base_classes, child_indexes))
@@ -7336,8 +7411,9 @@
               child_indexes.push_back(0);
 
               CompilerType superclass_clang_type(
-                  getASTContext(), getASTContext()->getObjCInterfaceType(
-                                       superclass_interface_decl));
+                  this, getASTContext()
+                            ->getObjCInterfaceType(superclass_interface_decl)
+                            .getAsOpaquePtr());
               if (superclass_clang_type.GetIndexOfChildMemberWithName(
                       name, omit_empty_base_classes, child_indexes)) {
                 // We did find an ivar in a superclass so just return the
@@ -7356,9 +7432,9 @@
 
     case clang::Type::ObjCObjectPointer: {
       CompilerType objc_object_clang_type(
-          getASTContext(),
-          llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
-              ->getPointeeType());
+          this, llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
+                    ->getPointeeType()
+                    .getAsOpaquePtr());
       return objc_object_clang_type.GetIndexOfChildMemberWithName(
           name, omit_empty_base_classes, child_indexes);
     } break;
@@ -7408,7 +7484,7 @@
       const clang::ReferenceType *reference_type =
           llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
       clang::QualType pointee_type(reference_type->getPointeeType());
-      CompilerType pointee_clang_type(getASTContext(), pointee_type);
+      CompilerType pointee_clang_type(this, pointee_type.getAsOpaquePtr());
 
       if (pointee_clang_type.IsAggregateType()) {
         return pointee_clang_type.GetIndexOfChildMemberWithName(
@@ -7426,30 +7502,31 @@
     } break;
 
     case clang::Type::Typedef:
-      return CompilerType(getASTContext(),
-                          llvm::cast<clang::TypedefType>(qual_type)
-                              ->getDecl()
-                              ->getUnderlyingType())
+      return CompilerType(this, llvm::cast<clang::TypedefType>(qual_type)
+                                    ->getDecl()
+                                    ->getUnderlyingType()
+                                    .getAsOpaquePtr())
           .GetIndexOfChildMemberWithName(name, omit_empty_base_classes,
                                          child_indexes);
 
     case clang::Type::Auto:
-      return CompilerType(
-                 getASTContext(),
-                 llvm::cast<clang::AutoType>(qual_type)->getDeducedType())
+      return CompilerType(this, llvm::cast<clang::AutoType>(qual_type)
+                                    ->getDeducedType()
+                                    .getAsOpaquePtr())
           .GetIndexOfChildMemberWithName(name, omit_empty_base_classes,
                                          child_indexes);
 
     case clang::Type::Elaborated:
-      return CompilerType(
-                 getASTContext(),
-                 llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())
+      return CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type)
+                                    ->getNamedType()
+                                    .getAsOpaquePtr())
           .GetIndexOfChildMemberWithName(name, omit_empty_base_classes,
                                          child_indexes);
 
     case clang::Type::Paren:
-      return CompilerType(getASTContext(),
-                          llvm::cast<clang::ParenType>(qual_type)->desugar())
+      return CompilerType(this, llvm::cast<clang::ParenType>(qual_type)
+                                    ->desugar()
+                                    .getAsOpaquePtr())
           .GetIndexOfChildMemberWithName(name, omit_empty_base_classes,
                                          child_indexes);
 
@@ -7502,8 +7579,8 @@
                 !ClangASTContext::RecordHasFields(base_class_decl))
               continue;
 
-            CompilerType base_class_clang_type(getASTContext(),
-                                               base_class->getType());
+            CompilerType base_class_clang_type(
+                this, base_class->getType().getAsOpaquePtr());
             std::string base_class_type_name(
                 base_class_clang_type.GetTypeName().AsCString(""));
             if (base_class_type_name == name)
@@ -7567,9 +7644,9 @@
 
     case clang::Type::ObjCObjectPointer: {
       CompilerType pointee_clang_type(
-          getASTContext(),
-          llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
-              ->getPointeeType());
+          this, llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())
+                    ->getPointeeType()
+                    .getAsOpaquePtr());
       return pointee_clang_type.GetIndexOfChildWithName(
           name, omit_empty_base_classes);
     } break;
@@ -7618,8 +7695,8 @@
     case clang::Type::RValueReference: {
       const clang::ReferenceType *reference_type =
           llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
-      CompilerType pointee_type(getASTContext(),
-                                reference_type->getPointeeType());
+      CompilerType pointee_type(
+          this, reference_type->getPointeeType().getAsOpaquePtr());
 
       if (pointee_type.IsAggregateType()) {
         return pointee_type.GetIndexOfChildWithName(name,
@@ -7630,8 +7707,8 @@
     case clang::Type::Pointer: {
       const clang::PointerType *pointer_type =
           llvm::cast<clang::PointerType>(qual_type.getTypePtr());
-      CompilerType pointee_type(getASTContext(),
-                                pointer_type->getPointeeType());
+      CompilerType pointee_type(
+          this, pointer_type->getPointeeType().getAsOpaquePtr());
 
       if (pointee_type.IsAggregateType()) {
         return pointee_type.GetIndexOfChildWithName(name,
@@ -7657,27 +7734,28 @@
     } break;
 
     case clang::Type::Auto:
-      return CompilerType(
-                 getASTContext(),
-                 llvm::cast<clang::AutoType>(qual_type)->getDeducedType())
+      return CompilerType(this, llvm::cast<clang::AutoType>(qual_type)
+                                    ->getDeducedType()
+                                    .getAsOpaquePtr())
           .GetIndexOfChildWithName(name, omit_empty_base_classes);
 
     case clang::Type::Elaborated:
-      return CompilerType(
-                 getASTContext(),
-                 llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())
+      return CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type)
+                                    ->getNamedType()
+                                    .getAsOpaquePtr())
           .GetIndexOfChildWithName(name, omit_empty_base_classes);
 
     case clang::Type::Paren:
-      return CompilerType(getASTContext(),
-                          llvm::cast<clang::ParenType>(qual_type)->desugar())
+      return CompilerType(this, llvm::cast<clang::ParenType>(qual_type)
+                                    ->desugar()
+                                    .getAsOpaquePtr())
           .GetIndexOfChildWithName(name, omit_empty_base_classes);
 
     case clang::Type::Typedef:
-      return CompilerType(getASTContext(),
-                          llvm::cast<clang::TypedefType>(qual_type)
-                              ->getDecl()
-                              ->getUnderlyingType())
+      return CompilerType(this, llvm::cast<clang::TypedefType>(qual_type)
+                                    ->getDecl()
+                                    ->getUnderlyingType()
+                                    .getAsOpaquePtr())
           .GetIndexOfChildWithName(name, omit_empty_base_classes);
 
     default:
@@ -7710,27 +7788,28 @@
     break;
 
   case clang::Type::Typedef:
-    return (CompilerType(getASTContext(),
-                         llvm::cast<clang::TypedefType>(qual_type)
-                             ->getDecl()
-                             ->getUnderlyingType()))
+    return CompilerType(this, llvm::cast<clang::TypedefType>(qual_type)
+                                  ->getDecl()
+                                  ->getUnderlyingType()
+                                  .getAsOpaquePtr())
         .GetNumTemplateArguments();
 
   case clang::Type::Auto:
-    return (CompilerType(
-                getASTContext(),
-                llvm::cast<clang::AutoType>(qual_type)->getDeducedType()))
+    return CompilerType(this, llvm::cast<clang::AutoType>(qual_type)
+                                  ->getDeducedType()
+                                  .getAsOpaquePtr())
         .GetNumTemplateArguments();
 
   case clang::Type::Elaborated:
-    return (CompilerType(
-                getASTContext(),
-                llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()))
+    return CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type)
+                                  ->getNamedType()
+                                  .getAsOpaquePtr())
         .GetNumTemplateArguments();
 
   case clang::Type::Paren:
-    return (CompilerType(getASTContext(),
-                         llvm::cast<clang::ParenType>(qual_type)->desugar()))
+    return CompilerType(this, llvm::cast<clang::ParenType>(qual_type)
+                                  ->desugar()
+                                  .getAsOpaquePtr())
         .GetNumTemplateArguments();
 
   default:
@@ -7838,7 +7917,7 @@
   if (template_arg.getKind() != clang::TemplateArgument::Type)
     return CompilerType();
 
-  return CompilerType(getASTContext(), template_arg.getAsType());
+  return CompilerType(this, template_arg.getAsType().getAsOpaquePtr());
 }
 
 Optional<CompilerType::IntegralTemplateArgument>
@@ -7854,8 +7933,9 @@
   if (template_arg.getKind() != clang::TemplateArgument::Integral)
     return llvm::None;
 
-  return {{template_arg.getAsIntegral(),
-           CompilerType(getASTContext(), template_arg.getIntegralType())}};
+  return {
+      {template_arg.getAsIntegral(),
+       CompilerType(this, template_arg.getIntegralType().getAsOpaquePtr())}};
 }
 
 CompilerType ClangASTContext::GetTypeForFormatters(void *type) {
@@ -8434,7 +8514,7 @@
       property_clang_type_to_access = property_clang_type;
     else if (ivar_decl)
       property_clang_type_to_access =
-          CompilerType(clang_ast, ivar_decl->getType());
+          CompilerType(ast, ivar_decl->getType().getAsOpaquePtr());
 
     if (class_interface_decl && property_clang_type_to_access.IsValid()) {
       clang::TypeSourceInfo *prop_type_source;
@@ -9040,7 +9120,7 @@
     if (enutype) {
       clang::EnumDecl *enum_decl = enutype->getDecl();
       if (enum_decl)
-        return CompilerType(getASTContext(), enum_decl->getIntegerType());
+        return CompilerType(this, enum_decl->getIntegerType().getAsOpaquePtr());
     }
   }
   return CompilerType();
@@ -9055,10 +9135,11 @@
         llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
     if (!ast)
       return CompilerType();
-    return CompilerType(ast->getASTContext(),
-                        ast->getASTContext()->getMemberPointerType(
-                            ClangUtil::GetQualType(pointee_type),
-                            ClangUtil::GetQualType(type).getTypePtr()));
+    return CompilerType(ast, ast->getASTContext()
+                                 ->getMemberPointerType(
+                                     ClangUtil::GetQualType(pointee_type),
+                                     ClangUtil::GetQualType(type).getTypePtr())
+                                 .getAsOpaquePtr());
   }
   return CompilerType();
 }
@@ -9148,7 +9229,8 @@
               getASTContext()->getTypeInfo(base_class_qual_type);
 
           // Dump the value of the member
-          CompilerType base_clang_type(getASTContext(), base_class_qual_type);
+          CompilerType base_clang_type(this,
+                                       base_class_qual_type.getAsOpaquePtr());
           base_clang_type.DumpValue(
               exe_ctx,
               s, // Stream to dump to
@@ -9215,7 +9297,7 @@
         s->Printf("%s = ", field->getNameAsString().c_str());
 
         // Dump the value of the member
-        CompilerType field_clang_type(getASTContext(), field_type);
+        CompilerType field_clang_type(this, field_type.getAsOpaquePtr());
         field_clang_type.DumpValue(
             exe_ctx,
             s, // Stream to dump to
@@ -9295,7 +9377,7 @@
       s->PutChar('"');
       return;
     } else {
-      CompilerType element_clang_type(getASTContext(), element_qual_type);
+      CompilerType element_clang_type(this, element_qual_type.getAsOpaquePtr());
       lldb::Format element_format = element_clang_type.GetFormat();
 
       for (element_idx = 0; element_idx < element_count; ++element_idx) {
@@ -9346,7 +9428,7 @@
             ->getDecl()
             ->getUnderlyingType();
 
-    CompilerType typedef_clang_type(getASTContext(), typedef_qual_type);
+    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);
@@ -9371,7 +9453,8 @@
   case clang::Type::Auto: {
     clang::QualType elaborated_qual_type =
         llvm::cast<clang::AutoType>(qual_type)->getDeducedType();
-    CompilerType elaborated_clang_type(getASTContext(), elaborated_qual_type);
+    CompilerType elaborated_clang_type(this,
+                                       elaborated_qual_type.getAsOpaquePtr());
     lldb::Format elaborated_format = elaborated_clang_type.GetFormat();
     clang::TypeInfo elaborated_type_info =
         getASTContext()->getTypeInfo(elaborated_qual_type);
@@ -9396,7 +9479,8 @@
   case clang::Type::Elaborated: {
     clang::QualType elaborated_qual_type =
         llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType();
-    CompilerType elaborated_clang_type(getASTContext(), elaborated_qual_type);
+    CompilerType elaborated_clang_type(this,
+                                       elaborated_qual_type.getAsOpaquePtr());
     lldb::Format elaborated_format = elaborated_clang_type.GetFormat();
     clang::TypeInfo elaborated_type_info =
         getASTContext()->getTypeInfo(elaborated_qual_type);
@@ -9421,7 +9505,7 @@
   case clang::Type::Paren: {
     clang::QualType desugar_qual_type =
         llvm::cast<clang::ParenType>(qual_type)->desugar();
-    CompilerType desugar_clang_type(getASTContext(), desugar_qual_type);
+    CompilerType desugar_clang_type(this, desugar_qual_type.getAsOpaquePtr());
 
     lldb::Format desugar_format = desugar_clang_type.GetFormat();
     clang::TypeInfo desugar_type_info =
@@ -9475,7 +9559,7 @@
           llvm::cast<clang::TypedefType>(qual_type)
               ->getDecl()
               ->getUnderlyingType();
-      CompilerType typedef_clang_type(getASTContext(), typedef_qual_type);
+      CompilerType typedef_clang_type(this, typedef_qual_type.getAsOpaquePtr());
       if (format == eFormatDefault)
         format = typedef_clang_type.GetFormat();
       clang::TypeInfo typedef_type_info =
@@ -9705,20 +9789,23 @@
     } break;
 
     case clang::Type::Auto:
-      CompilerType(getASTContext(),
-                   llvm::cast<clang::AutoType>(qual_type)->getDeducedType())
+      CompilerType(this, llvm::cast<clang::AutoType>(qual_type)
+                             ->getDeducedType()
+                             .getAsOpaquePtr())
           .DumpTypeDescription(s);
       return;
 
     case clang::Type::Elaborated:
-      CompilerType(getASTContext(),
-                   llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())
+      CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type)
+                             ->getNamedType()
+                             .getAsOpaquePtr())
           .DumpTypeDescription(s);
       return;
 
     case clang::Type::Paren:
-      CompilerType(getASTContext(),
-                   llvm::cast<clang::ParenType>(qual_type)->desugar())
+      CompilerType(
+          this,
+          llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr())
           .DumpTypeDescription(s);
       return;
 
Index: lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
+++ lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
@@ -120,24 +120,31 @@
     return clang_ast.GetBasicType(eBasicTypeBool);
   case PDB_BuiltinType::Long:
     if (width == ast->getTypeSize(ast->LongTy))
-      return CompilerType(ast, ast->LongTy);
+      return CompilerType(ClangASTContext::GetASTContext(ast),
+                          ast->LongTy.getAsOpaquePtr());
     if (width == ast->getTypeSize(ast->LongLongTy))
-      return CompilerType(ast, ast->LongLongTy);
+      return CompilerType(ClangASTContext::GetASTContext(ast),
+                          ast->LongLongTy.getAsOpaquePtr());
     break;
   case PDB_BuiltinType::ULong:
     if (width == ast->getTypeSize(ast->UnsignedLongTy))
-      return CompilerType(ast, ast->UnsignedLongTy);
+      return CompilerType(ClangASTContext::GetASTContext(ast),
+                          ast->UnsignedLongTy.getAsOpaquePtr());
     if (width == ast->getTypeSize(ast->UnsignedLongLongTy))
-      return CompilerType(ast, ast->UnsignedLongLongTy);
+      return CompilerType(ClangASTContext::GetASTContext(ast),
+                          ast->UnsignedLongLongTy.getAsOpaquePtr());
     break;
   case PDB_BuiltinType::WCharT:
     if (width == ast->getTypeSize(ast->WCharTy))
-      return CompilerType(ast, ast->WCharTy);
+      return CompilerType(ClangASTContext::GetASTContext(ast),
+                          ast->WCharTy.getAsOpaquePtr());
     break;
   case PDB_BuiltinType::Char16:
-    return CompilerType(ast, ast->Char16Ty);
+    return CompilerType(ClangASTContext::GetASTContext(ast),
+                        ast->Char16Ty.getAsOpaquePtr());
   case PDB_BuiltinType::Char32:
-    return CompilerType(ast, ast->Char32Ty);
+    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
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
===================================================================
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
@@ -149,8 +149,9 @@
       }
       ClangASTContext::AddFieldToRecordType(
           union_type, element.name.c_str(),
-          CompilerType(&ast_ctx, element.type), lldb::eAccessPublic,
-          element.bitfield);
+          CompilerType(ClangASTContext::GetASTContext(&ast_ctx),
+                       element.type.getAsOpaquePtr()),
+          lldb::eAccessPublic, element.bitfield);
       ++count;
     }
     ClangASTContext::CompleteTagDeclarationDefinition(union_type);
@@ -172,7 +173,9 @@
   if (!lldb_ctx)
     return clang::QualType();
   CompilerType array_type(lldb_ctx->CreateArrayType(
-      CompilerType(&ast_ctx, element_type), size, false));
+      CompilerType(ClangASTContext::GetASTContext(&ast_ctx),
+                   element_type.getAsOpaquePtr()),
+      size, false));
   return ClangUtil::GetQualType(array_type);
 }
 
@@ -375,7 +378,8 @@
   if (name && name[0]) {
     StringLexer lexer(name);
     clang::QualType qual_type = BuildType(ast_ctx, lexer, for_expression);
-    return CompilerType(&ast_ctx, qual_type);
+    return CompilerType(ClangASTContext::GetASTContext(&ast_ctx),
+                        qual_type.getAsOpaquePtr());
   }
   return CompilerType();
 }
Index: lldb/source/Plugins/Language/ObjC/NSArray.cpp
===================================================================
--- lldb/source/Plugins/Language/ObjC/NSArray.cpp
+++ lldb/source/Plugins/Language/ObjC/NSArray.cpp
@@ -461,12 +461,13 @@
     : SyntheticChildrenFrontEnd(*valobj_sp), m_exe_ctx_ref(), m_ptr_size(8),
       m_id_type() {
   if (valobj_sp) {
-    clang::ASTContext *ast = valobj_sp->GetExecutionContextRef()
-                                 .GetTargetSP()
-                                 ->GetScratchClangASTContext()
-                                 ->getASTContext();
-    if (ast)
-      m_id_type = CompilerType(ast, ast->ObjCBuiltinIdTy);
+    auto *clang_ast_context = valobj_sp->GetExecutionContextRef()
+                                  .GetTargetSP()
+                                  ->GetScratchClangASTContext();
+    if (clang_ast_context)
+      m_id_type = CompilerType(
+          clang_ast_context,
+          clang_ast_context->getASTContext()->ObjCBuiltinIdTy.getAsOpaquePtr());
     if (valobj_sp->GetProcessSP())
       m_ptr_size = valobj_sp->GetProcessSP()->GetAddressByteSize();
   }
@@ -609,12 +610,13 @@
   if (valobj_sp) {
     CompilerType type = valobj_sp->GetCompilerType();
     if (type) {
-      ClangASTContext *ast = valobj_sp->GetExecutionContextRef()
-                                 .GetTargetSP()
-                                 ->GetScratchClangASTContext();
-      if (ast)
-        m_id_type = CompilerType(ast->getASTContext(),
-                                 ast->getASTContext()->ObjCBuiltinIdTy);
+      auto *clang_ast_context = valobj_sp->GetExecutionContextRef()
+                                    .GetTargetSP()
+                                    ->GetScratchClangASTContext();
+      if (clang_ast_context)
+        m_id_type = CompilerType(clang_ast_context,
+                                 clang_ast_context->getASTContext()
+                                     ->ObjCBuiltinIdTy.getAsOpaquePtr());
     }
   }
 }
Index: lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.h
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.h
+++ lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.h
@@ -10,6 +10,7 @@
 #ifndef liblldb_IRForTarget_h_
 #define liblldb_IRForTarget_h_
 
+#include "lldb/Core/ClangForward.h"
 #include "lldb/Symbol/TaggedASTType.h"
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/Status.h"
Index: lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
@@ -1277,8 +1277,10 @@
     if (value_decl == nullptr)
       return false;
 
-    lldb_private::CompilerType compiler_type(&value_decl->getASTContext(),
-                                             value_decl->getType());
+    lldb_private::CompilerType compiler_type(
+        lldb_private::ClangASTContext::GetASTContext(
+            &value_decl->getASTContext()),
+        value_decl->getType().getAsOpaquePtr());
 
     const Type *value_type = nullptr;
 
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -2066,7 +2066,8 @@
     // seems to be generating bad types on occasion.
     return CompilerType();
 
-  return CompilerType(m_ast_context, copied_qual_type);
+  return CompilerType(ClangASTContext::GetASTContext(m_ast_context),
+                      copied_qual_type.getAsOpaquePtr());
 }
 
 clang::NamedDecl *NameSearchContext::AddVarDecl(const CompilerType &type) {
@@ -2194,7 +2195,9 @@
       proto_info));
 
   return AddFunDecl(
-      CompilerType(m_ast_source.m_ast_context, generic_function_type), true);
+      CompilerType(ClangASTContext::GetASTContext(m_ast_source.m_ast_context),
+                   generic_function_type.getAsOpaquePtr()),
+      true);
 }
 
 clang::NamedDecl *
Index: lldb/include/lldb/Symbol/CompilerType.h
===================================================================
--- lldb/include/lldb/Symbol/CompilerType.h
+++ lldb/include/lldb/Symbol/CompilerType.h
@@ -13,7 +13,6 @@
 #include <string>
 #include <vector>
 
-#include "lldb/Core/ClangForward.h"
 #include "lldb/lldb-private.h"
 #include "llvm/ADT/APSInt.h"
 
@@ -32,7 +31,6 @@
 public:
   // Constructors and Destructors
   CompilerType(TypeSystem *type_system, lldb::opaque_compiler_type_t type);
-  CompilerType(clang::ASTContext *ast_context, clang::QualType qual_type);
 
   CompilerType(const CompilerType &rhs)
       : m_type(rhs.m_type), m_type_system(rhs.m_type_system) {}
@@ -169,8 +167,6 @@
   void SetCompilerType(TypeSystem *type_system,
                        lldb::opaque_compiler_type_t type);
 
-  void SetCompilerType(clang::ASTContext *ast, clang::QualType qual_type);
-
   unsigned GetTypeQualifiers() const;
 
   // Creating related types
Index: lldb/include/lldb/Symbol/ClangASTContext.h
===================================================================
--- lldb/include/lldb/Symbol/ClangASTContext.h
+++ lldb/include/lldb/Symbol/ClangASTContext.h
@@ -229,7 +229,8 @@
           if (const RecordDeclType *record_decl =
                   llvm::dyn_cast<RecordDeclType>(named_decl))
             compiler_type.SetCompilerType(
-                ast, clang::QualType(record_decl->getTypeForDecl(), 0));
+                this, clang::QualType(record_decl->getTypeForDecl(), 0)
+                          .getAsOpaquePtr());
         }
       }
     }
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to