Index: source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h =================================================================== --- source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h +++ source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h @@ -53,9 +53,9 @@ // Constructors and Destructors PdbAstBuilder(ObjectFile &obj, PdbIndex &index); - clang::DeclContext &GetTranslationUnitDecl(); + lldb_private::CompilerDeclContext GetTranslationUnitDecl(); - clang::Decl *GetOrCreateDeclForUid(PdbSymUid uid); + lldb_private::CompilerDecl GetOrCreateDeclForUid(PdbSymUid uid); clang::DeclContext *GetOrCreateDeclContextForUid(PdbSymUid uid); clang::DeclContext *GetParentDeclContext(PdbSymUid uid); @@ -76,6 +76,7 @@ CompilerDecl ToCompilerDecl(clang::Decl &decl); CompilerType ToCompilerType(clang::QualType qt); CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context); + clang::Decl * FromCompilerDecl(CompilerDecl decl); clang::DeclContext *FromCompilerDeclContext(CompilerDeclContext context); ClangASTContext &clang() { return m_clang; } Index: source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp =================================================================== --- source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp +++ source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp @@ -214,8 +214,8 @@ BuildParentMap(); } -clang::DeclContext &PdbAstBuilder::GetTranslationUnitDecl() { - return *m_clang.GetTranslationUnitDecl(); +lldb_private::CompilerDeclContext PdbAstBuilder::GetTranslationUnitDecl() { + return ToCompilerDeclContext(*m_clang.GetTranslationUnitDecl()); } std::pair @@ -465,9 +465,9 @@ } } -clang::Decl *PdbAstBuilder::GetOrCreateDeclForUid(PdbSymUid uid) { +lldb_private::CompilerDecl PdbAstBuilder::GetOrCreateDeclForUid(PdbSymUid uid) { if (clang::Decl *result = TryGetDecl(uid)) - return result; + return ToCompilerDecl(*result); clang::Decl *result = nullptr; switch (uid.kind()) { @@ -480,22 +480,22 @@ result = tag; break; } - return nullptr; + return CompilerDecl(); } default: - return nullptr; + return CompilerDecl(); } m_uid_to_decl[toOpaqueUid(uid)] = result; - return result; + return ToCompilerDecl(*result); } clang::DeclContext *PdbAstBuilder::GetOrCreateDeclContextForUid(PdbSymUid uid) { if (uid.kind() == PdbSymUidKind::CompilandSym) { if (uid.asCompilandSym().offset == 0) - return &GetTranslationUnitDecl(); + return FromCompilerDeclContext(GetTranslationUnitDecl()); } - clang::Decl *decl = GetOrCreateDeclForUid(uid); + clang::Decl *decl = FromCompilerDecl(GetOrCreateDeclForUid(uid)); if (!decl) return nullptr; @@ -507,7 +507,7 @@ MSVCUndecoratedNameParser parser(name); llvm::ArrayRef specs = parser.GetSpecifiers(); - clang::DeclContext *context = &GetTranslationUnitDecl(); + auto context = FromCompilerDeclContext(GetTranslationUnitDecl()); llvm::StringRef uname = specs.back().GetBaseName(); specs = specs.drop_back(); @@ -548,7 +548,7 @@ StringView name{pub->Name.begin(), pub->Name.size()}; llvm::ms_demangle::SymbolNode *node = demangler.parse(name); if (!node) - return &GetTranslationUnitDecl(); + return FromCompilerDeclContext(GetTranslationUnitDecl()); llvm::ArrayRef name_components{ node->Name->Components->Nodes, node->Name->Components->Count - 1}; @@ -569,7 +569,7 @@ } // It's not a type. It must be a series of namespaces. - clang::DeclContext *context = &GetTranslationUnitDecl(); + auto context = FromCompilerDeclContext(GetTranslationUnitDecl()); while (!name_components.empty()) { std::string ns = name_components.front()->toString(); context = GetOrCreateNamespaceDecl(ns.c_str(), *context); @@ -597,7 +597,7 @@ PdbTypeSymId type_id = uid.asTypeSym(); auto iter = m_parent_types.find(type_id.index); if (iter == m_parent_types.end()) - return &GetTranslationUnitDecl(); + return FromCompilerDeclContext(GetTranslationUnitDecl()); return GetOrCreateDeclContextForUid(PdbTypeSymId(iter->second)); } case PdbSymUidKind::FieldListMember: @@ -635,7 +635,7 @@ default: break; } - return &GetTranslationUnitDecl(); + return FromCompilerDeclContext(GetTranslationUnitDecl()); } bool PdbAstBuilder::CompleteType(clang::QualType qt) { @@ -866,7 +866,8 @@ return llvm::dyn_cast(decl); CVSymbol sym = m_index.ReadSymbolRecord(var_id); - return CreateVariableDecl(PdbSymUid(var_id), sym, GetTranslationUnitDecl()); + auto context = FromCompilerDeclContext(GetTranslationUnitDecl()); + return CreateVariableDecl(PdbSymUid(var_id), sym, *context); } clang::TypedefNameDecl * @@ -1353,6 +1354,10 @@ return {&m_clang, &context}; } +clang::Decl * PdbAstBuilder::FromCompilerDecl(CompilerDecl decl) { + return static_cast(decl.GetOpaqueDecl()); +} + clang::DeclContext * PdbAstBuilder::FromCompilerDeclContext(CompilerDeclContext context) { return static_cast(context.GetOpaqueDeclContext()); Index: source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp =================================================================== --- source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -1506,9 +1506,7 @@ } CompilerDecl SymbolFileNativePDB::GetDeclForUID(lldb::user_id_t uid) { - clang::Decl *decl = m_ast->GetOrCreateDeclForUid(PdbSymUid(uid)); - - return m_ast->ToCompilerDecl(*decl); + return m_ast->GetOrCreateDeclForUid(uid); } CompilerDeclContext