Index: source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h =================================================================== --- source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h +++ source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h @@ -53,7 +53,7 @@ // Constructors and Destructors PdbAstBuilder(ObjectFile &obj, PdbIndex &index); - clang::DeclContext &GetTranslationUnitDecl(); + lldb_private::CompilerDeclContext GetTranslationUnitDecl(); clang::Decl *GetOrCreateDeclForUid(PdbSymUid uid); clang::DeclContext *GetOrCreateDeclContextForUid(PdbSymUid uid); Index: source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp =================================================================== --- source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp +++ source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp @@ -214,8 +214,10 @@ BuildParentMap(); } -clang::DeclContext &PdbAstBuilder::GetTranslationUnitDecl() { - return *m_clang.GetTranslationUnitDecl(); +lldb_private::CompilerDeclContext PdbAstBuilder::GetTranslationUnitDecl() { + auto decl_ctx = + CompilerDeclContext(&m_clang, m_clang.GetTranslationUnitDecl()); + return decl_ctx; } std::pair @@ -491,8 +493,12 @@ clang::DeclContext *PdbAstBuilder::GetOrCreateDeclContextForUid(PdbSymUid uid) { if (uid.kind() == PdbSymUidKind::CompilandSym) { - if (uid.asCompilandSym().offset == 0) - return &GetTranslationUnitDecl(); + if (uid.asCompilandSym().offset == 0) { + auto decl_ctx = GetTranslationUnitDecl(); + auto context = + static_cast(decl_ctx.GetOpaqueDeclContext()); + return context; + } } clang::Decl *decl = GetOrCreateDeclForUid(uid); @@ -507,7 +513,9 @@ MSVCUndecoratedNameParser parser(name); llvm::ArrayRef specs = parser.GetSpecifiers(); - clang::DeclContext *context = &GetTranslationUnitDecl(); + auto decl_ctx = GetTranslationUnitDecl(); + auto context = + static_cast(decl_ctx.GetOpaqueDeclContext()); llvm::StringRef uname = specs.back().GetBaseName(); specs = specs.drop_back(); @@ -547,8 +555,12 @@ llvm::ms_demangle::Demangler demangler; StringView name{pub->Name.begin(), pub->Name.size()}; llvm::ms_demangle::SymbolNode *node = demangler.parse(name); - if (!node) - return &GetTranslationUnitDecl(); + if (!node) { + auto decl_ctx = GetTranslationUnitDecl(); + auto context = + static_cast(decl_ctx.GetOpaqueDeclContext()); + return context; + } llvm::ArrayRef name_components{ node->Name->Components->Nodes, node->Name->Components->Count - 1}; @@ -569,7 +581,9 @@ } // It's not a type. It must be a series of namespaces. - clang::DeclContext *context = &GetTranslationUnitDecl(); + auto decl_ctx = GetTranslationUnitDecl(); + auto context = + static_cast(decl_ctx.GetOpaqueDeclContext()); while (!name_components.empty()) { std::string ns = name_components.front()->toString(); context = GetOrCreateNamespaceDecl(ns.c_str(), *context); @@ -596,8 +610,12 @@ // functions yet. Anyway, we just need to consult the parent type map. PdbTypeSymId type_id = uid.asTypeSym(); auto iter = m_parent_types.find(type_id.index); - if (iter == m_parent_types.end()) - return &GetTranslationUnitDecl(); + if (iter == m_parent_types.end()) { + auto decl_ctx = GetTranslationUnitDecl(); + auto context = + static_cast(decl_ctx.GetOpaqueDeclContext()); + return context; + } return GetOrCreateDeclContextForUid(PdbTypeSymId(iter->second)); } case PdbSymUidKind::FieldListMember: @@ -635,7 +653,10 @@ default: break; } - return &GetTranslationUnitDecl(); + auto decl_ctx = GetTranslationUnitDecl(); + auto context = + static_cast(decl_ctx.GetOpaqueDeclContext()); + return context; } bool PdbAstBuilder::CompleteType(clang::QualType qt) { @@ -866,7 +887,10 @@ return llvm::dyn_cast(decl); CVSymbol sym = m_index.ReadSymbolRecord(var_id); - return CreateVariableDecl(PdbSymUid(var_id), sym, GetTranslationUnitDecl()); + auto decl_ctx = GetTranslationUnitDecl(); + auto context = + static_cast(decl_ctx.GetOpaqueDeclContext()); + return CreateVariableDecl(PdbSymUid(var_id), sym, *context); } clang::TypedefNameDecl *