diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 9 | ||||
-rw-r--r-- | clang/lib/AST/Decl.cpp | 76 | ||||
-rw-r--r-- | clang/lib/AST/DeclCXX.cpp | 85 | ||||
-rw-r--r-- | clang/lib/AST/DeclObjC.cpp | 34 | ||||
-rw-r--r-- | clang/lib/AST/DeclTemplate.cpp | 59 | ||||
-rw-r--r-- | clang/lib/AST/ExternalASTSource.cpp | 20 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGBlocks.cpp | 21 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGDeclCXX.cpp | 3 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGObjC.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Frontend/FrontendAction.cpp | 15 | ||||
-rw-r--r-- | clang/lib/Sema/MultiplexExternalSemaSource.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 42 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReaderDecl.cpp | 52 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 5 |
14 files changed, 263 insertions, 171 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 2f406166690..fe735dc92fc 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -8239,3 +8239,12 @@ ASTContext::ObjCMethodsAreEqual(const ObjCMethodDecl *MethodDecl, return (MethodDecl->isVariadic() == MethodImpl->isVariadic()); } + +// Explicitly instantiate this in case a Redeclarable<T> is used from a TU that +// doesn't include ASTContext.h +template +clang::LazyGenerationalUpdatePtr< + const Decl *, Decl *, &ExternalASTSource::CompleteRedeclChain>::ValueType +clang::LazyGenerationalUpdatePtr< + const Decl *, Decl *, &ExternalASTSource::CompleteRedeclChain>::makeValue( + const clang::ASTContext &Ctx, Decl *Value); diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 101b1646248..fc15bdee010 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -1616,10 +1616,12 @@ const char *VarDecl::getStorageClassSpecifierString(StorageClass SC) { llvm_unreachable("Invalid storage class"); } -VarDecl::VarDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, - SourceLocation IdLoc, IdentifierInfo *Id, QualType T, - TypeSourceInfo *TInfo, StorageClass SC) - : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), Init() { +VarDecl::VarDecl(Kind DK, ASTContext &C, DeclContext *DC, + SourceLocation StartLoc, SourceLocation IdLoc, + IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, + StorageClass SC) + : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), + redeclarable_base(C), Init() { static_assert(sizeof(VarDeclBitfields) <= sizeof(unsigned), "VarDeclBitfields too large!"); static_assert(sizeof(ParmVarDeclBitfields) <= sizeof(unsigned), @@ -1633,12 +1635,13 @@ VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation StartL, SourceLocation IdL, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S) { - return new (C, DC) VarDecl(Var, DC, StartL, IdL, Id, T, TInfo, S); + return new (C, DC) VarDecl(Var, C, DC, StartL, IdL, Id, T, TInfo, S); } VarDecl *VarDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) VarDecl(Var, nullptr, SourceLocation(), SourceLocation(), - nullptr, QualType(), nullptr, SC_None); + return new (C, ID) + VarDecl(Var, C, nullptr, SourceLocation(), SourceLocation(), nullptr, + QualType(), nullptr, SC_None); } void VarDecl::setStorageClass(StorageClass SC) { @@ -2114,7 +2117,7 @@ ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg) { - return new (C, DC) ParmVarDecl(ParmVar, DC, StartLoc, IdLoc, Id, T, TInfo, + return new (C, DC) ParmVarDecl(ParmVar, C, DC, StartLoc, IdLoc, Id, T, TInfo, S, DefArg); } @@ -2127,9 +2130,9 @@ QualType ParmVarDecl::getOriginalType() const { } ParmVarDecl *ParmVarDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) ParmVarDecl(ParmVar, nullptr, SourceLocation(), - SourceLocation(), nullptr, QualType(), - nullptr, SC_None, nullptr); + return new (C, ID) + ParmVarDecl(ParmVar, C, nullptr, SourceLocation(), SourceLocation(), + nullptr, QualType(), nullptr, SC_None, nullptr); } SourceRange ParmVarDecl::getSourceRange() const { @@ -3234,10 +3237,10 @@ void TagDecl::startDefinition() { IsBeingDefined = true; if (CXXRecordDecl *D = dyn_cast<CXXRecordDecl>(this)) { - struct CXXRecordDecl::DefinitionData *Data = + struct CXXRecordDecl::DefinitionData *Data = new (getASTContext()) struct CXXRecordDecl::DefinitionData(D); for (auto I : redecls()) - cast<CXXRecordDecl>(I)->DefinitionData = Data; + cast<CXXRecordDecl>(I)->DefinitionData.setNotUpdated(Data); } } @@ -3319,7 +3322,7 @@ EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, EnumDecl *PrevDecl, bool IsScoped, bool IsScopedUsingClassTag, bool IsFixed) { - EnumDecl *Enum = new (C, DC) EnumDecl(DC, StartLoc, IdLoc, Id, PrevDecl, + EnumDecl *Enum = new (C, DC) EnumDecl(C, DC, StartLoc, IdLoc, Id, PrevDecl, IsScoped, IsScopedUsingClassTag, IsFixed); Enum->MayHaveOutOfDateDef = C.getLangOpts().Modules; @@ -3328,9 +3331,9 @@ EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, } EnumDecl *EnumDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - EnumDecl *Enum = new (C, ID) EnumDecl(nullptr, SourceLocation(), - SourceLocation(), nullptr, nullptr, - false, false, false); + EnumDecl *Enum = + new (C, ID) EnumDecl(C, nullptr, SourceLocation(), SourceLocation(), + nullptr, nullptr, false, false, false); Enum->MayHaveOutOfDateDef = C.getLangOpts().Modules; return Enum; } @@ -3389,10 +3392,11 @@ void EnumDecl::setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED, // RecordDecl Implementation //===----------------------------------------------------------------------===// -RecordDecl::RecordDecl(Kind DK, TagKind TK, DeclContext *DC, - SourceLocation StartLoc, SourceLocation IdLoc, - IdentifierInfo *Id, RecordDecl *PrevDecl) - : TagDecl(DK, TK, DC, IdLoc, Id, PrevDecl, StartLoc) { +RecordDecl::RecordDecl(Kind DK, TagKind TK, const ASTContext &C, + DeclContext *DC, SourceLocation StartLoc, + SourceLocation IdLoc, IdentifierInfo *Id, + RecordDecl *PrevDecl) + : TagDecl(DK, TK, C, DC, IdLoc, Id, PrevDecl, StartLoc) { HasFlexibleArrayMember = false; AnonymousStructOrUnion = false; HasObjectMember = false; @@ -3404,8 +3408,8 @@ RecordDecl::RecordDecl(Kind DK, TagKind TK, DeclContext *DC, RecordDecl *RecordDecl::Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl* PrevDecl) { - RecordDecl* R = new (C, DC) RecordDecl(Record, TK, DC, StartLoc, IdLoc, Id, - PrevDecl); + RecordDecl *R = new (C, DC) RecordDecl(Record, TK, C, DC, + StartLoc, IdLoc, Id, PrevDecl); R->MayHaveOutOfDateDef = C.getLangOpts().Modules; C.getTypeDeclType(R, PrevDecl); @@ -3413,9 +3417,9 @@ RecordDecl *RecordDecl::Create(const ASTContext &C, TagKind TK, DeclContext *DC, } RecordDecl *RecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { - RecordDecl *R = new (C, ID) RecordDecl(Record, TTK_Struct, nullptr, - SourceLocation(), SourceLocation(), - nullptr, nullptr); + RecordDecl *R = + new (C, ID) RecordDecl(Record, TTK_Struct, C, nullptr, SourceLocation(), + SourceLocation(), nullptr, nullptr); R->MayHaveOutOfDateDef = C.getLangOpts().Modules; return R; } @@ -3577,12 +3581,12 @@ ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType Type) { - return new (C, DC) ImplicitParamDecl(DC, IdLoc, Id, Type); + return new (C, DC) ImplicitParamDecl(C, DC, IdLoc, Id, Type); } ImplicitParamDecl *ImplicitParamDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) ImplicitParamDecl(nullptr, SourceLocation(), nullptr, + return new (C, ID) ImplicitParamDecl(C, nullptr, SourceLocation(), nullptr, QualType()); } @@ -3595,14 +3599,14 @@ FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC, bool hasWrittenPrototype, bool isConstexprSpecified) { FunctionDecl *New = - new (C, DC) FunctionDecl(Function, DC, StartLoc, NameInfo, T, TInfo, SC, - isInlineSpecified, isConstexprSpecified); + new (C, DC) FunctionDecl(Function, C, DC, StartLoc, NameInfo, T, TInfo, + SC, isInlineSpecified, isConstexprSpecified); New->HasWrittenPrototype = hasWrittenPrototype; return New; } FunctionDecl *FunctionDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) FunctionDecl(Function, nullptr, SourceLocation(), + return new (C, ID) FunctionDecl(Function, C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr, SC_None, false, false); } @@ -3668,13 +3672,13 @@ void TypeDecl::anchor() { } TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo) { - return new (C, DC) TypedefDecl(DC, StartLoc, IdLoc, Id, TInfo); + return new (C, DC) TypedefDecl(C, DC, StartLoc, IdLoc, Id, TInfo); } void TypedefNameDecl::anchor() { } TypedefDecl *TypedefDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) TypedefDecl(nullptr, SourceLocation(), SourceLocation(), + return new (C, ID) TypedefDecl(C, nullptr, SourceLocation(), SourceLocation(), nullptr, nullptr); } @@ -3682,12 +3686,12 @@ TypeAliasDecl *TypeAliasDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo) { - return new (C, DC) TypeAliasDecl(DC, StartLoc, IdLoc, Id, TInfo); + return new (C, DC) TypeAliasDecl(C, DC, StartLoc, IdLoc, Id, TInfo); } TypeAliasDecl *TypeAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) TypeAliasDecl(nullptr, SourceLocation(), SourceLocation(), - nullptr, nullptr); + return new (C, ID) TypeAliasDecl(C, nullptr, SourceLocation(), + SourceLocation(), nullptr, nullptr); } SourceRange TypedefDecl::getSourceRange() const { diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index 4cd35fc462b..1c416282759 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -82,19 +82,21 @@ CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getVBasesSlowCase() const { return VBases.get(Definition->getASTContext().getExternalSource()); } -CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, - SourceLocation StartLoc, SourceLocation IdLoc, - IdentifierInfo *Id, CXXRecordDecl *PrevDecl) - : RecordDecl(K, TK, DC, StartLoc, IdLoc, Id, PrevDecl), - DefinitionData(PrevDecl ? PrevDecl->DefinitionData : nullptr), - TemplateOrInstantiation() { } +CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, + DeclContext *DC, SourceLocation StartLoc, + SourceLocation IdLoc, IdentifierInfo *Id, + CXXRecordDecl *PrevDecl) + : RecordDecl(K, TK, C, DC, StartLoc, IdLoc, Id, PrevDecl), + DefinitionData(PrevDecl ? PrevDecl->DefinitionData + : DefinitionDataPtr(C)), + TemplateOrInstantiation() {} CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, CXXRecordDecl* PrevDecl, bool DelayTypeCreation) { - CXXRecordDecl *R = new (C, DC) CXXRecordDecl(CXXRecord, TK, DC, StartLoc, + CXXRecordDecl *R = new (C, DC) CXXRecordDecl(CXXRecord, TK, C, DC, StartLoc, IdLoc, Id, PrevDecl); R->MayHaveOutOfDateDef = C.getLangOpts().Modules; @@ -104,18 +106,18 @@ CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, TagKind TK, return R; } -CXXRecordDecl *CXXRecordDecl::CreateLambda(const ASTContext &C, DeclContext *DC, - TypeSourceInfo *Info, SourceLocation Loc, - bool Dependent, bool IsGeneric, - LambdaCaptureDefault CaptureDefault) { +CXXRecordDecl * +CXXRecordDecl::CreateLambda(const ASTContext &C, DeclContext *DC, + TypeSourceInfo *Info, SourceLocation Loc, + bool Dependent, bool IsGeneric, + LambdaCaptureDefault CaptureDefault) { CXXRecordDecl *R = - new (C, DC) CXXRecordDecl(CXXRecord, TTK_Class, DC, Loc, Loc, nullptr, - nullptr); + new (C, DC) CXXRecordDecl(CXXRecord, TTK_Class, C, DC, Loc, Loc, + nullptr, nullptr); R->IsBeingDefined = true; - R->DefinitionData = new (C) struct LambdaDefinitionData(R, Info, - Dependent, - IsGeneric, - CaptureDefault); + R->DefinitionData.setNotUpdated( + new (C) struct LambdaDefinitionData(R, Info, Dependent, IsGeneric, + CaptureDefault)); R->MayHaveOutOfDateDef = false; R->setImplicit(true); C.getTypeDeclType(R, /*PrevDecl=*/nullptr); @@ -125,7 +127,7 @@ CXXRecordDecl *CXXRecordDecl::CreateLambda(const ASTContext &C, DeclContext *DC, CXXRecordDecl * CXXRecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { CXXRecordDecl *R = new (C, ID) CXXRecordDecl( - CXXRecord, TTK_Struct, nullptr, SourceLocation(), SourceLocation(), + CXXRecord, TTK_Struct, C, nullptr, SourceLocation(), SourceLocation(), nullptr, nullptr); R->MayHaveOutOfDateDef = false; return R; @@ -1410,12 +1412,13 @@ CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool isInline, bool isConstexpr, SourceLocation EndLocation) { - return new (C, RD) CXXMethodDecl(CXXMethod, RD, StartLoc, NameInfo, T, TInfo, - SC, isInline, isConstexpr, EndLocation); + return new (C, RD) CXXMethodDecl(CXXMethod, C, RD, StartLoc, NameInfo, + T, TInfo, SC, isInline, isConstexpr, + EndLocation); } CXXMethodDecl *CXXMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) CXXMethodDecl(CXXMethod, nullptr, SourceLocation(), + return new (C, ID) CXXMethodDecl(CXXMethod, C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr, SC_None, false, false, SourceLocation()); } @@ -1680,7 +1683,7 @@ void CXXConstructorDecl::anchor() { } CXXConstructorDecl * CXXConstructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) CXXConstructorDecl(nullptr, SourceLocation(), + return new (C, ID) CXXConstructorDecl(C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr, false, false, false, false); } @@ -1695,7 +1698,7 @@ CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, assert(NameInfo.getName().getNameKind() == DeclarationName::CXXConstructorName && "Name must refer to a constructor"); - return new (C, RD) CXXConstructorDecl(RD, StartLoc, NameInfo, T, TInfo, + return new (C, RD) CXXConstructorDecl(C, RD, StartLoc, NameInfo, T, TInfo, isExplicit, isInline, isImplicitlyDeclared, isConstexpr); } @@ -1830,9 +1833,9 @@ void CXXDestructorDecl::anchor() { } CXXDestructorDecl * CXXDestructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) CXXDestructorDecl( - nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr, - false, false); + return new (C, ID) + CXXDestructorDecl(C, nullptr, SourceLocation(), DeclarationNameInfo(), + QualType(), nullptr, false, false); } CXXDestructorDecl * @@ -1844,7 +1847,7 @@ CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, assert(NameInfo.getName().getNameKind() == DeclarationName::CXXDestructorName && "Name must refer to a destructor"); - return new (C, RD) CXXDestructorDecl(RD, StartLoc, NameInfo, T, TInfo, + return new (C, RD) CXXDestructorDecl(C, RD, StartLoc, NameInfo, T, TInfo, isInline, isImplicitlyDeclared); } @@ -1852,7 +1855,7 @@ void CXXConversionDecl::anchor() { } CXXConversionDecl * CXXConversionDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) CXXConversionDecl(nullptr, SourceLocation(), + return new (C, ID) CXXConversionDecl(C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr, false, false, false, SourceLocation()); @@ -1868,7 +1871,7 @@ CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD, assert(NameInfo.getName().getNameKind() == DeclarationName::CXXConversionFunctionName && "Name must refer to a conversion function"); - return new (C, RD) CXXConversionDecl(RD, StartLoc, NameInfo, T, TInfo, + return new (C, RD) CXXConversionDecl(C, RD, StartLoc, NameInfo, T, TInfo, isInline, isExplicit, isConstexpr, EndLocation); } @@ -1925,15 +1928,14 @@ NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() { return cast_or_null<NamespaceDecl>(NominatedNamespace); } -NamespaceDecl::NamespaceDecl(DeclContext *DC, bool Inline, - SourceLocation StartLoc, - SourceLocation IdLoc, IdentifierInfo *Id, - NamespaceDecl *PrevDecl) - : NamedDecl(Namespace, DC, IdLoc, Id), DeclContext(Namespace), - LocStart(StartLoc), RBraceLoc(), - AnonOrFirstNamespaceAndInline(nullptr, Inline) { +NamespaceDecl::NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline, + SourceLocation StartLoc, SourceLocation IdLoc, + IdentifierInfo *Id, NamespaceDecl *PrevDecl) + : NamedDecl(Namespace, DC, IdLoc, Id), DeclContext(Namespace), + redeclarable_base(C), LocStart(StartLoc), RBraceLoc(), + AnonOrFirstNamespaceAndInline(nullptr, Inline) { setPreviousDecl(PrevDecl); - + if (PrevDecl) AnonOrFirstNamespaceAndInline.setPointer(PrevDecl->getOriginalNamespace()); } @@ -1942,11 +1944,12 @@ NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl) { - return new (C, DC) NamespaceDecl(DC, Inline, StartLoc, IdLoc, Id, PrevDecl); + return new (C, DC) NamespaceDecl(C, DC, Inline, StartLoc, IdLoc, Id, + PrevDecl); } NamespaceDecl *NamespaceDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) NamespaceDecl(nullptr, false, SourceLocation(), + return new (C, ID) NamespaceDecl(C, nullptr, false, SourceLocation(), SourceLocation(), nullptr, nullptr); } @@ -1987,8 +1990,8 @@ void UsingShadowDecl::anchor() { } UsingShadowDecl * UsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) UsingShadowDecl(nullptr, SourceLocation(), nullptr, - nullptr); + return new (C, ID) UsingShadowDecl(C, nullptr, SourceLocation(), + nullptr, nullptr); } UsingDecl *UsingShadowDecl::getUsingDecl() const { diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index 42462a1b140..186a7417b65 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/lib/AST/DeclObjC.cpp @@ -1134,15 +1134,15 @@ ObjCInterfaceDecl *ObjCInterfaceDecl::Create(const ASTContext &C, SourceLocation ClassLoc, bool isInternal){ ObjCInterfaceDecl *Result = new (C, DC) - ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, PrevDecl, isInternal); + ObjCInterfaceDecl(C, DC, atLoc, Id, ClassLoc, PrevDecl, isInternal); Result->Data.setInt(!C.getLangOpts().Modules); C.getObjCInterfaceType(Result, PrevDecl); return Result; } -ObjCInterfaceDecl *ObjCInterfaceDecl::CreateDeserialized(ASTContext &C, +ObjCInterfaceDecl *ObjCInterfaceDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { - ObjCInterfaceDecl *Result = new (C, ID) ObjCInterfaceDecl(nullptr, + ObjCInterfaceDecl *Result = new (C, ID) ObjCInterfaceDecl(C, nullptr, SourceLocation(), nullptr, SourceLocation(), @@ -1151,20 +1151,20 @@ ObjCInterfaceDecl *ObjCInterfaceDecl::CreateDeserialized(ASTContext &C, return Result; } -ObjCInterfaceDecl:: -ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, - SourceLocation CLoc, ObjCInterfaceDecl *PrevDecl, - bool isInternal) - : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, atLoc), - TypeForDecl(nullptr), Data() -{ +ObjCInterfaceDecl::ObjCInterfaceDecl(const ASTContext &C, DeclContext *DC, + SourceLocation AtLoc, IdentifierInfo *Id, + SourceLocation CLoc, + ObjCInterfaceDecl *PrevDecl, + bool IsInternal) + : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, AtLoc), + redeclarable_base(C), TypeForDecl(nullptr), Data() { setPreviousDecl(PrevDecl); // Copy the 'data' pointer over. if (PrevDecl) Data = PrevDecl->Data; - setImplicit(isInternal); + setImplicit(IsInternal); } void ObjCInterfaceDecl::LoadExternalDefinition() const { @@ -1487,12 +1487,12 @@ ObjCAtDefsFieldDecl *ObjCAtDefsFieldDecl::CreateDeserialized(ASTContext &C, void ObjCProtocolDecl::anchor() { } -ObjCProtocolDecl::ObjCProtocolDecl(DeclContext *DC, IdentifierInfo *Id, - SourceLocation nameLoc, +ObjCProtocolDecl::ObjCProtocolDecl(ASTContext &C, DeclContext *DC, + IdentifierInfo *Id, SourceLocation nameLoc, SourceLocation atStartLoc, ObjCProtocolDecl *PrevDecl) - : ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc), Data() -{ + : ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc), + redeclarable_base(C), Data() { setPreviousDecl(PrevDecl); if (PrevDecl) Data = PrevDecl->Data; @@ -1504,7 +1504,7 @@ ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation atStartLoc, ObjCProtocolDecl *PrevDecl) { ObjCProtocolDecl *Result = - new (C, DC) ObjCProtocolDecl(DC, Id, nameLoc, atStartLoc, PrevDecl); + new (C, DC) ObjCProtocolDecl(C, DC, Id, nameLoc, atStartLoc, PrevDecl); Result->Data.setInt(!C.getLangOpts().Modules); return Result; } @@ -1512,7 +1512,7 @@ ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC, ObjCProtocolDecl *ObjCProtocolDecl::CreateDeserialized(ASTContext &C, unsigned ID) { ObjCProtocolDecl *Result = - new (C, ID) ObjCProtocolDecl(nullptr, nullptr, SourceLocation(), + new (C, ID) ObjCProtocolDecl(C, nullptr, nullptr, SourceLocation(), SourceLocation(), nullptr); Result->Data.setInt(!C.getLangOpts().Modules); return Result; diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 4a934747e94..a69146b5b88 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -229,12 +229,12 @@ FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C, TemplateParameterList *Params, NamedDecl *Decl) { AdoptTemplateParameterList(Params, cast<DeclContext>(Decl)); - return new (C, DC) FunctionTemplateDecl(DC, L, Name, Params, Decl); + return new (C, DC) FunctionTemplateDecl(C, DC, L, Name, Params, Decl); } FunctionTemplateDecl *FunctionTemplateDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) FunctionTemplateDecl(nullptr, SourceLocation(), + return new (C, ID) FunctionTemplateDecl(C, nullptr, SourceLocation(), DeclarationName(), nullptr, nullptr); } @@ -307,15 +307,16 @@ ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C, NamedDecl *Decl, ClassTemplateDecl *PrevDecl) { AdoptTemplateParameterList(Params, cast<DeclContext>(Decl)); - ClassTemplateDecl *New = - new (C, DC) ClassTemplateDecl(DC, L, Name, Params, Decl); + ClassTemplateDecl *New = new (C, DC) ClassTemplateDecl(C, DC, L, Name, + Params, Decl); New->setPreviousDecl(PrevDecl); return New; } -ClassTemplateDecl *ClassTemplateDecl::CreateDeserialized(ASTContext &C, +ClassTemplateDecl *ClassTemplateDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) ClassTemplateDecl(EmptyShell()); + return new (C, ID) ClassTemplateDecl(C, nullptr, SourceLocation(), + DeclarationName(), nullptr, nullptr); } void ClassTemplateDecl::LoadLazySpecializations() const { @@ -695,7 +696,7 @@ ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, const TemplateArgument *Args, unsigned NumArgs, ClassTemplateSpecializationDecl *PrevDecl) - : CXXRecordDecl(DK, TK, DC, StartLoc, IdLoc, + : CXXRecordDecl(DK, TK, Context, DC, StartLoc, IdLoc, SpecializedTemplate->getIdentifier(), PrevDecl), SpecializedTemplate(SpecializedTemplate), @@ -704,12 +705,11 @@ ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, SpecializationKind(TSK_Undeclared) { } -ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(Kind DK) - : CXXRecordDecl(DK, TTK_Struct, nullptr, SourceLocation(), SourceLocation(), - nullptr, nullptr), - ExplicitInfo(nullptr), - SpecializationKind(TSK_Undeclared) { -} +ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(ASTContext &C, + Kind DK) + : CXXRecordDecl(DK, TTK_Struct, C, nullptr, SourceLocation(), + SourceLocation(), nullptr, nullptr), + ExplicitInfo(nullptr), SpecializationKind(TSK_Undeclared) {} ClassTemplateSpecializationDecl * ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK, @@ -734,7 +734,7 @@ ClassTemplateSpecializationDecl * ClassTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, unsigned ID) { ClassTemplateSpecializationDecl *Result = - new (C, ID) ClassTemplateSpecializationDecl(ClassTemplateSpecialization); + new (C, ID) ClassTemplateSpecializationDecl(C, ClassTemplateSpecialization); Result->MayHaveOutOfDateDef = false; return Result; } @@ -851,7 +851,7 @@ ClassTemplatePartialSpecializationDecl * ClassTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C, unsigned ID) { ClassTemplatePartialSpecializationDecl *Result = - new (C, ID) ClassTemplatePartialSpecializationDecl(); + new (C, ID) ClassTemplatePartialSpecializationDecl(C); Result->MayHaveOutOfDateDef = false; return Result; } @@ -889,12 +889,12 @@ TypeAliasTemplateDecl *TypeAliasTemplateDecl::Create(ASTContext &C, TemplateParameterList *Params, NamedDecl *Decl) { AdoptTemplateParameterList(Params, DC); - return new (C, DC) TypeAliasTemplateDecl(DC, L, Name, Params, Decl); + return new (C, DC) TypeAliasTemplateDecl(C, DC, L, Name, Params, Decl); } TypeAliasTemplateDecl *TypeAliasTemplateDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) TypeAliasTemplateDecl(nullptr, SourceLocation(), + return new (C, ID) TypeAliasTemplateDecl(C, nullptr, SourceLocation(), DeclarationName(), nullptr, nullptr); } @@ -943,12 +943,13 @@ VarTemplateDecl *VarTemplateDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, VarDecl *Decl) { - return new (C, DC) VarTemplateDecl(DC, L, Name, Params, Decl); + return new (C, DC) VarTemplateDecl(C, DC, L, Name, Params, Decl); } VarTemplateDecl *VarTemplateDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) VarTemplateDecl(EmptyShell()); + return new (C, ID) VarTemplateDecl(C, nullptr, SourceLocation(), + DeclarationName(), nullptr, nullptr); } // TODO: Unify across class, function and variable templates? @@ -1057,18 +1058,19 @@ VarTemplateDecl::findPartialSpecInstantiatedFromMember( // VarTemplateSpecializationDecl Implementation //===----------------------------------------------------------------------===// VarTemplateSpecializationDecl::VarTemplateSpecializationDecl( - ASTContext &Context, Kind DK, DeclContext *DC, SourceLocation StartLoc, + Kind DK, ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args, unsigned NumArgs) - : VarDecl(DK, DC, StartLoc, IdLoc, SpecializedTemplate->getIdentifier(), T, - TInfo, S), + : VarDecl(DK, Context, DC, StartLoc, IdLoc, + SpecializedTemplate->getIdentifier(), T, TInfo, S), SpecializedTemplate(SpecializedTemplate), ExplicitInfo(nullptr), TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args, NumArgs)), SpecializationKind(TSK_Undeclared) {} -VarTemplateSpecializationDecl::VarTemplateSpecializationDecl(Kind DK) - : VarDecl(DK, nullptr, SourceLocation(), SourceLocation(), nullptr, +VarTemplateSpecializationDecl::VarTemplateSpecializationDecl(Kind DK, + ASTContext &C) + : VarDecl(DK, C, nullptr, SourceLocation(), SourceLocation(), nullptr, QualType(), nullptr, SC_None), ExplicitInfo(nullptr), SpecializationKind(TSK_Undeclared) {} @@ -1078,13 +1080,14 @@ VarTemplateSpecializationDecl *VarTemplateSpecializationDecl::Create( TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args, unsigned NumArgs) { return new (Context, DC) VarTemplateSpecializationDecl( - Context, VarTemplateSpecialization, DC, StartLoc, IdLoc, + VarTemplateSpecialization, Context, DC, StartLoc, IdLoc, SpecializedTemplate, T, TInfo, S, Args, NumArgs); } VarTemplateSpecializationDecl * VarTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) VarTemplateSpecializationDecl(VarTemplateSpecialization); + return new (C, ID) + VarTemplateSpecializationDecl(VarTemplateSpecialization, C); } void VarTemplateSpecializationDecl::getNameForDiagnostic( @@ -1123,7 +1126,7 @@ VarTemplatePartialSpecializationDecl::VarTemplatePartialSpecializationDecl( VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args, unsigned NumArgs, const ASTTemplateArgumentListInfo *ArgInfos) - : VarTemplateSpecializationDecl(Context, VarTemplatePartialSpecialization, + : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization, Context, DC, StartLoc, IdLoc, SpecializedTemplate, T, TInfo, S, Args, NumArgs), TemplateParams(Params), ArgsAsWritten(ArgInfos), @@ -1153,5 +1156,5 @@ VarTemplatePartialSpecializationDecl::Create( VarTemplatePartialSpecializationDecl * VarTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) VarTemplatePartialSpecializationDecl(); + return new (C, ID) VarTemplatePartialSpecializationDecl(C); } diff --git a/clang/lib/AST/ExternalASTSource.cpp b/clang/lib/AST/ExternalASTSource.cpp index 05a17db6bf0..ae8297cecd1 100644 --- a/clang/lib/AST/ExternalASTSource.cpp +++ b/clang/lib/AST/ExternalASTSource.cpp @@ -14,7 +14,9 @@ //===----------------------------------------------------------------------===// #include "clang/AST/ExternalASTSource.h" +#include "clang/AST/ASTContext.h" #include "clang/AST/DeclarationName.h" +#include "llvm/Support/ErrorHandling.h" using namespace clang; @@ -60,3 +62,21 @@ ExternalASTSource::FindExternalLexicalDecls(const DeclContext *DC, } void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { } + +uint32_t ExternalASTSource::incrementGeneration(ASTContext &C) { + uint32_t OldGeneration = CurrentGeneration; + + // Make sure the generation of the topmost external source for the context is + // incremented. That might not be us. + auto *P = C.getExternalSource(); + if (P && P != this) + CurrentGeneration = P->incrementGeneration(C); + else { + // FIXME: Only bump the generation counter if the current generation number + // has been observed? + if (!++CurrentGeneration) + llvm::report_fatal_error("generation counter overflowed", false); + } + + return OldGeneration; +} diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp index 941410a7416..56c8a07140b 100644 --- a/clang/lib/CodeGen/CGBlocks.cpp +++ b/clang/lib/CodeGen/CGBlocks.cpp @@ -841,8 +841,8 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) { } else { // Fake up a new variable so that EmitScalarInit doesn't think // we're referring to the variable in its own initializer. - ImplicitParamDecl blockFieldPseudoVar(/*DC*/ 0, SourceLocation(), - /*name*/ 0, type); + ImplicitParamDecl blockFieldPseudoVar(getContext(), /*DC*/ 0, + SourceLocation(), /*name*/ 0, type); // We use one of these or the other depending on whether the // reference is nested. @@ -1108,7 +1108,7 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, QualType selfTy = getContext().VoidPtrTy; IdentifierInfo *II = &CGM.getContext().Idents.get(".block_descriptor"); - ImplicitParamDecl selfDecl(const_cast<BlockDecl*>(blockDecl), + ImplicitParamDecl selfDecl(getContext(), const_cast<BlockDecl*>(blockDecl), SourceLocation(), II, selfTy); args.push_back(&selfDecl); @@ -1279,9 +1279,9 @@ CodeGenFunction::GenerateCopyHelperFunction(const CGBlockInfo &blockInfo) { ASTContext &C = getContext(); FunctionArgList args; - ImplicitParamDecl dstDecl(0, SourceLocation(), 0, C.VoidPtrTy); + ImplicitParamDecl dstDecl(getContext(), 0, SourceLocation(), 0, C.VoidPtrTy); args.push_back(&dstDecl); - ImplicitParamDecl srcDecl(0, SourceLocation(), 0, C.VoidPtrTy); + ImplicitParamDecl srcDecl(getContext(), 0, SourceLocation(), 0, C.VoidPtrTy); args.push_back(&srcDecl); const CGFunctionInfo &FI = CGM.getTypes().arrangeFreeFunctionDeclaration( @@ -1453,7 +1453,7 @@ CodeGenFunction::GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo) { ASTContext &C = getContext(); FunctionArgList args; - ImplicitParamDecl srcDecl(0, SourceLocation(), 0, C.VoidPtrTy); + ImplicitParamDecl srcDecl(getContext(), 0, SourceLocation(), 0, C.VoidPtrTy); args.push_back(&srcDecl); const CGFunctionInfo &FI = CGM.getTypes().arrangeFreeFunctionDeclaration( @@ -1738,10 +1738,12 @@ generateByrefCopyHelper(CodeGenFunction &CGF, QualType R = Context.VoidTy; FunctionArgList args; - ImplicitParamDecl dst(0, SourceLocation(), 0, Context.VoidPtrTy); + ImplicitParamDecl dst(CGF.getContext(), 0, SourceLocation(), 0, + Context.VoidPtrTy); args.push_back(&dst); - ImplicitParamDecl src(0, SourceLocation(), 0, Context.VoidPtrTy); + ImplicitParamDecl src(CGF.getContext(), 0, SourceLocation(), 0, + Context.VoidPtrTy); args.push_back(&src); const CGFunctionInfo &FI = CGF.CGM.getTypes().arrangeFreeFunctionDeclaration( @@ -1810,7 +1812,8 @@ generateByrefDisposeHelper(CodeGenFunction &CGF, QualType R = Context.VoidTy; FunctionArgList args; - ImplicitParamDecl src(0, SourceLocation(), 0, Context.VoidPtrTy); + ImplicitParamDecl src(CGF.getContext(), 0, SourceLocation(), 0, + Context.VoidPtrTy); args.push_back(&src); const CGFunctionInfo &FI = CGF.CGM.getTypes().arrangeFreeFunctionDeclaration( diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp index 59129f6aeea..0cc9330a866 100644 --- a/clang/lib/CodeGen/CGDeclCXX.cpp +++ b/clang/lib/CodeGen/CGDeclCXX.cpp @@ -522,7 +522,8 @@ llvm::Function *CodeGenFunction::generateDestroyHelper( llvm::Constant *addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray, const VarDecl *VD) { FunctionArgList args; - ImplicitParamDecl dst(0, SourceLocation(), 0, getContext().VoidPtrTy); + ImplicitParamDecl dst(getContext(), 0, SourceLocation(), 0, + getContext().VoidPtrTy); args.push_back(&dst); const CGFunctionInfo &FI = CGM.getTypes().arrangeFreeFunctionDeclaration( diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp index 47a096d5404..d1cfddce9f1 100644 --- a/clang/lib/CodeGen/CGObjC.cpp +++ b/clang/lib/CodeGen/CGObjC.cpp @@ -2901,9 +2901,9 @@ CodeGenFunction::GenerateObjCAtomicSetterCopyHelperFunction( SrcTy = C.getPointerType(SrcTy); FunctionArgList args; - ImplicitParamDecl dstDecl(FD, SourceLocation(), 0, DestTy); + ImplicitParamDecl dstDecl(getContext(), FD, SourceLocation(), 0, DestTy); args.push_back(&dstDecl); - ImplicitParamDecl srcDecl(FD, SourceLocation(), 0, SrcTy); + ImplicitParamDecl srcDecl(getContext(), FD, SourceLocation(), 0, SrcTy); args.push_back(&srcDecl); const CGFunctionInfo &FI = CGM.getTypes().arrangeFreeFunctionDeclaration( @@ -2980,9 +2980,9 @@ CodeGenFunction::GenerateObjCAtomicGetterCopyHelperFunction( SrcTy = C.getPointerType(SrcTy); FunctionArgList args; - ImplicitParamDecl dstDecl(FD, SourceLocation(), 0, DestTy); + ImplicitParamDecl dstDecl(getContext(), FD, SourceLocation(), 0, DestTy); args.push_back(&dstDecl); - ImplicitParamDecl srcDecl(FD, SourceLocation(), 0, SrcTy); + ImplicitParamDecl srcDecl(getContext(), FD, SourceLocation(), 0, SrcTy); args.push_back(&srcDecl); const CGFunctionInfo &FI = CGM.getTypes().arrangeFreeFunctionDeclaration( diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index 77eb1a14434..ade23b87d17 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -358,8 +358,21 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, // source. if (!CI.hasASTContext() || !CI.getASTContext().getExternalSource()) { Preprocessor &PP = CI.getPreprocessor(); + + // If modules are enabled, create the module manager before creating + // any builtins, so that all declarations know that they might be + // extended by an external source. + if (CI.getLangOpts().Modules) + CI.createModuleManager(); + PP.getBuiltinInfo().InitializeBuiltins(PP.getIdentifierTable(), PP.getLangOpts()); + } else { + // FIXME: If this is a problem, recover from it by creating a multiplex + // source. + assert((!CI.getLangOpts().Modules || CI.getModuleManager()) && + "modules enabled but created an external source that " + "doesn't support modules"); } // If there is a layout overrides file, attach an external AST source that @@ -371,7 +384,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, CI.getFrontendOpts().OverrideRecordLayoutsFile)); CI.getASTContext().setExternalSource(Override); } - + return true; // If we failed, reset state since the client will not end up calling the diff --git a/clang/lib/Sema/MultiplexExternalSemaSource.cpp b/clang/lib/Sema/MultiplexExternalSemaSource.cpp index ad7627a4571..35072a5faca 100644 --- a/clang/lib/Sema/MultiplexExternalSemaSource.cpp +++ b/clang/lib/Sema/MultiplexExternalSemaSource.cpp @@ -49,6 +49,11 @@ Decl *MultiplexExternalSemaSource::GetExternalDecl(uint32_t ID) { return 0; } +void MultiplexExternalSemaSource::CompleteRedeclChain(const Decl *D) { + for (size_t i = 0; i < Sources.size(); ++i) + Sources[i]->CompleteRedeclChain(D); +} + Selector MultiplexExternalSemaSource::GetExternalSelector(uint32_t ID) { Selector Sel; for(size_t i = 0; i < Sources.size(); ++i) { diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index d61372cc1bd..eb151ef16f6 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -1707,7 +1707,7 @@ void ASTReader::markIdentifierUpToDate(IdentifierInfo *II) { // Update the generation for this identifier. if (getContext().getLangOpts().Modules) - IdentifierGeneration[II] = CurrentGeneration; + IdentifierGeneration[II] = getGeneration(); } struct ASTReader::ModuleMacroInfo { @@ -3435,7 +3435,7 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, Deserializing AnASTFile(this); // Bump the generation number. - unsigned PreviousGeneration = CurrentGeneration++; + unsigned PreviousGeneration = incrementGeneration(Context); unsigned NumModules = ModuleMgr.size(); SmallVector<ImportedModule, 4> Loaded; @@ -3615,7 +3615,7 @@ ASTReader::ReadASTCore(StringRef FileName, std::string ErrorStr; ModuleManager::AddModuleResult AddResult = ModuleMgr.addModule(FileName, Type, ImportLoc, ImportedBy, - CurrentGeneration, ExpectedSize, ExpectedModTime, + getGeneration(), ExpectedSize, ExpectedModTime, M, ErrorStr); switch (AddResult) { @@ -5939,6 +5939,37 @@ Decl *ASTReader::GetExternalDecl(uint32_t ID) { return GetDecl(ID); } +void ASTReader::CompleteRedeclChain(const Decl *D) { + const DeclContext *DC = D->getDeclContext()->getRedeclContext(); + + // Recursively ensure that the decl context itself is complete + // (in particular, this matters if the decl context is a namespace). + // + // FIXME: This should be performed by lookup instead of here. + cast<Decl>(DC)->getMostRecentDecl(); + + // If this is a named declaration, complete it by looking it up + // within its context. + // + // FIXME: We don't currently handle the cases where we can't do this; + // merging a class definition that contains unnamed entities should merge + // those entities. Likewise, merging a function definition should merge + // all mergeable entities within it. + if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC) || + isa<CXXRecordDecl>(DC) || isa<EnumDecl>(DC)) { + if (DeclarationName Name = cast<NamedDecl>(D)->getDeclName()) { + auto *II = Name.getAsIdentifierInfo(); + if (isa<TranslationUnitDecl>(DC) && II) { + // Outside of C++, we don't have a lookup table for the TU, so update + // the identifier instead. In C++, either way should work fine. + if (II->isOutOfDate()) + updateOutOfDateIdentifier(*II); + } else + DC->lookup(Name); + } + } +} + uint64_t ASTReader::readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record, unsigned &Idx) { @@ -6926,7 +6957,7 @@ void ASTReader::ReadMethodPool(Selector Sel) { // Get the selector generation and update it to the current generation. unsigned &Generation = SelectorGeneration[Sel]; unsigned PriorGeneration = Generation; - Generation = CurrentGeneration; + Generation = getGeneration(); // Search for methods defined with this selector. ++NumMethodPoolLookups; @@ -8114,7 +8145,6 @@ void ASTReader::finishPendingActions() { if (auto RD = dyn_cast<CXXRecordDecl>(*D)) { for (auto R : RD->redecls()) cast<CXXRecordDecl>(R)->DefinitionData = RD->DefinitionData; - } continue; @@ -8250,7 +8280,7 @@ ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context, StringRef isysroot, AllowConfigurationMismatch(AllowConfigurationMismatch), ValidateSystemInputs(ValidateSystemInputs), UseGlobalIndex(UseGlobalIndex), TriedLoadingGlobalIndex(false), - CurrentGeneration(0), CurrSwitchCaseStmts(&SwitchCaseStmts), + CurrSwitchCaseStmts(&SwitchCaseStmts), NumSLocEntriesRead(0), TotalNumSLocEntries(0), NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), TotalNumMacros(0), NumIdentifierLookups(0), NumIdentifierLookupHits(0), NumSelectorsRead(0), diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index d2219d49812..719d56edf2c 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -1289,8 +1289,9 @@ void ASTDeclReader::ReadCXXDefinitionData( void ASTDeclReader::MergeDefinitionData( CXXRecordDecl *D, struct CXXRecordDecl::DefinitionData &MergeDD) { - assert(D->DefinitionData && "merging class definition into non-definition"); - auto &DD = *D->DefinitionData; + assert(D->DefinitionData.getNotUpdated() && + "merging class definition into non-definition"); + auto &DD = *D->DefinitionData.getNotUpdated(); // If the new definition has new special members, let the name lookup // code know that it needs to look in the new definition too. @@ -1390,7 +1391,7 @@ void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D) { // If we're reading an update record, we might already have a definition for // this record. If so, just merge into it. - if (D->DefinitionData) { + if (D->DefinitionData.getNotUpdated()) { MergeDefinitionData(D, *DD); return; } @@ -1399,25 +1400,26 @@ void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D) { // that all other deserialized declarations will see it. CXXRecordDecl *Canon = D->getCanonicalDecl(); if (Canon == D) { - D->DefinitionData = DD; + D->DefinitionData.setNotUpdated(DD); D->IsCompleteDefinition = true; - } else if (!Canon->DefinitionData) { - Canon->DefinitionData = D->DefinitionData = DD; - D->IsCompleteDefinition = true; - - // Note that we have deserialized a definition. Any declarations - // deserialized before this one will be be given the DefinitionData - // pointer at the end. - Reader.PendingDefinitions.insert(D); - } else { + } else if (auto *CanonDD = Canon->DefinitionData.getNotUpdated()) { // We have already deserialized a definition of this record. This // definition is no longer really a definition. Note that the pre-existing // definition is the *real* definition. Reader.MergedDeclContexts.insert( - std::make_pair(D, Canon->DefinitionData->Definition)); - D->DefinitionData = D->getCanonicalDecl()->DefinitionData; + std::make_pair(D, CanonDD->Definition)); + D->DefinitionData = Canon->DefinitionData; D->IsCompleteDefinition = false; MergeDefinitionData(D, *DD); + } else { + Canon->DefinitionData.setNotUpdated(DD); + D->DefinitionData = Canon->DefinitionData; + D->IsCompleteDefinition = true; + + // Note that we have deserialized a definition. Any declarations + // deserialized before this one will be be given the DefinitionData + // pointer at the end. + Reader.PendingDefinitions.insert(D); } } @@ -1741,16 +1743,16 @@ ASTDeclReader::VisitClassTemplateSpecializationDeclImpl( // This declaration might be a definition. Merge with any existing // definition. - if (D->DefinitionData) { - if (!CanonSpec->DefinitionData) { - CanonSpec->DefinitionData = D->DefinitionData; - } else { - MergeDefinitionData(CanonSpec, *D->DefinitionData); + if (auto *DDD = D->DefinitionData.getNotUpdated()) { + if (auto *CanonDD = CanonSpec->DefinitionData.getNotUpdated()) { + MergeDefinitionData(CanonSpec, *DDD); Reader.PendingDefinitions.erase(D); Reader.MergedDeclContexts.insert( - std::make_pair(D, CanonSpec->DefinitionData->Definition)); + std::make_pair(D, CanonDD->Definition)); D->IsCompleteDefinition = false; D->DefinitionData = CanonSpec->DefinitionData; + } else { + CanonSpec->DefinitionData = D->DefinitionData; } } } @@ -2459,7 +2461,7 @@ ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) { template<typename DeclT> void ASTDeclReader::attachPreviousDeclImpl(Redeclarable<DeclT> *D, Decl *Previous) { - D->RedeclLink.setNext(cast<DeclT>(Previous)); + D->RedeclLink.setPrevious(cast<DeclT>(Previous)); } void ASTDeclReader::attachPreviousDeclImpl(...) { llvm_unreachable("attachPreviousDecl on non-redeclarable declaration"); @@ -2489,7 +2491,7 @@ void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *Previous) { template<typename DeclT> void ASTDeclReader::attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest) { - D->RedeclLink = Redeclarable<DeclT>::LatestDeclLink(cast<DeclT>(Latest)); + D->RedeclLink.setLatest(cast<DeclT>(Latest)); } void ASTDeclReader::attachLatestDeclImpl(...) { llvm_unreachable("attachLatestDecl on non-redeclarable declaration"); @@ -2500,8 +2502,8 @@ void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) { switch (D->getKind()) { #define ABSTRACT_DECL(TYPE) -#define DECL(TYPE, BASE) \ - case Decl::TYPE: \ +#define DECL(TYPE, BASE) \ + case Decl::TYPE: \ attachLatestDeclImpl(cast<TYPE##Decl>(D), Latest); \ break; #include "clang/AST/DeclNodes.inc" diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index d9bef82130a..d88d1ca99f1 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -5301,8 +5301,7 @@ void ASTWriter::AddCXXCtorInitializers( } void ASTWriter::AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record) { - assert(D->DefinitionData); - struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData; + auto &Data = D->data(); Record.push_back(Data.IsLambda); Record.push_back(Data.UserDeclaredConstructor); Record.push_back(Data.UserDeclaredSpecialMembers); @@ -5361,7 +5360,7 @@ void ASTWriter::AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Rec // Add lambda-specific data. if (Data.IsLambda) { - CXXRecordDecl::LambdaDefinitionData &Lambda = D->getLambdaData(); + auto &Lambda = D->getLambdaData(); Record.push_back(Lambda.Dependent); Record.push_back(Lambda.IsGenericLambda); Record.push_back(Lambda.CaptureDefault); |