Index: lldb/include/lldb/Symbol/ClangExternalASTSourceCommon.h =================================================================== --- lldb/include/lldb/Symbol/ClangExternalASTSourceCommon.h +++ lldb/include/lldb/Symbol/ClangExternalASTSourceCommon.h @@ -122,14 +122,18 @@ }; class ClangExternalASTSourceCommon : public clang::ExternalASTSource { + static char ID; + public: - ClangExternalASTSourceCommon(); + ClangExternalASTSourceCommon() = default; ~ClangExternalASTSourceCommon() override; ClangASTMetadata *GetMetadata(const void *object); void SetMetadata(const void *object, ClangASTMetadata &metadata); - static ClangExternalASTSourceCommon *Lookup(clang::ExternalASTSource *source); + // LLVM-style RTTI. + bool isA(const void *ClassID) const override { return ClassID == &ID; } + static bool classof(const ExternalASTSource *S) { return S->isA(&ID); } private: typedef llvm::DenseMap MetadataMap; Index: lldb/source/Symbol/ClangASTContext.cpp =================================================================== --- lldb/source/Symbol/ClangASTContext.cpp +++ lldb/source/Symbol/ClangASTContext.cpp @@ -2407,22 +2407,18 @@ void ClangASTContext::SetMetadata(clang::ASTContext *ast, const void *object, ClangASTMetadata &metadata) { - ClangExternalASTSourceCommon *external_source = - ClangExternalASTSourceCommon::Lookup(ast->getExternalSource()); - - if (external_source) - external_source->SetMetadata(object, metadata); + if (auto *A = llvm::dyn_cast_or_null( + ast->getExternalSource())) + A->SetMetadata(object, metadata); } ClangASTMetadata *ClangASTContext::GetMetadata(clang::ASTContext *ast, const void *object) { - ClangExternalASTSourceCommon *external_source = - ClangExternalASTSourceCommon::Lookup(ast->getExternalSource()); - if (external_source) - return external_source->GetMetadata(object); - else - return nullptr; + if (auto *A = llvm::dyn_cast_or_null( + ast->getExternalSource())) + return A->GetMetadata(object); + return nullptr; } bool ClangASTContext::SetTagTypeKind(clang::QualType tag_qual_type, Index: lldb/source/Symbol/ClangExternalASTSourceCommon.cpp =================================================================== --- lldb/source/Symbol/ClangExternalASTSourceCommon.cpp +++ lldb/source/Symbol/ClangExternalASTSourceCommon.cpp @@ -13,43 +13,9 @@ using namespace lldb_private; -typedef llvm::DenseMap - ASTSourceMap; +char ClangExternalASTSourceCommon::ID; -static ASTSourceMap &GetSourceMap(std::unique_lock &guard) { - // Intentionally leaked to avoid problems with global destructors. - static ASTSourceMap *s_source_map = new ASTSourceMap; - static std::mutex s_mutex; - std::unique_lock locked_guard(s_mutex); - guard.swap(locked_guard); - return *s_source_map; -} - -ClangExternalASTSourceCommon * -ClangExternalASTSourceCommon::Lookup(clang::ExternalASTSource *source) { - std::unique_lock guard; - ASTSourceMap &source_map = GetSourceMap(guard); - - ASTSourceMap::iterator iter = source_map.find(source); - - if (iter != source_map.end()) { - return iter->second; - } else { - return nullptr; - } -} - -ClangExternalASTSourceCommon::ClangExternalASTSourceCommon() - : clang::ExternalASTSource() { - std::unique_lock guard; - GetSourceMap(guard)[this] = this; -} - -ClangExternalASTSourceCommon::~ClangExternalASTSourceCommon() { - std::unique_lock guard; - GetSourceMap(guard).erase(this); -} +ClangExternalASTSourceCommon::~ClangExternalASTSourceCommon() {} ClangASTMetadata * ClangExternalASTSourceCommon::GetMetadata(const void *object) {