From: Raphael Isemann Date: Fri, 31 Jan 2020 08:22:25 +0000 (+0100) Subject: [lldb][NFC] Add safe Decl->CompilerDecl conversion function TypeSystemClang X-Git-Tag: llvmorg-12-init~16210 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=46ca55f2a2c88609657dff7f49ec54d5a71032d3;p=platform%2Fupstream%2Fllvm.git [lldb][NFC] Add safe Decl->CompilerDecl conversion function TypeSystemClang This adds a conversion function from clang::Decl to CompilerDecl. It checks that the TypeSystemClang in the CompilerDecl actually fits to the clang::Decl AST during creation, thus preventing the creation of CompilerDecl instances with inconsistent state. --- diff --git a/lldb/include/lldb/Symbol/TypeSystemClang.h b/lldb/include/lldb/Symbol/TypeSystemClang.h index 9d4d5e5..fd8276d 100644 --- a/lldb/include/lldb/Symbol/TypeSystemClang.h +++ b/lldb/include/lldb/Symbol/TypeSystemClang.h @@ -407,6 +407,16 @@ public: llvm::DenseMap &vbase_offsets); + /// Creates a CompilerDecl from the given Decl with the current + /// TypeSystemClang instance as its typesystem. + /// The Decl has to come from the ASTContext of this + /// TypeSystemClang. + CompilerDecl GetCompilerDecl(clang::Decl *decl) { + assert(&decl->getASTContext() == &getASTContext() && + "CreateCompilerDecl for Decl from wrong ASTContext?"); + return CompilerDecl(this, decl); + } + // CompilerDecl override functions ConstString DeclGetName(void *opaque_decl) override; diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp index c6eb451..cc3b4ed 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp @@ -384,7 +384,7 @@ ClangModulesDeclVendorImpl::FindDecls(ConstString name, bool append, if (num_matches >= max_matches) return num_matches; - decls.push_back(CompilerDecl(m_ast_context.get(), named_decl)); + decls.push_back(m_ast_context->GetCompilerDecl(named_decl)); ++num_matches; } diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp index bdc5c31..2701f5b 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp @@ -583,7 +583,7 @@ uint32_t AppleObjCDeclVendor::FindDecls(ConstString name, bool append, current_id, result_iface_type.getAsString(), isa_value); } - decls.push_back(CompilerDecl(&m_ast_ctx, result_iface_decl)); + decls.push_back(m_ast_ctx.GetCompilerDecl(result_iface_decl)); ret++; break; } else { @@ -626,7 +626,7 @@ uint32_t AppleObjCDeclVendor::FindDecls(ConstString name, bool append, new_iface_type.getAsString(), (uint64_t)isa); } - decls.push_back(CompilerDecl(&m_ast_ctx, iface_decl)); + decls.push_back(m_ast_ctx.GetCompilerDecl(iface_decl)); ret++; break; } while (false); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index 468603c..39d4b37 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -2182,7 +2182,7 @@ void DWARFASTParserClang::EnsureAllDIEsInDeclContextHaveBeenParsed( CompilerDecl DWARFASTParserClang::GetDeclForUIDFromDWARF(const DWARFDIE &die) { clang::Decl *clang_decl = GetClangDeclForDIE(die); if (clang_decl != nullptr) - return CompilerDecl(&m_ast, clang_decl); + return m_ast.GetCompilerDecl(clang_decl); return CompilerDecl(); } diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp index d06d542..806f7b6 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp @@ -1334,7 +1334,7 @@ void PdbAstBuilder::ParseDeclsForContext(clang::DeclContext &context) { } CompilerDecl PdbAstBuilder::ToCompilerDecl(clang::Decl &decl) { - return {&m_clang, &decl}; + return m_clang.GetCompilerDecl(&decl); } CompilerType PdbAstBuilder::ToCompilerType(clang::QualType qt) { diff --git a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp index 16fda8c..04a9dae 100644 --- a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp +++ b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp @@ -636,7 +636,7 @@ lldb_private::CompilerDecl SymbolFilePDB::GetDeclForUID(lldb::user_id_t uid) { if (!decl) return CompilerDecl(); - return CompilerDecl(clang_ast_ctx, decl); + return clang_ast_ctx->GetCompilerDecl(decl); } lldb_private::CompilerDeclContext diff --git a/lldb/source/Symbol/TypeSystemClang.cpp b/lldb/source/Symbol/TypeSystemClang.cpp index d1bb2fe..77e89eb 100644 --- a/lldb/source/Symbol/TypeSystemClang.cpp +++ b/lldb/source/Symbol/TypeSystemClang.cpp @@ -4129,7 +4129,7 @@ TypeSystemClang::GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, else kind = lldb::eMemberFunctionKindInstanceMethod; clang_type = GetType(cxx_method_decl->getType()); - clang_decl = CompilerDecl(this, cxx_method_decl); + clang_decl = GetCompilerDecl(cxx_method_decl); } } } @@ -4155,7 +4155,7 @@ TypeSystemClang::GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, clang::ObjCMethodDecl *objc_method_decl = method_iter->getCanonicalDecl(); if (objc_method_decl) { - clang_decl = CompilerDecl(this, objc_method_decl); + clang_decl = GetCompilerDecl(objc_method_decl); name = objc_method_decl->getSelector().getAsString(); if (objc_method_decl->isClassMethod()) kind = lldb::eMemberFunctionKindStaticMethod; @@ -4185,7 +4185,7 @@ TypeSystemClang::GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, clang::ObjCMethodDecl *objc_method_decl = method_iter->getCanonicalDecl(); if (objc_method_decl) { - clang_decl = CompilerDecl(this, objc_method_decl); + clang_decl = GetCompilerDecl(objc_method_decl); name = objc_method_decl->getSelector().getAsString(); if (objc_method_decl->isClassMethod()) kind = lldb::eMemberFunctionKindStaticMethod; @@ -8980,14 +8980,14 @@ std::vector TypeSystemClang::DeclContextFindDeclByName( IdentifierInfo *ii = nd->getIdentifier(); if (ii != nullptr && ii->getName().equals(name.AsCString(nullptr))) - found_decls.push_back(CompilerDecl(this, nd)); + found_decls.push_back(GetCompilerDecl(nd)); } } } else if (clang::NamedDecl *nd = llvm::dyn_cast(child)) { IdentifierInfo *ii = nd->getIdentifier(); if (ii != nullptr && ii->getName().equals(name.AsCString(nullptr))) - found_decls.push_back(CompilerDecl(this, nd)); + found_decls.push_back(GetCompilerDecl(nd)); } } }