diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 49 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTCommon.h | 2 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 9 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReaderDecl.cpp | 47 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 1 |
5 files changed, 55 insertions, 53 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index ba4bcbc488c..34d085e7128 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -1083,7 +1083,7 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target) { InitBuiltinType(HalfTy, BuiltinType::Half); // Builtin type used to help define __builtin_va_list. - VaListTagTy = QualType(); + VaListTagDecl = nullptr; } DiagnosticsEngine &ASTContext::getDiagnostics() const { @@ -6068,8 +6068,8 @@ CreateAArch64ABIBuiltinVaListDecl(const ASTContext *Context) { VaListTagDecl->addDecl(Field); } VaListTagDecl->completeDefinition(); + Context->VaListTagDecl = VaListTagDecl; QualType VaListTagType = Context->getRecordType(VaListTagDecl); - Context->VaListTagTy = VaListTagType; // } __builtin_va_list; return Context->buildImplicitTypedef(VaListTagType, "__builtin_va_list"); @@ -6120,8 +6120,8 @@ static TypedefDecl *CreatePowerABIBuiltinVaListDecl(const ASTContext *Context) { VaListTagDecl->addDecl(Field); } VaListTagDecl->completeDefinition(); + Context->VaListTagDecl = VaListTagDecl; QualType VaListTagType = Context->getRecordType(VaListTagDecl); - Context->VaListTagTy = VaListTagType; // } __va_list_tag; TypedefDecl *VaListTagTypedefDecl = @@ -6140,7 +6140,7 @@ static TypedefDecl *CreatePowerABIBuiltinVaListDecl(const ASTContext *Context) { static TypedefDecl * CreateX86_64ABIBuiltinVaListDecl(const ASTContext *Context) { - // typedef struct __va_list_tag { + // struct __va_list_tag { RecordDecl *VaListTagDecl; VaListTagDecl = Context->buildImplicitRecord("__va_list_tag"); VaListTagDecl->startDefinition(); @@ -6180,21 +6180,15 @@ CreateX86_64ABIBuiltinVaListDecl(const ASTContext *Context) { VaListTagDecl->addDecl(Field); } VaListTagDecl->completeDefinition(); + Context->VaListTagDecl = VaListTagDecl; QualType VaListTagType = Context->getRecordType(VaListTagDecl); - Context->VaListTagTy = VaListTagType; - - // } __va_list_tag; - TypedefDecl *VaListTagTypedefDecl = - Context->buildImplicitTypedef(VaListTagType, "__va_list_tag"); - QualType VaListTagTypedefType = - Context->getTypedefType(VaListTagTypedefDecl); + // }; - // typedef __va_list_tag __builtin_va_list[1]; + // typedef struct __va_list_tag __builtin_va_list[1]; llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 1); - QualType VaListTagArrayType - = Context->getConstantArrayType(VaListTagTypedefType, - Size, ArrayType::Normal,0); + QualType VaListTagArrayType = + Context->getConstantArrayType(VaListTagType, Size, ArrayType::Normal, 0); return Context->buildImplicitTypedef(VaListTagArrayType, "__builtin_va_list"); } @@ -6249,7 +6243,7 @@ CreateAAPCSABIBuiltinVaListDecl(const ASTContext *Context) { static TypedefDecl * CreateSystemZBuiltinVaListDecl(const ASTContext *Context) { - // typedef struct __va_list_tag { + // struct __va_list_tag { RecordDecl *VaListTagDecl; VaListTagDecl = Context->buildImplicitRecord("__va_list_tag"); VaListTagDecl->startDefinition(); @@ -6289,20 +6283,15 @@ CreateSystemZBuiltinVaListDecl(const ASTContext *Context) { VaListTagDecl->addDecl(Field); } VaListTagDecl->completeDefinition(); + Context->VaListTagDecl = VaListTagDecl; QualType VaListTagType = Context->getRecordType(VaListTagDecl); - Context->VaListTagTy = VaListTagType; - // } __va_list_tag; - TypedefDecl *VaListTagTypedefDecl = - Context->buildImplicitTypedef(VaListTagType, "__va_list_tag"); - QualType VaListTagTypedefType = - Context->getTypedefType(VaListTagTypedefDecl); + // }; // typedef __va_list_tag __builtin_va_list[1]; llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 1); - QualType VaListTagArrayType - = Context->getConstantArrayType(VaListTagTypedefType, - Size, ArrayType::Normal,0); + QualType VaListTagArrayType = + Context->getConstantArrayType(VaListTagType, Size, ArrayType::Normal, 0); return Context->buildImplicitTypedef(VaListTagArrayType, "__builtin_va_list"); } @@ -6340,13 +6329,13 @@ TypedefDecl *ASTContext::getBuiltinVaListDecl() const { return BuiltinVaListDecl; } -QualType ASTContext::getVaListTagType() const { - // Force the creation of VaListTagTy by building the __builtin_va_list +Decl *ASTContext::getVaListTagDecl() const { + // Force the creation of VaListTagDecl by building the __builtin_va_list // declaration. - if (VaListTagTy.isNull()) - (void) getBuiltinVaListDecl(); + if (!VaListTagDecl) + (void)getBuiltinVaListDecl(); - return VaListTagTy; + return VaListTagDecl; } void ASTContext::setObjCConstantStringInterface(ObjCInterfaceDecl *Decl) { diff --git a/clang/lib/Serialization/ASTCommon.h b/clang/lib/Serialization/ASTCommon.h index f21e8a7ea03..e59bc891f9b 100644 --- a/clang/lib/Serialization/ASTCommon.h +++ b/clang/lib/Serialization/ASTCommon.h @@ -62,8 +62,6 @@ TypeID MakeTypeID(ASTContext &Context, QualType T, IdxForTypeTy IdxForType) { return TypeIdx(PREDEF_TYPE_AUTO_DEDUCT).asTypeID(FastQuals); if (T == Context.AutoRRefDeductTy) return TypeIdx(PREDEF_TYPE_AUTO_RREF_DEDUCT).asTypeID(FastQuals); - if (T == Context.VaListTagTy) - return TypeIdx(PREDEF_TYPE_VA_LIST_TAG).asTypeID(FastQuals); return IdxForType(T).asTypeID(FastQuals); } diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 520c3418b26..0c4dab4065b 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -5762,10 +5762,6 @@ QualType ASTReader::GetType(TypeID ID) { T = Context.ARCUnbridgedCastTy; break; - case PREDEF_TYPE_VA_LIST_TAG: - T = Context.getVaListTagType(); - break; - case PREDEF_TYPE_BUILTIN_FN: T = Context.BuiltinFnTy; break; @@ -6078,6 +6074,9 @@ static Decl *getPredefinedDecl(ASTContext &Context, PredefinedDeclIDs ID) { case PREDEF_DECL_BUILTIN_VA_LIST_ID: return Context.getBuiltinVaListDecl(); + case PREDEF_DECL_VA_LIST_TAG: + return Context.getVaListTagDecl(); + case PREDEF_DECL_EXTERN_C_CONTEXT_ID: return Context.getExternCContextDecl(); } @@ -8142,6 +8141,8 @@ void ASTReader::finishPendingActions() { assert(PendingDeclChainsKnown.empty()); PendingDeclChains.clear(); + assert(RedeclsDeserialized.empty() && "some redecls not wired up"); + // Make the most recent of the top-level declarations visible. for (TopLevelDeclsMap::iterator TLD = TopLevelDecls.begin(), TLDEnd = TopLevelDecls.end(); TLD != TLDEnd; ++TLD) { diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index f6858b4a5b7..45a3e45bbcf 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -126,35 +126,43 @@ namespace clang { class RedeclarableResult { ASTReader &Reader; GlobalDeclID FirstID; + Decl *LoadedDecl; Decl *MergeWith; mutable bool Owning; bool IsKeyDecl; - Decl::Kind DeclKind; void operator=(RedeclarableResult &) = delete; public: RedeclarableResult(ASTReader &Reader, GlobalDeclID FirstID, - Decl *MergeWith, Decl::Kind DeclKind, - bool IsKeyDecl) - : Reader(Reader), FirstID(FirstID), MergeWith(MergeWith), - Owning(true), IsKeyDecl(IsKeyDecl), DeclKind(DeclKind) {} + Decl *LoadedDecl, Decl *MergeWith, bool IsKeyDecl) + : Reader(Reader), FirstID(FirstID), LoadedDecl(LoadedDecl), + MergeWith(MergeWith), Owning(true), IsKeyDecl(IsKeyDecl) {} RedeclarableResult(RedeclarableResult &&Other) - : Reader(Other.Reader), FirstID(Other.FirstID), - MergeWith(Other.MergeWith), Owning(Other.Owning), - IsKeyDecl(Other.IsKeyDecl), DeclKind(Other.DeclKind) { + : Reader(Other.Reader), FirstID(Other.FirstID), + LoadedDecl(Other.LoadedDecl), MergeWith(Other.MergeWith), + Owning(Other.Owning), IsKeyDecl(Other.IsKeyDecl) { Other.Owning = false; } ~RedeclarableResult() { - if (FirstID && Owning && isRedeclarableDeclKind(DeclKind)) { + if (FirstID && Owning && + isRedeclarableDeclKind(LoadedDecl->getKind())) { auto Canon = Reader.GetDecl(FirstID)->getCanonicalDecl(); if (Reader.PendingDeclChainsKnown.insert(Canon).second) Reader.PendingDeclChains.push_back(Canon); } } + /// \brief Note that a RedeclarableDecl is not actually redeclarable. + void setNotRedeclarable() { + Owning = false; + Reader.RedeclsDeserialized.erase(LoadedDecl); + assert(FirstID == LoadedDecl->getGlobalID() && !MergeWith && + "non-redeclarable declaration was redeclared?"); + } + /// \brief Retrieve the first ID. GlobalDeclID getFirstID() const { return FirstID; } @@ -908,7 +916,9 @@ void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { } void ASTDeclReader::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { - VisitTypedefNameDecl(D); + RedeclarableResult Redecl = VisitTypedefNameDecl(D); + Redecl.setNotRedeclarable(); + D->Variance = Record[Idx++]; D->Index = Record[Idx++]; D->VarianceLoc = ReadSourceLocation(Record, Idx); @@ -1208,9 +1218,11 @@ ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) { }; switch ((VarKind)Record[Idx++]) { case VarNotTemplate: - // Only true variables (not parameters or implicit parameters) can be merged - if (VD->getKind() != Decl::ParmVar && VD->getKind() != Decl::ImplicitParam && - !isa<VarTemplateSpecializationDecl>(VD)) + // Only true variables (not parameters or implicit parameters) can be + // merged; the other kinds are not really redeclarable at all. + if (isa<ParmVarDecl>(VD) || isa<ImplicitParamDecl>(VD)) + Redecl.setNotRedeclarable(); + else if (!isa<VarTemplateSpecializationDecl>(VD)) mergeRedeclarable(VD, Redecl); break; case VarTemplate: @@ -2070,6 +2082,7 @@ ASTDeclReader::VisitVarTemplateSpecializationDeclImpl( if (writtenAsCanonicalDecl) { VarTemplateDecl *CanonPattern = ReadDeclAs<VarTemplateDecl>(Record, Idx); if (D->isCanonicalDecl()) { // It's kept in the folding set. + // FIXME: If it's already present, merge it. if (VarTemplatePartialSpecializationDecl *Partial = dyn_cast<VarTemplatePartialSpecializationDecl>(D)) { CanonPattern->getCommonPtr()->PartialSpecializations @@ -2212,8 +2225,8 @@ ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) { // The result structure takes care to note that we need to load the // other declaration chains for this ID. - return RedeclarableResult(Reader, FirstDeclID, MergeWith, - static_cast<T *>(D)->getKind(), IsKeyDecl); + return RedeclarableResult(Reader, FirstDeclID, static_cast<T *>(D), MergeWith, + IsKeyDecl); } /// \brief Attempts to merge the given declaration (D) with another declaration @@ -2256,8 +2269,7 @@ void ASTDeclReader::mergeTemplatePattern(RedeclarableTemplateDecl *D, auto *DPattern = D->getTemplatedDecl(); auto *ExistingPattern = Existing->getTemplatedDecl(); RedeclarableResult Result(Reader, DPattern->getCanonicalDecl()->getGlobalID(), - /*MergeWith*/ExistingPattern, DPattern->getKind(), - IsKeyDecl); + DPattern, /*MergeWith*/ ExistingPattern, IsKeyDecl); if (auto *DClass = dyn_cast<CXXRecordDecl>(DPattern)) { // Merge with any existing definition. @@ -3540,6 +3552,7 @@ void ASTReader::loadPendingDeclChain(Decl *CanonDecl) { // Build up the list of redeclarations. RedeclChainVisitor Visitor(*this, SearchDecls, RedeclsDeserialized, CanonID); ModuleMgr.visit(Visitor); + RedeclsDeserialized.erase(CanonDecl); // Retrieve the chains. ArrayRef<Decl *> Chain = Visitor.getChain(); diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 60c9aa4486c..ba8e1a85107 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -4165,6 +4165,7 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, RegisterPredefDecl(Context.ObjCInstanceTypeDecl, PREDEF_DECL_OBJC_INSTANCETYPE_ID); RegisterPredefDecl(Context.BuiltinVaListDecl, PREDEF_DECL_BUILTIN_VA_LIST_ID); + RegisterPredefDecl(Context.VaListTagDecl, PREDEF_DECL_VA_LIST_TAG); RegisterPredefDecl(Context.ExternCContext, PREDEF_DECL_EXTERN_C_CONTEXT_ID); // Build a record containing all of the tentative definitions in this file, in |