diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp index 4991be8e70ce..a78f6097978c 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp @@ -465,9 +465,9 @@ clang::Decl *PdbAstBuilder::GetOrCreateSymbolForId(PdbCompilandSymId id) { } } -clang::Decl *PdbAstBuilder::GetOrCreateDeclForUid(PdbSymUid uid) { +llvm::Optional PdbAstBuilder::GetOrCreateDeclForUid(PdbSymUid uid) { if (clang::Decl *result = TryGetDecl(uid)) - return result; + return ToCompilerDecl(*result); clang::Decl *result = nullptr; switch (uid.kind()) { @@ -480,13 +480,13 @@ clang::Decl *PdbAstBuilder::GetOrCreateDeclForUid(PdbSymUid uid) { result = tag; break; } - return nullptr; + return llvm::None; } default: - return nullptr; + return llvm::None; } m_uid_to_decl[toOpaqueUid(uid)] = result; - return result; + return ToCompilerDecl(*result); } clang::DeclContext *PdbAstBuilder::GetOrCreateDeclContextForUid(PdbSymUid uid) { @@ -494,8 +494,10 @@ clang::DeclContext *PdbAstBuilder::GetOrCreateDeclContextForUid(PdbSymUid uid) { if (uid.asCompilandSym().offset == 0) return FromCompilerDeclContext(GetTranslationUnitDecl()); } - - clang::Decl *decl = GetOrCreateDeclForUid(uid); + auto option = GetOrCreateDeclForUid(uid); + if (!option) + return nullptr; + clang::Decl *decl = FromCompilerDecl(option.getValue()); if (!decl) return nullptr; diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h index 67d024741e0d..593bf05ebbc2 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h +++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h @@ -55,7 +55,8 @@ public: lldb_private::CompilerDeclContext GetTranslationUnitDecl(); - clang::Decl *GetOrCreateDeclForUid(PdbSymUid uid); + llvm::Optional + GetOrCreateDeclForUid(PdbSymUid uid); clang::DeclContext *GetOrCreateDeclContextForUid(PdbSymUid uid); clang::DeclContext *GetParentDeclContext(PdbSymUid uid); @@ -76,7 +77,7 @@ public: CompilerDecl ToCompilerDecl(clang::Decl &decl); CompilerType ToCompilerType(clang::QualType qt); CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context); - clang::Decl * FromCompilerDecl(CompilerDecl decl); + clang::Decl *FromCompilerDecl(CompilerDecl decl); clang::DeclContext *FromCompilerDeclContext(CompilerDeclContext context); ClangASTContext &clang() { return m_clang; } diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp index e27d4699ae2f..c9fb1dc86140 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -1506,9 +1506,10 @@ size_t SymbolFileNativePDB::ParseVariablesForContext(const SymbolContext &sc) { } CompilerDecl SymbolFileNativePDB::GetDeclForUID(lldb::user_id_t uid) { - clang::Decl *decl = m_ast->GetOrCreateDeclForUid(PdbSymUid(uid)); - - return m_ast->ToCompilerDecl(*decl); + if (auto decl = m_ast->GetOrCreateDeclForUid(uid)) + return decl.getValue(); + else + return CompilerDecl(); } CompilerDeclContext