Author: Raphael Isemann Date: 2020-01-31T09:44:24+01:00 New Revision: 46ca55f2a2c88609657dff7f49ec54d5a71032d3
URL: https://github.com/llvm/llvm-project/commit/46ca55f2a2c88609657dff7f49ec54d5a71032d3 DIFF: https://github.com/llvm/llvm-project/commit/46ca55f2a2c88609657dff7f49ec54d5a71032d3.diff LOG: [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. Added: Modified: lldb/include/lldb/Symbol/TypeSystemClang.h lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp lldb/source/Symbol/TypeSystemClang.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Symbol/TypeSystemClang.h b/lldb/include/lldb/Symbol/TypeSystemClang.h index 9d4d5e56a4fa..fd8276dbf3dc 100644 --- a/lldb/include/lldb/Symbol/TypeSystemClang.h +++ b/lldb/include/lldb/Symbol/TypeSystemClang.h @@ -407,6 +407,16 @@ class TypeSystemClang : public TypeSystem { llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &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 c6eb45169da3..cc3b4ed0cd04 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 bdc5c315da60..2701f5b3a45e 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 468603c35cce..39d4b370bc3c 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 d06d542472d0..806f7b60bfff 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 16fda8cc223d..04a9dae68358 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 d1bb2fe87e6f..77e89eb5c897 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<CompilerDecl> 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<clang::NamedDecl>(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)); } } } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits