[Lldb-commits] [lldb] 0460a6b - [lldb][NFC] Remove most GetASTContext calls in AST metadata code

2019-12-29 Thread Raphael Isemann via lldb-commits

Author: Raphael Isemann
Date: 2019-12-29T16:33:40+01:00
New Revision: 0460a6bdf2f2b6c98eb6c72621baaf445aca34d5

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

LOG: [lldb][NFC] Remove most GetASTContext calls in AST metadata code

Added: 


Modified: 
lldb/include/lldb/Symbol/ClangASTContext.h
lldb/source/Symbol/ClangASTContext.cpp
lldb/source/Symbol/ClangASTImporter.cpp

Removed: 




diff  --git a/lldb/include/lldb/Symbol/ClangASTContext.h 
b/lldb/include/lldb/Symbol/ClangASTContext.h
index e25eae8180df..cb9b89cf3e10 100644
--- a/lldb/include/lldb/Symbol/ClangASTContext.h
+++ b/lldb/include/lldb/Symbol/ClangASTContext.h
@@ -132,20 +132,10 @@ class ClangASTContext : public TypeSystem {
   void SetMetadataAsUserID(const clang::Type *type, lldb::user_id_t user_id);
 
   void SetMetadata(const clang::Decl *object, ClangASTMetadata &meta_data);
-  void SetMetadata(const clang::Type *object, ClangASTMetadata &meta_data);
-  ClangASTMetadata *GetMetadata(const clang::Decl *object) {
-return GetMetadata(&getASTContext(), object);
-  }
-
-  static ClangASTMetadata *GetMetadata(clang::ASTContext *ast,
-   const clang::Decl *object);
 
-  ClangASTMetadata *GetMetadata(const clang::Type *object) {
-return GetMetadata(&getASTContext(), object);
-  }
-
-  static ClangASTMetadata *GetMetadata(clang::ASTContext *ast,
-   const clang::Type *object);
+  void SetMetadata(const clang::Type *object, ClangASTMetadata &meta_data);
+  ClangASTMetadata *GetMetadata(const clang::Decl *object);
+  ClangASTMetadata *GetMetadata(const clang::Type *object);
 
   // Basic Types
   CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding,

diff  --git a/lldb/source/Symbol/ClangASTContext.cpp 
b/lldb/source/Symbol/ClangASTContext.cpp
index 089d0177c8fc..5c78e9ff0c98 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -2335,20 +2335,16 @@ void ClangASTContext::SetMetadata(const clang::Type 
*object,
   m_type_metadata[object] = metadata;
 }
 
-ClangASTMetadata *ClangASTContext::GetMetadata(clang::ASTContext *ast,
-   const clang::Decl *object) {
-  ClangASTContext *self = GetASTContext(ast);
-  auto It = self->m_decl_metadata.find(object);
-  if (It != self->m_decl_metadata.end())
+ClangASTMetadata *ClangASTContext::GetMetadata(const clang::Decl *object) {
+  auto It = m_decl_metadata.find(object);
+  if (It != m_decl_metadata.end())
 return &It->second;
   return nullptr;
 }
 
-ClangASTMetadata *ClangASTContext::GetMetadata(clang::ASTContext *ast,
-   const clang::Type *object) {
-  ClangASTContext *self = GetASTContext(ast);
-  auto It = self->m_type_metadata.find(object);
-  if (It != self->m_type_metadata.end())
+ClangASTMetadata *ClangASTContext::GetMetadata(const clang::Type *object) {
+  auto It = m_type_metadata.find(object);
+  if (It != m_type_metadata.end())
 return &It->second;
   return nullptr;
 }
@@ -2746,8 +2742,7 @@ bool ClangASTContext::IsRuntimeGeneratedType(
   clang::ObjCInterfaceDecl *result_iface_decl =
   llvm::dyn_cast(decl_ctx);
 
-  ClangASTMetadata *ast_metadata =
-  ClangASTContext::GetMetadata(&getASTContext(), result_iface_decl);
+  ClangASTMetadata *ast_metadata = GetMetadata(result_iface_decl);
   if (!ast_metadata)
 return false;
   return (ast_metadata->GetISAPtr() != 0);
@@ -3398,8 +3393,7 @@ bool 
ClangASTContext::IsPossibleDynamicType(lldb::opaque_compiler_type_t type,
 if (is_complete)
   success = cxx_record_decl->isDynamicClass();
 else {
-  ClangASTMetadata *metadata = ClangASTContext::GetMetadata(
-  &getASTContext(), cxx_record_decl);
+  ClangASTMetadata *metadata = GetMetadata(cxx_record_decl);
   if (metadata)
 success = metadata->GetIsDynamicCXXType();
   else {
@@ -8729,8 +8723,7 @@ void 
ClangASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type) {
 
   CompilerType ct(this, type);
   const clang::Type *clang_type = ClangUtil::GetQualType(ct).getTypePtr();
-  ClangASTMetadata *metadata =
-  ClangASTContext::GetMetadata(&getASTContext(), clang_type);
+  ClangASTMetadata *metadata = GetMetadata(clang_type);
   if (metadata) {
 metadata->Dump(&s);
   }
@@ -9268,8 +9261,7 @@ bool ClangASTContext::DeclContextIsClassMethod(
   return true;
 } else if (clang::FunctionDecl *function_decl =
llvm::dyn_cast(decl_ctx)) {
-  ClangASTMetadata *metadata =
-  GetMetadata(&decl_ctx->getParentASTContext(), function_decl);
+  ClangASTMetadata *met

[Lldb-commits] [lldb] 0007f9d - [lldb][NFC] Delete static versions of ClangASTContext::CreateFunctionType

2019-12-29 Thread Raphael Isemann via lldb-commits

Author: Raphael Isemann
Date: 2019-12-29T20:27:05+01:00
New Revision: 0007f9da7c0c780e2466759c1e53b1109a54e400

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

LOG: [lldb][NFC] Delete static versions of ClangASTContext::CreateFunctionType

We can always call the member function version of this function.

Added: 


Modified: 
lldb/include/lldb/Symbol/ClangASTContext.h
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
lldb/source/Symbol/ClangASTContext.cpp

Removed: 




diff  --git a/lldb/include/lldb/Symbol/ClangASTContext.h 
b/lldb/include/lldb/Symbol/ClangASTContext.h
index cb9b89cf3e10..7bc5c5912aaa 100644
--- a/lldb/include/lldb/Symbol/ClangASTContext.h
+++ b/lldb/include/lldb/Symbol/ClangASTContext.h
@@ -315,36 +315,16 @@ class ClangASTContext : public TypeSystem {
 const CompilerType &function_Type, int storage,
 bool is_inline);
 
-  static CompilerType CreateFunctionType(clang::ASTContext *ast,
- const CompilerType &result_type,
- const CompilerType *args,
- unsigned num_args, bool is_variadic,
- unsigned type_quals,
- clang::CallingConv cc);
-
-  static CompilerType CreateFunctionType(clang::ASTContext *ast,
- const CompilerType &result_type,
- const CompilerType *args,
- unsigned num_args, bool is_variadic,
- unsigned type_quals) {
-return ClangASTContext::CreateFunctionType(
-ast, result_type, args, num_args, is_variadic, type_quals, 
clang::CC_C);
-  }
-
   CompilerType CreateFunctionType(const CompilerType &result_type,
   const CompilerType *args, unsigned num_args,
-  bool is_variadic, unsigned type_quals) {
-return ClangASTContext::CreateFunctionType(
-&getASTContext(), result_type, args, num_args, is_variadic, 
type_quals);
-  }
+  bool is_variadic, unsigned type_quals,
+  clang::CallingConv cc);
 
   CompilerType CreateFunctionType(const CompilerType &result_type,
   const CompilerType *args, unsigned num_args,
-  bool is_variadic, unsigned type_quals,
-  clang::CallingConv cc) {
-return ClangASTContext::CreateFunctionType(&getASTContext(), result_type,
-   args, num_args, is_variadic,
-   type_quals, cc);
+  bool is_variadic, unsigned type_quals) {
+return CreateFunctionType(result_type, args, num_args, is_variadic,
+  type_quals, clang::CC_C);
   }
 
   clang::ParmVarDecl *CreateParameterDeclaration(clang::DeclContext *decl_ctx,

diff  --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
index ec1f3478df2a..6634824be01f 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -1955,8 +1955,8 @@ void 
ClangExpressionDeclMap::AddThisType(NameSearchContext &context,
 m_clang_ast_context->GetBasicType(eBasicTypeVoid);
 CompilerType void_ptr_clang_type = void_clang_type.GetPointerType();
 
-CompilerType method_type = ClangASTContext::CreateFunctionType(
-m_ast_context, void_clang_type, &void_ptr_clang_type, 1, false, 0);
+CompilerType method_type = m_clang_ast_context->CreateFunctionType(
+void_clang_type, &void_ptr_clang_type, 1, false, 0);
 
 const bool is_virtual = false;
 const bool is_static = false;

diff  --git a/lldb/source/Symbol/ClangASTContext.cpp 
b/lldb/source/Symbol/ClangASTContext.cpp
index 5c78e9ff0c98..0664db37a04c 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -1917,13 +1917,11 @@ FunctionDecl 
*ClangASTContext::CreateFunctionDeclaration(
   return func_decl;
 }
 
-CompilerType ClangASTContext::CreateFunctionType(
-ASTContext *ast, const CompilerType &result_type, const CompilerType *args,
-unsigned num_args, bool is_variadic, unsigned type_quals,
-clang::CallingConv cc) {
-  if (ast == nullptr)
-return CompilerType(); // invalid AST
-
+CompilerType
+ClangASTContext::CreateFunctionType(const CompilerTy

[Lldb-commits] [PATCH] D63540: Fix lookup of symbols with the same address range but different binding

2019-12-29 Thread Jan Kratochvil via Phabricator via lldb-commits
jankratochvil marked an inline comment as done.
jankratochvil added a comment.

In D63540#1791017 , @labath wrote:

> Defining some sort of a preference based on symbol type seems like a good 
> idea, but I don't think this is a good way to implement it. If I read this 
> patch correctly, then this for example means that the "less global" symbols 
> will not be reported through the Symtab::ForEachSymbolContainingFileAddress 
> API, which seems like a bad thing.


Is this update OK now? Thanks for the review.

> I'm also not happy that this is supposed to be a replacement for the size 
> setting patch, as I believe (and I think we've agreed on that while reviewing 
> the original patch) that *not* fiddling with the sizes of those symbols is a 
> good thing.

I agree although I think this new "bindings priority" patch is also a good 
thing on its own and it is easier to implement. IMHO we can then continue with 
the "sizeless" patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63540/new/

https://reviews.llvm.org/D63540



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D63540: Fix lookup of symbols with the same address range but different binding

2019-12-29 Thread Jan Kratochvil via Phabricator via lldb-commits
jankratochvil updated this revision to Diff 235518.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63540/new/

https://reviews.llvm.org/D63540

Files:
  lldb/include/lldb/Utility/RangeMap.h
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/source/Symbol/Symtab.cpp
  lldb/test/Shell/SymbolFile/Inputs/symbol-binding.s
  lldb/test/Shell/SymbolFile/symbol-binding.test

Index: lldb/test/Shell/SymbolFile/symbol-binding.test
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/symbol-binding.test
@@ -0,0 +1,22 @@
+# Some targets do not have the .size directive.
+# RUN: %clang -target x86_64-unknown-unknown-elf %S/Inputs/symbol-binding.s -c -o %t.o
+# RUN: %lldb %t.o -s %s -o quit | FileCheck %s
+
+image lookup --address 4
+# CHECK: Summary: symbol-binding.test.tmp.o`case1_global
+image lookup --address 5
+# CHECK: Summary: symbol-binding.test.tmp.o`case2_weak
+image lookup --address 6
+# CHECK: Summary: symbol-binding.test.tmp.o`case3_global
+image dump symtab
+# CHECK: Index   UserID DSX TypeFile Address/Value Load Address   Size   Flags  Name
+# CHECK-NEXT:--- -- --- --- -- -- -- -- --
+# CHECK-NEXT:[0]  1 Code0x00040x0001 0x case1_local
+# CHECK-NEXT:[1]  2 Code0x00050x0001 0x case2_local
+# CHECK-NEXT:[2]  3 Code0x00030x0001 0x sizeend
+# CHECK-NEXT:[3]  4 Code0x00010x0002 0x sizeful
+# CHECK-NEXT:[4]  5 Code0x00010x0002 0x sizeless
+# CHECK-NEXT:[5]  6   X Code0x00040x0001 0x0010 case1_global
+# CHECK-NEXT:[6]  7 Code0x00050x0001 0x0020 case2_weak
+# CHECK-NEXT:[7]  8   X Code0x00060x0001 0x0010 case3_global
+# CHECK-NEXT:[8]  9 Code0x00060x0001 0x0020 case3_weak
Index: lldb/test/Shell/SymbolFile/Inputs/symbol-binding.s
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/Inputs/symbol-binding.s
@@ -0,0 +1,22 @@
+.text
+.byte   0
+sizeless:
+sizeful:
+.byte   0
+.byte   0
+sizeend:
+.size   sizeful, sizeend - sizeful
+.byte   0
+case1_local:
+case1_global:
+.globl  case1_global
+.byte   0
+case2_local:
+case2_weak:
+.weak   case2_weak
+.byte   0
+case3_weak:
+.weak   case3_weak
+case3_global:
+.globl  case3_global
+.byte   0
Index: lldb/source/Symbol/Symtab.cpp
===
--- lldb/source/Symbol/Symtab.cpp
+++ lldb/source/Symbol/Symtab.cpp
@@ -928,8 +928,27 @@
 }
   }
 
+  // How much preferred is this symbol?
+  auto rank = [this](const FileRangeToIndexMap::Entry &entry) {
+const Symbol &symbol = *SymbolAtIndex(entry.data);
+if (symbol.IsExternal())
+  return 3;
+else if (symbol.IsWeak())
+  return 2;
+else if (symbol.IsDebug())
+  return 0;
+return 1;
+  };
+
   // Sort again in case the range size changes the ordering
-  m_file_addr_to_index.Sort();
+  m_file_addr_to_index.Sort([rank](const FileRangeToIndexMap::Entry &a,
+   const FileRangeToIndexMap::Entry &b) {
+// For each matching address range choose the most global symbol.
+if (a.GetRangeBase() != b.GetRangeBase() ||
+a.GetByteSize() != b.GetByteSize())
+  return a < b;
+return rank(a) > rank(b);
+  });
 }
   }
 }
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2258,6 +2258,8 @@
 symbol_size_valid,  // Symbol size is valid
 has_suffix, // Contains linker annotations?
 flags); // Symbol flags.
+if (symbol.getBinding() == STB_WEAK)
+  dc_symbol.SetIsWeak(true);
 symtab->AddSymbol(dc_symbol);
   }
   return i;
Index: lldb/include/lldb/Utility/RangeMap.h
===
--- lldb/include/lldb/Utility/RangeMap.h
++

[Lldb-commits] [lldb] 6991d57 - [lldb][NFC] Make integer types functions in ClangASTContext not static

2019-12-29 Thread Raphael Isemann via lldb-commits

Author: Raphael Isemann
Date: 2019-12-29T21:54:07+01:00
New Revision: 6991d5728f12594cabfd8d8d570361efb07f1d5a

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

LOG: [lldb][NFC] Make integer types functions in ClangASTContext not static

These functions need a ClangASTContext instance that we would otherwise
recalculate by calling GetASTContext (which is no longer necessary with
this patch).

Added: 


Modified: 
lldb/include/lldb/Symbol/ClangASTContext.h
lldb/source/Symbol/ClangASTContext.cpp

Removed: 




diff  --git a/lldb/include/lldb/Symbol/ClangASTContext.h 
b/lldb/include/lldb/Symbol/ClangASTContext.h
index 7bc5c5912aaa..9307825675cf 100644
--- a/lldb/include/lldb/Symbol/ClangASTContext.h
+++ b/lldb/include/lldb/Symbol/ClangASTContext.h
@@ -352,15 +352,9 @@ class ClangASTContext : public TypeSystem {
 
   // Integer type functions
 
-  static CompilerType GetIntTypeFromBitSize(clang::ASTContext *ast,
-size_t bit_size, bool is_signed);
+  CompilerType GetIntTypeFromBitSize(size_t bit_size, bool is_signed);
 
-  CompilerType GetPointerSizedIntType(bool is_signed) {
-return GetPointerSizedIntType(&getASTContext(), is_signed);
-  }
-
-  static CompilerType GetPointerSizedIntType(clang::ASTContext *ast,
- bool is_signed);
+  CompilerType GetPointerSizedIntType(bool is_signed);
 
   // Floating point functions
 

diff  --git a/lldb/source/Symbol/ClangASTContext.cpp 
b/lldb/source/Symbol/ClangASTContext.cpp
index 0664db37a04c..e9727399d7ec 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -2094,66 +2094,53 @@ ClangASTContext::CreateEnumerationType(const char 
*name, DeclContext *decl_ctx,
   return CompilerType();
 }
 
-CompilerType ClangASTContext::GetIntTypeFromBitSize(clang::ASTContext *ast,
-size_t bit_size,
+CompilerType ClangASTContext::GetIntTypeFromBitSize(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(clang_ast_context,
-ast->SignedCharTy.getAsOpaquePtr());
+  clang::ASTContext &ast = getASTContext();
 
-  if (bit_size == ast->getTypeSize(ast->ShortTy))
-return CompilerType(clang_ast_context, ast->ShortTy.getAsOpaquePtr());
+  if (is_signed) {
+if (bit_size == ast.getTypeSize(ast.SignedCharTy))
+  return CompilerType(this, ast.SignedCharTy.getAsOpaquePtr());
 
-  if (bit_size == ast->getTypeSize(ast->IntTy))
-return CompilerType(clang_ast_context, ast->IntTy.getAsOpaquePtr());
+if (bit_size == ast.getTypeSize(ast.ShortTy))
+  return CompilerType(this, ast.ShortTy.getAsOpaquePtr());
 
-  if (bit_size == ast->getTypeSize(ast->LongTy))
-return CompilerType(clang_ast_context, ast->LongTy.getAsOpaquePtr());
+if (bit_size == ast.getTypeSize(ast.IntTy))
+  return CompilerType(this, ast.IntTy.getAsOpaquePtr());
 
-  if (bit_size == ast->getTypeSize(ast->LongLongTy))
-return CompilerType(clang_ast_context,
-ast->LongLongTy.getAsOpaquePtr());
+if (bit_size == ast.getTypeSize(ast.LongTy))
+  return CompilerType(this, ast.LongTy.getAsOpaquePtr());
 
-  if (bit_size == ast->getTypeSize(ast->Int128Ty))
-return CompilerType(clang_ast_context, ast->Int128Ty.getAsOpaquePtr());
-} else {
-  if (bit_size == ast->getTypeSize(ast->UnsignedCharTy))
-return CompilerType(clang_ast_context,
-ast->UnsignedCharTy.getAsOpaquePtr());
+if (bit_size == ast.getTypeSize(ast.LongLongTy))
+  return CompilerType(this, ast.LongLongTy.getAsOpaquePtr());
 
-  if (bit_size == ast->getTypeSize(ast->UnsignedShortTy))
-return CompilerType(clang_ast_context,
-ast->UnsignedShortTy.getAsOpaquePtr());
+if (bit_size == ast.getTypeSize(ast.Int128Ty))
+  return CompilerType(this, ast.Int128Ty.getAsOpaquePtr());
+  } else {
+if (bit_size == ast.getTypeSize(ast.UnsignedCharTy))
+  return CompilerType(this, ast.UnsignedCharTy.getAsOpaquePtr());
 
-  if (bit_size == ast->getTypeSize(ast->UnsignedIntTy))
-return CompilerType(clang_ast_context,
-ast->UnsignedIntTy.getAsOpaquePtr());
+if (bit_size == ast.getTypeSize(ast.UnsignedShortTy))
+  return CompilerType(this, ast.UnsignedShortTy.getAsOpaquePtr());
 
-  if (bit_size == ast->getTypeSize(ast->UnsignedLongTy))
-return CompilerType(clang_

[Lldb-commits] [lldb] b1fb07d - [lldb][NFC] Simplify ClangASTContext::GetTypeForDecl

2019-12-29 Thread Raphael Isemann via lldb-commits

Author: Raphael Isemann
Date: 2019-12-30T00:22:23+01:00
New Revision: b1fb07ddbaa539f9173e32dc27110168b165c1fe

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

LOG: [lldb][NFC] Simplify ClangASTContext::GetTypeForDecl

Also removes the GetASTContext call from this code.

Added: 


Modified: 
lldb/include/lldb/Symbol/ClangASTContext.h
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
lldb/source/Symbol/ClangASTContext.cpp

Removed: 




diff  --git a/lldb/include/lldb/Symbol/ClangASTContext.h 
b/lldb/include/lldb/Symbol/ClangASTContext.h
index 9307825675cf..e9a1d536ca8e 100644
--- a/lldb/include/lldb/Symbol/ClangASTContext.h
+++ b/lldb/include/lldb/Symbol/ClangASTContext.h
@@ -164,11 +164,11 @@ class ClangASTContext : public TypeSystem {
   static bool AreTypesSame(CompilerType type1, CompilerType type2,
bool ignore_qualifiers = false);
 
-  static CompilerType GetTypeForDecl(clang::NamedDecl *decl);
+  CompilerType GetTypeForDecl(clang::NamedDecl *decl);
 
-  static CompilerType GetTypeForDecl(clang::TagDecl *decl);
+  CompilerType GetTypeForDecl(clang::TagDecl *decl);
 
-  static CompilerType GetTypeForDecl(clang::ObjCInterfaceDecl *objc_decl);
+  CompilerType GetTypeForDecl(clang::ObjCInterfaceDecl *objc_decl);
 
   template 
   CompilerType

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index e5c37e771945..96dd72bb1009 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -255,7 +255,8 @@ TypeSP DWARFASTParserClang::ParseTypeFromClangModule(const 
SymbolContext &sc,
   return type_sp;
 }
 
-static void CompleteExternalTagDeclType(ClangASTImporter &ast_importer,
+static void CompleteExternalTagDeclType(ClangASTContext &ast,
+ClangASTImporter &ast_importer,
 clang::DeclContext *decl_ctx,
 DWARFDIE die,
 const char *type_name_cstr) {
@@ -264,7 +265,7 @@ static void CompleteExternalTagDeclType(ClangASTImporter 
&ast_importer,
 return;
 
   // If this type was not imported from an external AST, there's nothing to do.
-  CompilerType type = ClangASTContext::GetTypeForDecl(tag_decl_ctx);
+  CompilerType type = ast.GetTypeForDecl(tag_decl_ctx);
   if (!type || !ast_importer.CanImport(type))
 return;
 
@@ -1594,7 +1595,7 @@ DWARFASTParserClang::ParseStructureLikeDIE(const 
SymbolContext &sc,
 // backing the Decl is complete before adding children to it. This is
 // not an issue in the non-gmodules case because the debug info will
 // always contain a full definition of parent types in that case.
-CompleteExternalTagDeclType(GetClangASTImporter(), decl_ctx, die,
+CompleteExternalTagDeclType(m_ast, GetClangASTImporter(), decl_ctx, die,
 attrs.name.GetCString());
 
 if (attrs.accessibility == eAccessNone && decl_ctx) {

diff  --git a/lldb/source/Symbol/ClangASTContext.cpp 
b/lldb/source/Symbol/ClangASTContext.cpp
index e9727399d7ec..d226a34b1ac4 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -1179,25 +1179,13 @@ CompilerType 
ClangASTContext::GetTypeForDecl(clang::NamedDecl *decl) {
 }
 
 CompilerType ClangASTContext::GetTypeForDecl(TagDecl *decl) {
-  // No need to call the getASTContext() accessor (which can create the AST if
-  // it isn't created yet, because we can't have created a decl in this
-  // AST if our AST didn't already exist...
-  ASTContext *ast = &decl->getASTContext();
-  if (ast)
-return CompilerType(ClangASTContext::GetASTContext(ast),
-ast->getTagDeclType(decl).getAsOpaquePtr());
-  return CompilerType();
+  return CompilerType(this,
+  getASTContext().getTagDeclType(decl).getAsOpaquePtr());
 }
 
 CompilerType ClangASTContext::GetTypeForDecl(ObjCInterfaceDecl *decl) {
-  // No need to call the getASTContext() accessor (which can create the AST if
-  // it isn't created yet, because we can't have created a decl in this
-  // AST if our AST didn't already exist...
-  ASTContext *ast = &decl->getASTContext();
-  if (ast)
-return CompilerType(ClangASTContext::GetASTContext(ast),
-ast->getObjCInterfaceType(decl).getAsOpaquePtr());
-  return CompilerType();
+  return CompilerType(
+  this, getASTContext().getObjCInterfaceType(decl).getAsOpaquePtr());
 }
 
 #pragma mark Structure, Unions, Classes
@@ -9183,7 +9171,7 @@ uint32_t 
ClangASTContext::CountDeclLevels(clang::DeclContext *frame_decl_ctx,