Index: source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h =================================================================== --- source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h +++ source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h @@ -57,7 +57,7 @@ lldb_private::CompilerDecl GetOrCreateDeclForUid(PdbSymUid uid); lldb_private::CompilerDeclContext GetOrCreateDeclContextForUid(PdbSymUid uid); - clang::DeclContext *GetParentDeclContext(PdbSymUid uid); + lldb_private::CompilerDeclContext GetParentDeclContext(PdbSymUid uid); clang::FunctionDecl *GetOrCreateFunctionDecl(PdbCompilandSymId func_id); clang::BlockDecl *GetOrCreateBlockDecl(PdbCompilandSymId block_id); Index: source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp =================================================================== --- source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp +++ source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp @@ -444,7 +444,9 @@ CVSymbol cvs = m_index.ReadSymbolRecord(id); if (isLocalVariableType(cvs.kind())) { - clang::DeclContext *scope = GetParentDeclContext(id); + lldb_private::CompilerDeclContext decl_ctx = GetParentDeclContext(id); + auto scope = + static_cast(decl_ctx.GetOpaqueDeclContext()); clang::Decl *scope_decl = clang::Decl::castFromDeclContext(scope); PdbCompilandSymId scope_id(id.modi, m_decl_to_status[scope_decl].uid); return GetOrCreateVariableDecl(scope_id, id); @@ -598,40 +600,29 @@ return context; } -clang::DeclContext *PdbAstBuilder::GetParentDeclContext(PdbSymUid uid) { +lldb_private::CompilerDeclContext +PdbAstBuilder::GetParentDeclContext(PdbSymUid uid) { // We must do this *without* calling GetOrCreate on the current uid, as // that would be an infinite recursion. switch (uid.kind()) { case PdbSymUidKind::CompilandSym: { llvm::Optional scope = FindSymbolScope(m_index, uid.asCompilandSym()); - if (scope) { - lldb_private::CompilerDeclContext decl_ctx = - GetOrCreateDeclContextForUid(*scope); - auto ctx = - static_cast(decl_ctx.GetOpaqueDeclContext()); - return ctx; - } + if (scope) + return GetOrCreateDeclContextForUid(*scope); CVSymbol sym = m_index.ReadSymbolRecord(uid.asCompilandSym()); - return GetParentDeclContextForSymbol(sym); + clang::DeclContext *decl_ctx = GetParentDeclContextForSymbol(sym); + return CompilerDeclContext(&m_clang, decl_ctx); } case PdbSymUidKind::Type: { // It could be a namespace, class, or global. We don't support nested // 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()) { - auto decl_ctx = GetTranslationUnitDecl(); - auto context = - static_cast(decl_ctx.GetOpaqueDeclContext()); - return context; - } - lldb_private::CompilerDeclContext decl_ctx = - GetOrCreateDeclContextForUid(PdbTypeSymId(iter->second)); - auto ctx = - static_cast(decl_ctx.GetOpaqueDeclContext()); - return ctx; + if (iter == m_parent_types.end()) + return GetTranslationUnitDecl(); + return GetOrCreateDeclContextForUid(PdbTypeSymId(iter->second)); } case PdbSymUidKind::FieldListMember: // In this case the parent DeclContext is the one for the class that this @@ -647,8 +638,10 @@ CVSymbol global = m_index.ReadSymbolRecord(uid.asGlobalSym()); switch (global.kind()) { case SymbolKind::S_GDATA32: - case SymbolKind::S_LDATA32: - return GetParentDeclContextForSymbol(global); + case SymbolKind::S_LDATA32: { + clang::DeclContext *decl_ctx = GetParentDeclContextForSymbol(global); + return CompilerDeclContext(&m_clang, decl_ctx); + } case SymbolKind::S_PROCREF: case SymbolKind::S_LPROCREF: { ProcRefSym ref{global.kind()}; @@ -658,8 +651,11 @@ return GetParentDeclContext(cu_sym_id); } case SymbolKind::S_CONSTANT: - case SymbolKind::S_UDT: - return CreateDeclInfoForUndecoratedName(getSymbolName(global)).first; + case SymbolKind::S_UDT: { + clang::DeclContext *decl_ctx = + CreateDeclInfoForUndecoratedName(getSymbolName(global)).first; + return CompilerDeclContext(&m_clang, decl_ctx); + } default: break; } @@ -668,10 +664,7 @@ default: break; } - auto decl_ctx = GetTranslationUnitDecl(); - auto context = - static_cast(decl_ctx.GetOpaqueDeclContext()); - return context; + return GetTranslationUnitDecl(); } bool PdbAstBuilder::CompleteType(clang::QualType qt) { @@ -856,7 +849,9 @@ if (clang::Decl *decl = TryGetDecl(block_id)) return llvm::dyn_cast(decl); - clang::DeclContext *scope = GetParentDeclContext(block_id); + lldb_private::CompilerDeclContext decl_ctx = GetParentDeclContext(block_id); + auto scope = + static_cast(decl_ctx.GetOpaqueDeclContext()); clang::BlockDecl *block_decl = m_clang.CreateBlockDeclaration(scope); m_uid_to_decl.insert({toOpaqueUid(block_id), block_decl}); @@ -920,7 +915,9 @@ lldbassert(sym.kind() == S_UDT); UDTSym udt = llvm::cantFail(SymbolDeserializer::deserializeAs(sym)); - clang::DeclContext *scope = GetParentDeclContext(id); + lldb_private::CompilerDeclContext decl_ctx = GetParentDeclContext(id); + auto scope = + static_cast(decl_ctx.GetOpaqueDeclContext()); PdbTypeSymId real_type_id{udt.Type, false}; clang::QualType qt = GetOrCreateType(real_type_id); @@ -1030,7 +1027,10 @@ if (clang::Decl *decl = TryGetDecl(func_id)) return llvm::dyn_cast(decl); - clang::DeclContext *parent = GetParentDeclContext(PdbSymUid(func_id)); + lldb_private::CompilerDeclContext decl_ctx = + GetParentDeclContext(PdbSymUid(func_id)); + auto parent = + static_cast(decl_ctx.GetOpaqueDeclContext()); std::string context_name; if (clang::NamespaceDecl *ns = llvm::dyn_cast(parent)) { context_name = ns->getQualifiedNameAsString(); Index: source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp =================================================================== --- source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -1527,8 +1527,7 @@ CompilerDeclContext SymbolFileNativePDB::GetDeclContextContainingUID(lldb::user_id_t uid) { - clang::DeclContext *context = m_ast->GetParentDeclContext(PdbSymUid(uid)); - return m_ast->ToCompilerDeclContext(*context); + return m_ast->GetParentDeclContext(PdbSymUid(uid)); } Type *SymbolFileNativePDB::ResolveTypeUID(lldb::user_id_t type_uid) {