diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h b/lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h index 03c01707e6b31..fe6f477b6d326 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h @@ -9,7 +9,6 @@ #ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTUTILS_H #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTUTILS_H -#include "Plugins/TypeSystem/Clang/ImporterBackedASTSource.h" #include "clang/Basic/ASTSourceDescriptor.h" #include "clang/Sema/Lookup.h" #include "clang/Sema/MultiplexExternalSemaSource.h" @@ -30,7 +29,7 @@ namespace lldb_private { /// Wraps an ExternalASTSource into an ExternalSemaSource. /// /// Assumes shared ownership of the underlying source. -class ExternalASTSourceWrapper : public ImporterBackedASTSource { +class ExternalASTSourceWrapper : public clang::ExternalSemaSource { llvm::IntrusiveRefCntPtr m_Source; public: @@ -281,7 +280,7 @@ class ASTConsumerForwarder : public clang::SemaConsumer { /// provide more accurate replies to the requests, but might not be able to /// answer all requests. The debug information will be used as a fallback then /// to provide information that is not in the C++ module. -class SemaSourceWithPriorities : public ImporterBackedASTSource { +class SemaSourceWithPriorities : public clang::ExternalSemaSource { private: /// The sources ordered in decreasing priority. diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp index 6bedb3ef4939a..f7905bf59a13d 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include "Plugins/TypeSystem/Clang/ImporterBackedASTSource.h" #include "lldb/Core/Module.h" #include "lldb/Utility/LLDBAssert.h" #include "lldb/Utility/LLDBLog.h" diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h index 7b6ab7114f159..ee3acb409e692 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h @@ -13,7 +13,6 @@ #include "Plugins/ExpressionParser/Clang/ClangASTImporter.h" #include "Plugins/ExpressionParser/Clang/NameSearchContext.h" -#include "Plugins/TypeSystem/Clang/ImporterBackedASTSource.h" #include "lldb/Symbol/CompilerType.h" #include "lldb/Target/Target.h" #include "clang/AST/ExternalASTSource.h" @@ -31,7 +30,7 @@ namespace lldb_private { /// knows the name it is looking for, but nothing else. The ExternalSemaSource /// class provides Decls (VarDecl, FunDecl, TypeDecl) to Clang for these /// names, consulting the ClangExpressionDeclMap to do the actual lookups. -class ClangASTSource : public ImporterBackedASTSource, +class ClangASTSource : public clang::ExternalASTSource, public ClangASTImporter::MapCompleter { public: /// Constructor @@ -210,7 +209,7 @@ class ClangASTSource : public ImporterBackedASTSource, /// /// Clang AST contexts like to own their AST sources, so this is a state- /// free proxy object. - class ClangASTSourceProxy : public ImporterBackedASTSource { + class ClangASTSourceProxy : public clang::ExternalASTSource { public: ClangASTSourceProxy(ClangASTSource &original) : m_original(original) {} diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h index b5c9060d0605e..d0eabb509455c 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h @@ -9,7 +9,6 @@ #ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXTERNALASTSOURCECALLBACKS_H #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXTERNALASTSOURCECALLBACKS_H -#include "Plugins/TypeSystem/Clang/ImporterBackedASTSource.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" #include "clang/Basic/ASTSourceDescriptor.h" #include @@ -22,15 +21,13 @@ class Module; namespace lldb_private { -class ClangExternalASTSourceCallbacks : public ImporterBackedASTSource { +class ClangExternalASTSourceCallbacks : public clang::ExternalASTSource { /// LLVM RTTI support. static char ID; public: /// LLVM RTTI support. - bool isA(const void *ClassID) const override { - return ClassID == &ID || ImporterBackedASTSource::isA(ClassID); - } + bool isA(const void *ClassID) const override { return ClassID == &ID; } static bool classof(const clang::ExternalASTSource *s) { return s->isA(&ID); } ClangExternalASTSourceCallbacks(TypeSystemClang &ast) : m_ast(ast) {} diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtil.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtil.cpp index c8d7cb2a9f9d0..f1c40d497c178 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtil.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtil.cpp @@ -66,16 +66,6 @@ clang::TagDecl *ClangUtil::GetAsTagDecl(const CompilerType &type) { return qual_type->getAsTagDecl(); } -clang::Decl *ClangUtil::GetFirstDecl(clang::Decl *d) { - if (!d) - return nullptr; - if (auto *td = llvm::dyn_cast(d)) - return td->getFirstDecl(); - if (auto *od = llvm::dyn_cast(d)) - return od->getFirstDecl(); - return d; -} - clang::ObjCInterfaceDecl *ClangUtil::GetAsObjCDecl(const CompilerType &type) { clang::QualType qual_type = ClangUtil::GetCanonicalQualType(type); if (qual_type.isNull()) diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtil.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtil.h index 199c6639b68fb..f100485d21b34 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtil.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtil.h @@ -36,15 +36,6 @@ struct ClangUtil { static clang::TagDecl *GetAsTagDecl(const CompilerType &type); - /// If the given Decl is redeclarable, return the first declaration in its - /// redeclaration chain. Otherwise return d itself. - static clang::Decl *GetFirstDecl(clang::Decl *d); - - /// \see ClangUtil::GetFirstDecl - static const clang::Decl *GetFirstDecl(const clang::Decl *d) { - return GetFirstDecl(const_cast(d)); - } - static clang::ObjCInterfaceDecl *GetAsObjCDecl(const CompilerType &type); /// Returns a textual representation of the given Decl's AST. Does not diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp index b1c25aa4d17e6..a5e33e65fe2b4 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp @@ -11,7 +11,6 @@ #include "Plugins/ExpressionParser/Clang/ClangASTMetadata.h" #include "Plugins/ExpressionParser/Clang/ClangUtil.h" #include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h" -#include "Plugins/TypeSystem/Clang/ImporterBackedASTSource.h" #include "lldb/Core/Module.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" @@ -25,7 +24,7 @@ using namespace lldb_private; class lldb_private::AppleObjCExternalASTSource - : public ImporterBackedASTSource { + : public clang::ExternalASTSource { public: AppleObjCExternalASTSource(AppleObjCDeclVendor &decl_vendor) : m_decl_vendor(decl_vendor) {} diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index bcbcba505d2c3..ee903c1d53fc4 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -13,7 +13,6 @@ #include "DWARFDebugInfo.h" #include "DWARFDeclContext.h" #include "DWARFDefines.h" -#include "Plugins/TypeSystem/Clang/ImporterBackedASTSource.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" #include "SymbolFileDWARF.h" #include "SymbolFileDWARFDebugMap.h" @@ -2033,9 +2032,6 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc, m_ast.SetMetadata(class_template_decl, metadata); m_ast.SetMetadata(class_specialization_decl, metadata); RegisterDIE(die.GetDIE(), clang_type); - if (auto *source = llvm::dyn_cast_or_null( - m_ast.getASTContext().getExternalSource())) - source->MarkRedeclChainsAsOutOfDate(m_ast.getASTContext()); } if (!clang_type) { diff --git a/lldb/source/Plugins/TypeSystem/Clang/CMakeLists.txt b/lldb/source/Plugins/TypeSystem/Clang/CMakeLists.txt index f5cddc99acf28..90f173bc442d4 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/CMakeLists.txt +++ b/lldb/source/Plugins/TypeSystem/Clang/CMakeLists.txt @@ -1,5 +1,4 @@ add_lldb_library(lldbPluginTypeSystemClang PLUGIN - ImporterBackedASTSource.cpp TypeSystemClang.cpp LINK_COMPONENTS diff --git a/lldb/source/Plugins/TypeSystem/Clang/ImporterBackedASTSource.cpp b/lldb/source/Plugins/TypeSystem/Clang/ImporterBackedASTSource.cpp deleted file mode 100644 index f9445b4548cc7..0000000000000 --- a/lldb/source/Plugins/TypeSystem/Clang/ImporterBackedASTSource.cpp +++ /dev/null @@ -1,13 +0,0 @@ -//===-- ImporterBackedASTSource.cpp ---------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "Plugins/TypeSystem/Clang/ImporterBackedASTSource.h" - -using namespace lldb_private; - -char ImporterBackedASTSource::ID; diff --git a/lldb/source/Plugins/TypeSystem/Clang/ImporterBackedASTSource.h b/lldb/source/Plugins/TypeSystem/Clang/ImporterBackedASTSource.h deleted file mode 100644 index 00d1a578a0596..0000000000000 --- a/lldb/source/Plugins/TypeSystem/Clang/ImporterBackedASTSource.h +++ /dev/null @@ -1,46 +0,0 @@ -//===-- ImporterBackedASTSource.h -------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLDB_SOURCE_PLUGINS_TYPESYSTEM_CLANG_IMPORTERBACKEDASTSOURCE -#define LLDB_SOURCE_PLUGINS_TYPESYSTEM_CLANG_IMPORTERBACKEDASTSOURCE - -#include "clang/AST/ASTContext.h" -#include "clang/Sema/ExternalSemaSource.h" - -namespace lldb_private { - -/// The base class of all ExternalASTSources in LLDB that use the -/// ClangASTImporter to move declarations from other ASTs to the ASTContext they -/// are attached to. -class ImporterBackedASTSource : public clang::ExternalSemaSource { - /// LLVM RTTI support. - static char ID; - -public: - /// LLVM RTTI support. - bool isA(const void *ClassID) const override { - return ClassID == &ID || ExternalSemaSource::isA(ClassID); - } - static bool classof(const clang::ExternalASTSource *s) { return s->isA(&ID); } - - /// This marks all redeclaration chains in the ASTContext as out-of-date and - /// that this ExternalASTSource should be consulted to get the complete - /// redeclaration chain. - /// - /// \see ExternalASTSource::CompleteRedeclChain - void MarkRedeclChainsAsOutOfDate(clang::ASTContext &c) { - // This invalidates redeclaration chains but also other things such as - // identifiers. There isn't a more precise way at the moment that only - // affects redecl chains. - incrementGeneration(c); - } -}; - -} // namespace lldb_private - -#endif // LLDB_SOURCE_PLUGINS_TYPESYSTEM_CLANG_IMPORTERBACKEDASTSOURCE diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index a44be15aca3e6..f768df34221cc 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -1186,18 +1186,11 @@ CompilerType TypeSystemClang::GetTypeForDecl(clang::NamedDecl *decl) { } CompilerType TypeSystemClang::GetTypeForDecl(TagDecl *decl) { - // Create the type for the TagDecl. Pass the previous decl to make sure that - // all redeclarations share the same type. - return GetType( - getASTContext().getTypeDeclType(decl, decl->getPreviousDecl())); + return GetType(getASTContext().getTagDeclType(decl)); } CompilerType TypeSystemClang::GetTypeForDecl(const ObjCInterfaceDecl *decl) { - // FIXME: getObjCInterfaceType second parameter could be const. - // Create the type for the ObjCInterfaceDecl. Pass the previous decl to make - // sure that all redeclarations share the same type. - return GetType(getASTContext().getObjCInterfaceType( - decl, const_cast(decl->getPreviousDecl()))); + return GetType(getASTContext().getObjCInterfaceType(decl)); } CompilerType TypeSystemClang::GetTypeForDecl(clang::ValueDecl *value_decl) { @@ -1716,13 +1709,6 @@ TypeSystemClang::CreateClassTemplateSpecializationDecl( class_template_specialization_decl->setSpecializationKind( TSK_ExplicitSpecialization); - // Store the information that is needed to later redeclare this exact - // template specialization. - ClassTemplateRedeclInfo redecl_info; - redecl_info.m_template_args = template_param_infos; - m_class_template_redecl_infos[class_template_specialization_decl] = - redecl_info; - return class_template_specialization_decl; } @@ -2539,17 +2525,9 @@ void TypeSystemClang::SetMetadataAsUserID(const clang::Type *type, SetMetadata(type, meta_data); } -/// Returns the Decl in a redeclaration chain that is used to store the -/// the ClangASTMetadata in the metadata map. -static const clang::Decl *GetDeclForMetadataStorage(const clang::Decl *d) { - // Only the first Decl never changes and never requires any loading from - // the ExternalASTSource, so it can be a stable key for the map. - return ClangUtil::GetFirstDecl(d); -} - void TypeSystemClang::SetMetadata(const clang::Decl *object, ClangASTMetadata metadata) { - m_decl_metadata[GetDeclForMetadataStorage(object)] = metadata; + m_decl_metadata[object] = metadata; } void TypeSystemClang::SetMetadata(const clang::Type *object, @@ -2559,7 +2537,7 @@ void TypeSystemClang::SetMetadata(const clang::Type *object, std::optional TypeSystemClang::GetMetadata(const clang::Decl *object) { - auto It = m_decl_metadata.find(GetDeclForMetadataStorage(object)); + auto It = m_decl_metadata.find(object); if (It != m_decl_metadata.end()) return It->second; @@ -8463,11 +8441,7 @@ bool TypeSystemClang::StartTagDeclarationDefinition(const CompilerType &type) { if (tag_type) { clang::TagDecl *tag_decl = tag_type->getDecl(); if (tag_decl) { - // There are several declarations in the redeclaration chain that could - // define this type. The most logical declaration that we could turn - // into a definition is the most recent one. - clang::TagDecl *def = tag_decl->getMostRecentDecl(); - def->startDefinition(); + tag_decl->startDefinition(); return true; } } @@ -8477,11 +8451,7 @@ bool TypeSystemClang::StartTagDeclarationDefinition(const CompilerType &type) { if (object_type) { clang::ObjCInterfaceDecl *interface_decl = object_type->getInterface(); if (interface_decl) { - // There are several declarations in the redeclaration chain that could - // define this type. The most logical declaration that we could turn - // into a definition is the most recent one. - clang::ObjCInterfaceDecl *def = interface_decl->getMostRecentDecl(); - def->startDefinition(); + interface_decl->startDefinition(); return true; } } @@ -9154,87 +9124,6 @@ void TypeSystemClang::CompleteObjCInterfaceDecl( } } -/// Appends an existing declaration to the redeclaration chain. -/// \param ts The TypeSystemClang that contains the two declarations. -/// \param prev The most recent existing declaration. -/// \param redecl The new declaration which should be appended to the end of -/// redeclaration chain. -template -static void ConnectRedeclToPrev(TypeSystemClang &ts, T *prev, T *redecl) { - assert(&ts.getASTContext() == &prev->getASTContext() && "Not "); - redecl->setPreviousDecl(prev); - // Now that the redecl chain is done, create the type explicitly via - // the TypeSystemClang interface that will reuse the type of the previous - // decl. - ts.GetTypeForDecl(redecl); - // The previous decl and the redeclaration both declare the same type. - // FIXME: rdar://123500660, this is causing large number of test failures. - // assert(prev->getTypeForDecl() == redecl->getTypeForDecl()); -} - -/// Returns the ClangModuleID for the given declaration. -static OptionalClangModuleID GetModuleForDecl(clang::Decl *d) { - if (!d->isFromASTFile() || !d->getOwningModuleID()) - return OptionalClangModuleID(); - return OptionalClangModuleID(d->getOwningModuleID()); -} - -CompilerType TypeSystemClang::CreateRedeclaration(CompilerType ct) { - // All the cases below just check for a specific declaration kind, create - // a new declaration with matching data. We don't care about metadata which - // should only be tracked in the first redeclaration and should be identical - // for all redeclarations. - - if (clang::ObjCInterfaceDecl *interface = ClangUtil::GetAsObjCDecl(ct)) { - clang::NamedDecl *res = CreateObjCDecl( - interface->getName(), interface->getDeclContext()->getRedeclContext(), - GetModuleForDecl(interface), interface->isImplicit()); - clang::ObjCInterfaceDecl *redecl = llvm::cast(res); - ConnectRedeclToPrev(*this, interface, redecl); - return GetTypeForDecl(redecl); - } - - clang::TagDecl *tag_decl = ClangUtil::GetAsTagDecl(ct); - if (!tag_decl) - return {}; - - if (clang::EnumDecl *enum_decl = dyn_cast(tag_decl)) { - Declaration decl; - clang::EnumDecl *redecl = CreateEnumerationDecl( - enum_decl->getNameAsString().c_str(), - tag_decl->getDeclContext()->getRedeclContext(), - GetModuleForDecl(enum_decl), decl, GetType(enum_decl->getIntegerType()), - enum_decl->isScoped()); - ConnectRedeclToPrev(*this, enum_decl, redecl); - return GetTypeForDecl(redecl); - } - - if (auto *template_decl = - dyn_cast(tag_decl)) { - auto redecl_info = m_class_template_redecl_infos.find(template_decl); - // If we are asked to redeclare a template that we haven't declared, then - // there is nothing we can do. - assert(redecl_info != m_class_template_redecl_infos.end()); - TemplateParameterInfos template_infos = redecl_info->second.m_template_args; - auto *redecl = CreateClassTemplateSpecializationDecl( - tag_decl->getDeclContext()->getRedeclContext(), - GetModuleForDecl(template_decl), - template_decl->getSpecializedTemplate(), - llvm::to_underlying(tag_decl->getTagKind()), template_infos); - ConnectRedeclToPrev(*this, template_decl, redecl); - return GetType(clang::QualType(redecl->getTypeForDecl(), 0U)); - } - - assert(llvm::isa(tag_decl)); - clang::NamedDecl *redecl_record = CreateRecordDecl( - tag_decl->getDeclContext()->getRedeclContext(), - GetModuleForDecl(tag_decl), lldb::eAccessPublic, tag_decl->getName(), - llvm::to_underlying(tag_decl->getTagKind()), eLanguageTypeC_plus_plus); - clang::TagDecl *redecl = llvm::cast(redecl_record); - ConnectRedeclToPrev(*this, tag_decl, redecl); - return GetTypeForDecl(redecl); -} - DWARFASTParser *TypeSystemClang::GetDWARFParser() { if (!m_dwarf_ast_parser_up) m_dwarf_ast_parser_up = std::make_unique(*this); diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h index a82e811e7914a..0d4d95bc8c457 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h @@ -577,15 +577,6 @@ class TypeSystemClang : public TypeSystem { void CompleteObjCInterfaceDecl(clang::ObjCInterfaceDecl *); - /// Creates a redeclaration for the declaration specified by the given type. - /// The redeclaration will be at the end of the redeclaration chain. The - /// passed declaration has to be created via a TypeSystemClang interface. - /// - /// \param type The type which declaration should be redeclared. Has to be - /// an Objective-C interface type (or Objective-C type), RecordType or - /// EnumType. - CompilerType CreateRedeclaration(CompilerType ct); - bool LayoutRecordType( const clang::RecordDecl *record_decl, uint64_t &size, uint64_t &alignment, llvm::DenseMap &field_offsets, @@ -1319,18 +1310,6 @@ class TypeSystemClang : public TypeSystem { /// AccessSpecifier. CXXRecordDeclAccessMap m_cxx_record_decl_access; - /// The information we need to redeclare a class template but that we can't - /// gather from the forward declaration. - struct ClassTemplateRedeclInfo { - TemplateParameterInfos m_template_args; - }; - typedef llvm::DenseMap - ClassTemplateRedeclInfoMap; - // FIXME: This is in theory redundant. Instead we should change the way we - // create ClassTemplateSpecializationDecls in TypeSystemClang so that we can - // just pass the data from the forward declaration. - ClassTemplateRedeclInfoMap m_class_template_redecl_infos; - /// The sema associated that is currently used to build this ASTContext. /// May be null if we are already done parsing this ASTContext or the /// ASTContext wasn't created by parsing source code.