From: Eugene Zelenko Date: Wed, 11 Apr 2018 20:57:28 +0000 (+0000) Subject: [Serialization] Fix some Clang-tidy modernize and Include What You Use warnings;... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e69b33f232c96d3d5ec706e6426a16aa79f635d0;p=platform%2Fupstream%2Fllvm.git [Serialization] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). llvm-svn: 329851 --- diff --git a/clang/include/clang/Serialization/Module.h b/clang/include/clang/Serialization/Module.h index 26b3bce..d799e9f 100644 --- a/clang/include/clang/Serialization/Module.h +++ b/clang/include/clang/Serialization/Module.h @@ -1,4 +1,4 @@ -//===--- Module.h - Module description --------------------------*- C++ -*-===// +//===- Module.h - Module description ----------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -15,42 +15,49 @@ #ifndef LLVM_CLANG_SERIALIZATION_MODULE_H #define LLVM_CLANG_SERIALIZATION_MODULE_H -#include "clang/Basic/FileManager.h" #include "clang/Basic/Module.h" #include "clang/Basic/SourceLocation.h" #include "clang/Serialization/ASTBitCodes.h" #include "clang/Serialization/ContinuousRangeMap.h" #include "clang/Serialization/ModuleFileExtension.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Bitcode/BitstreamReader.h" #include "llvm/Support/Endian.h" +#include +#include #include #include - -namespace llvm { -template class OnDiskChainedHashTable; -template class OnDiskIterableChainedHashTable; -} +#include namespace clang { -class DeclContext; -class Module; +class FileEntry; namespace serialization { -namespace reader { - class ASTDeclContextNameLookupTrait; -} - /// \brief Specifies the kind of module that has been loaded. enum ModuleKind { - MK_ImplicitModule, ///< File is an implicitly-loaded module. - MK_ExplicitModule, ///< File is an explicitly-loaded module. - MK_PCH, ///< File is a PCH file treated as such. - MK_Preamble, ///< File is a PCH file treated as the preamble. - MK_MainFile, ///< File is a PCH file treated as the actual main file. - MK_PrebuiltModule ///< File is from a prebuilt module path. + /// File is an implicitly-loaded module. + MK_ImplicitModule, + + /// File is an explicitly-loaded module. + MK_ExplicitModule, + + /// File is a PCH file treated as such. + MK_PCH, + + /// File is a PCH file treated as the preamble. + MK_Preamble, + + /// File is a PCH file treated as the actual main file. + MK_MainFile, + + /// File is from a prebuilt module path. + MK_PrebuiltModule }; /// \brief The input file that has been loaded from this AST file, along with @@ -65,7 +72,8 @@ class InputFile { llvm::PointerIntPair Val; public: - InputFile() {} + InputFile() = default; + InputFile(const FileEntry *File, bool isOverridden = false, bool isOutOfDate = false) { assert(!(isOverridden && isOutOfDate) && @@ -205,6 +213,7 @@ public: StringRef ModuleOffsetMap; // === Input Files === + /// \brief The cursor to the start of the input-files block. llvm::BitstreamCursor InputFilesCursor; @@ -347,6 +356,7 @@ public: void *HeaderFileInfoTable = nullptr; // === Submodule information === + /// \brief The number of submodules in this module. unsigned LocalNumSubmodules = 0; @@ -470,8 +480,8 @@ public: void dump(); }; -} // end namespace serialization +} // namespace serialization -} // end namespace clang +} // namespace clang -#endif +#endif // LLVM_CLANG_SERIALIZATION_MODULE_H diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index af4cf84..7a5d22c 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -1,4 +1,4 @@ -//===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===// +//===- ASTReaderDecl.cpp - Decl Deserialization ---------------------------===// // // The LLVM Compiler Infrastructure // @@ -15,42 +15,89 @@ #include "ASTCommon.h" #include "ASTReaderInternals.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/Attr.h" +#include "clang/AST/AttrIterator.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclBase.h" #include "clang/AST/DeclCXX.h" -#include "clang/AST/DeclGroup.h" +#include "clang/AST/DeclFriend.h" +#include "clang/AST/DeclObjC.h" +#include "clang/AST/DeclOpenMP.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/DeclVisitor.h" +#include "clang/AST/DeclarationName.h" #include "clang/AST/Expr.h" +#include "clang/AST/ExternalASTSource.h" +#include "clang/AST/LambdaCapture.h" +#include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/Redeclarable.h" +#include "clang/AST/Stmt.h" +#include "clang/AST/TemplateBase.h" +#include "clang/AST/Type.h" +#include "clang/AST/UnresolvedSet.h" +#include "clang/Basic/AttrKinds.h" +#include "clang/Basic/ExceptionSpecificationType.h" +#include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/Lambda.h" +#include "clang/Basic/LangOptions.h" +#include "clang/Basic/Linkage.h" +#include "clang/Basic/Module.h" +#include "clang/Basic/PragmaKinds.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/Specifiers.h" #include "clang/Sema/IdentifierResolver.h" #include "clang/Sema/SemaDiagnostic.h" +#include "clang/Serialization/ASTBitCodes.h" #include "clang/Serialization/ASTReader.h" +#include "clang/Serialization/ContinuousRangeMap.h" +#include "clang/Serialization/Module.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/FoldingSet.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/Bitcode/BitstreamReader.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/SaveAndRestore.h" +#include +#include +#include +#include +#include +#include using namespace clang; -using namespace clang::serialization; +using namespace serialization; //===----------------------------------------------------------------------===// // Declaration deserialization //===----------------------------------------------------------------------===// namespace clang { + class ASTDeclReader : public DeclVisitor { ASTReader &Reader; ASTRecordReader &Record; ASTReader::RecordLocation Loc; const DeclID ThisDeclID; const SourceLocation ThisDeclLoc; - typedef ASTReader::RecordData RecordData; - TypeID TypeIDForTypeDecl; + + using RecordData = ASTReader::RecordData; + + TypeID TypeIDForTypeDecl = 0; unsigned AnonymousDeclNumber; - GlobalDeclID NamedDeclForTagDecl; - IdentifierInfo *TypedefNameForLinkage; + GlobalDeclID NamedDeclForTagDecl = 0; + IdentifierInfo *TypedefNameForLinkage = nullptr; - bool HasPendingBody; + bool HasPendingBody = false; ///\brief A flag to carry the information for a decl from the entity is /// used. We use it to delay the marking of the canonical decl as used until /// the entire declaration is deserialized and merged. - bool IsDeclMarkedUsed; + bool IsDeclMarkedUsed = false; uint64_t GetCurrentCursorOffset(); @@ -144,7 +191,7 @@ namespace clang { public: RedeclarableResult(Decl *MergeWith, GlobalDeclID FirstID, bool IsKeyDecl) - : MergeWith(MergeWith), FirstID(FirstID), IsKeyDecl(IsKeyDecl) {} + : MergeWith(MergeWith), FirstID(FirstID), IsKeyDecl(IsKeyDecl) {} /// \brief Retrieve the first ID. GlobalDeclID getFirstID() const { return FirstID; } @@ -164,19 +211,14 @@ namespace clang { /// if requested. class FindExistingResult { ASTReader &Reader; - NamedDecl *New; - NamedDecl *Existing; - bool AddResult; - - unsigned AnonymousDeclNumber; - IdentifierInfo *TypedefNameForLinkage; - - void operator=(FindExistingResult &&) = delete; + NamedDecl *New = nullptr; + NamedDecl *Existing = nullptr; + bool AddResult = false; + unsigned AnonymousDeclNumber = 0; + IdentifierInfo *TypedefNameForLinkage = nullptr; public: - FindExistingResult(ASTReader &Reader) - : Reader(Reader), New(nullptr), Existing(nullptr), AddResult(false), - AnonymousDeclNumber(0), TypedefNameForLinkage(nullptr) {} + FindExistingResult(ASTReader &Reader) : Reader(Reader) {} FindExistingResult(ASTReader &Reader, NamedDecl *New, NamedDecl *Existing, unsigned AnonymousDeclNumber, @@ -193,6 +235,7 @@ namespace clang { Other.AddResult = false; } + FindExistingResult &operator=(FindExistingResult &&) = delete; ~FindExistingResult(); /// \brief Suppress the addition of this result into the known set of @@ -213,11 +256,8 @@ namespace clang { ASTDeclReader(ASTReader &Reader, ASTRecordReader &Record, ASTReader::RecordLocation Loc, DeclID thisDeclID, SourceLocation ThisDeclLoc) - : Reader(Reader), Record(Record), Loc(Loc), - ThisDeclID(thisDeclID), ThisDeclLoc(ThisDeclLoc), - TypeIDForTypeDecl(0), NamedDeclForTagDecl(0), - TypedefNameForLinkage(nullptr), HasPendingBody(false), - IsDeclMarkedUsed(false) {} + : Reader(Reader), Record(Record), Loc(Loc), ThisDeclID(thisDeclID), + ThisDeclLoc(ThisDeclLoc) {} template static void AddLazySpecializations(T *D, @@ -271,7 +311,7 @@ namespace clang { void ReadFunctionDefinition(FunctionDecl *FD); void Visit(Decl *D); - void UpdateDecl(Decl *D, llvm::SmallVectorImpl&); + void UpdateDecl(Decl *D, SmallVectorImpl &); static void setNextObjCCategory(ObjCCategoryDecl *Cat, ObjCCategoryDecl *Next) { @@ -300,19 +340,23 @@ namespace clang { void VisitCXXRecordDecl(CXXRecordDecl *D) { VisitCXXRecordDeclImpl(D); } RedeclarableResult VisitClassTemplateSpecializationDeclImpl( ClassTemplateSpecializationDecl *D); + void VisitClassTemplateSpecializationDecl( ClassTemplateSpecializationDecl *D) { VisitClassTemplateSpecializationDeclImpl(D); } + void VisitClassTemplatePartialSpecializationDecl( ClassTemplatePartialSpecializationDecl *D); void VisitClassScopeFunctionSpecializationDecl( ClassScopeFunctionSpecializationDecl *D); RedeclarableResult VisitVarTemplateSpecializationDeclImpl(VarTemplateSpecializationDecl *D); + void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D) { VisitVarTemplateSpecializationDeclImpl(D); } + void VisitVarTemplatePartialSpecializationDecl( VarTemplatePartialSpecializationDecl *D); void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); @@ -402,18 +446,22 @@ namespace clang { void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D); void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D); }; -} // end namespace clang + +} // namespace clang namespace { + /// Iterator over the redeclarations of a declaration that have already /// been merged into the same redeclaration chain. template class MergedRedeclIterator { - DeclT *Start, *Canonical, *Current; + DeclT *Start; + DeclT *Canonical = nullptr; + DeclT *Current = nullptr; + public: - MergedRedeclIterator() : Current(nullptr) {} - MergedRedeclIterator(DeclT *Start) - : Start(Start), Canonical(nullptr), Current(Start) {} + MergedRedeclIterator() = default; + MergedRedeclIterator(DeclT *Start) : Start(Start), Current(Start) {} DeclT *operator*() { return Current; } @@ -438,7 +486,8 @@ public: return A.Current != B.Current; } }; -} // end anonymous namespace + +} // namespace template static llvm::iterator_range> @@ -472,10 +521,9 @@ void ASTDeclReader::Visit(Decl *D) { D->getCanonicalDecl()->Used |= IsDeclMarkedUsed; IsDeclMarkedUsed = false; - if (DeclaratorDecl *DD = dyn_cast(D)) { + if (auto *DD = dyn_cast(D)) { if (DD->DeclInfo) { - DeclaratorDecl::ExtInfo *Info = - DD->DeclInfo.get(); + auto *Info = DD->DeclInfo.get(); Info->TInfo = GetTypeSourceInfo(); } else { @@ -483,7 +531,7 @@ void ASTDeclReader::Visit(Decl *D) { } } - if (TypeDecl *TD = dyn_cast(D)) { + if (auto *TD = dyn_cast(D)) { // We have a fully initialized TypeDecl. Read its type now. TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull()); @@ -492,10 +540,10 @@ void ASTDeclReader::Visit(Decl *D) { if (NamedDeclForTagDecl) cast(D)->TypedefNameDeclOrQualifier = cast(Reader.GetDecl(NamedDeclForTagDecl)); - } else if (ObjCInterfaceDecl *ID = dyn_cast(D)) { + } else if (auto *ID = dyn_cast(D)) { // if we have a fully initialized TypeDecl, we can safely read its type now. ID->TypeForDecl = Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull(); - } else if (FunctionDecl *FD = dyn_cast(D)) { + } else if (auto *FD = dyn_cast(D)) { // FunctionDecl's body was written last after all other Stmts/Exprs. // We only read it if FD doesn't already have a body (e.g., from another // module). @@ -523,8 +571,8 @@ void ASTDeclReader::VisitDecl(Decl *D) { LexicalDCIDForTemplateParmDecl); D->setDeclContext(Reader.getContext().getTranslationUnitDecl()); } else { - DeclContext *SemaDC = ReadDeclAs(); - DeclContext *LexicalDC = ReadDeclAs(); + auto *SemaDC = ReadDeclAs(); + auto *LexicalDC = ReadDeclAs(); if (!LexicalDC) LexicalDC = SemaDC; DeclContext *MergedSemaDC = Reader.MergedDeclContexts.lookup(SemaDC); @@ -667,7 +715,7 @@ ASTDeclReader::RedeclarableResult ASTDeclReader::VisitTagDecl(TagDecl *TD) { case 0: break; case 1: { // ExtInfo - TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo(); + auto *Info = new (Reader.getContext()) TagDecl::ExtInfo(); ReadQualifierInfo(*Info); TD->TypedefNameDeclOrQualifier = Info; break; @@ -723,9 +771,8 @@ void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) { } } - if (EnumDecl *InstED = ReadDeclAs()) { - TemplateSpecializationKind TSK = - (TemplateSpecializationKind)Record.readInt(); + if (auto *InstED = ReadDeclAs()) { + auto TSK = (TemplateSpecializationKind)Record.readInt(); SourceLocation POI = ReadSourceLocation(); ED->setInstantiationOfMemberEnum(Reader.getContext(), InstED, TSK); ED->getMemberSpecializationInfo()->setPointOfInstantiation(POI); @@ -764,8 +811,7 @@ void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) { VisitValueDecl(DD); DD->setInnerLocStart(ReadSourceLocation()); if (Record.readInt()) { // hasExtInfo - DeclaratorDecl::ExtInfo *Info - = new (Reader.getContext()) DeclaratorDecl::ExtInfo(); + auto *Info = new (Reader.getContext()) DeclaratorDecl::ExtInfo(); ReadQualifierInfo(*Info); DD->DeclInfo = Info; } @@ -815,9 +861,8 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { FD->setDescribedFunctionTemplate(ReadDeclAs()); break; case FunctionDecl::TK_MemberSpecialization: { - FunctionDecl *InstFD = ReadDeclAs(); - TemplateSpecializationKind TSK = - (TemplateSpecializationKind)Record.readInt(); + auto *InstFD = ReadDeclAs(); + auto TSK = (TemplateSpecializationKind)Record.readInt(); SourceLocation POI = ReadSourceLocation(); FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK); FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); @@ -825,9 +870,8 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { break; } case FunctionDecl::TK_FunctionTemplateSpecialization: { - FunctionTemplateDecl *Template = ReadDeclAs(); - TemplateSpecializationKind TSK = - (TemplateSpecializationKind)Record.readInt(); + auto *Template = ReadDeclAs(); + auto TSK = (TemplateSpecializationKind)Record.readInt(); // Template arguments. SmallVector TemplArgs; @@ -840,7 +884,7 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { if (HasTemplateArgumentsAsWritten) { unsigned NumTemplateArgLocs = Record.readInt(); TemplArgLocs.reserve(NumTemplateArgLocs); - for (unsigned i=0; i != NumTemplateArgLocs; ++i) + for (unsigned i = 0; i != NumTemplateArgLocs; ++i) TemplArgLocs.push_back(Record.readTemplateArgumentLoc()); LAngleLoc = ReadSourceLocation(); @@ -853,7 +897,7 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { TemplateArgumentList *TemplArgList = TemplateArgumentList::CreateCopy(C, TemplArgs); TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc); - for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i) + for (unsigned i = 0, e = TemplArgLocs.size(); i != e; ++i) TemplArgsInfo.addArgument(TemplArgLocs[i]); FunctionTemplateSpecializationInfo *FTInfo = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK, @@ -866,7 +910,7 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { if (FD->isCanonicalDecl()) { // if canonical add to template's set. // The template that contains the specializations set. It's not safe to // use getCanonicalDecl on Template since it may still be initializing. - FunctionTemplateDecl *CanonTemplate = ReadDeclAs(); + auto *CanonTemplate = ReadDeclAs(); // Get the InsertPos by FindNodeOrInsertPos() instead of calling // InsertNode(FTInfo) directly to avoid the getASTContext() call in // FunctionTemplateSpecializationInfo's Profile(). @@ -988,7 +1032,7 @@ ObjCTypeParamList *ASTDeclReader::ReadObjCTypeParamList() { SmallVector typeParams; typeParams.reserve(numParams); for (unsigned i = 0; i != numParams; ++i) { - auto typeParam = ReadDeclAs(); + auto *typeParam = ReadDeclAs(); if (!typeParam) return nullptr; @@ -1086,7 +1130,6 @@ void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { void ASTDeclReader::ReadObjCDefinitionData( struct ObjCProtocolDecl::DefinitionData &Data) { - unsigned NumProtoRefs = Record.readInt(); SmallVector ProtoRefs; ProtoRefs.reserve(NumProtoRefs); @@ -1241,7 +1284,7 @@ void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) { FD->setBitWidth(BW); if (!FD->getDeclName()) { - if (FieldDecl *Tmpl = ReadDeclAs()) + if (auto *Tmpl = ReadDeclAs()) Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl); } mergeMergeable(FD); @@ -1288,7 +1331,7 @@ ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) { VD->NonParmVarDeclBits.PreviousDeclInSameBlockScope = Record.readInt(); VD->NonParmVarDeclBits.ImplicitParamKind = Record.readInt(); } - Linkage VarLinkage = Linkage(Record.readInt()); + auto VarLinkage = Linkage(Record.readInt()); VD->setCachedLinkage(VarLinkage); // Reconstruct the one piece of the IdentifierNamespace that we need. @@ -1324,9 +1367,8 @@ ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) { VD->setDescribedVarTemplate(ReadDeclAs()); break; case StaticDataMemberSpecialization: { // HasMemberSpecializationInfo. - VarDecl *Tmpl = ReadDeclAs(); - TemplateSpecializationKind TSK = - (TemplateSpecializationKind)Record.readInt(); + auto *Tmpl = ReadDeclAs(); + auto TSK = (TemplateSpecializationKind)Record.readInt(); SourceLocation POI = ReadSourceLocation(); Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI); mergeRedeclarable(VD, Redecl); @@ -1365,7 +1407,7 @@ void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { void ASTDeclReader::VisitDecompositionDecl(DecompositionDecl *DD) { VisitVarDecl(DD); - BindingDecl **BDs = DD->getTrailingObjects(); + auto **BDs = DD->getTrailingObjects(); for (unsigned I = 0; I != DD->NumBindings; ++I) BDs[I] = ReadDeclAs(); } @@ -1401,7 +1443,7 @@ void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) { SmallVector captures; captures.reserve(numCaptures); for (unsigned i = 0; i != numCaptures; ++i) { - VarDecl *decl = ReadDeclAs(); + auto *decl = ReadDeclAs(); unsigned flags = Record.readInt(); bool byRef = (flags & 1); bool nested = (flags & 2); @@ -1468,7 +1510,7 @@ void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { // Each module has its own anonymous namespace, which is disjoint from // any other module's anonymous namespaces, so don't attach the anonymous // namespace at all. - NamespaceDecl *Anon = cast(Reader.GetDecl(AnonNamespace)); + auto *Anon = cast(Reader.GetDecl(AnonNamespace)); if (!Record.isModule()) D->setAnonymousNamespace(Anon); } @@ -1491,7 +1533,7 @@ void ASTDeclReader::VisitUsingDecl(UsingDecl *D) { ReadDeclarationNameLoc(D->DNLoc, D->getDeclName()); D->FirstUsingShadow.setPointer(ReadDeclAs()); D->setTypename(Record.readInt()); - if (NamedDecl *Pattern = ReadDeclAs()) + if (auto *Pattern = ReadDeclAs()) Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern); mergeMergeable(D); } @@ -1499,7 +1541,7 @@ void ASTDeclReader::VisitUsingDecl(UsingDecl *D) { void ASTDeclReader::VisitUsingPackDecl(UsingPackDecl *D) { VisitNamedDecl(D); D->InstantiatedFrom = ReadDeclAs(); - NamedDecl **Expansions = D->getTrailingObjects(); + auto **Expansions = D->getTrailingObjects(); for (unsigned I = 0; I != D->NumExpansions; ++I) Expansions[I] = ReadDeclAs(); mergeMergeable(D); @@ -1511,7 +1553,7 @@ void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) { D->Underlying = ReadDeclAs(); D->IdentifierNamespace = Record.readInt(); D->UsingOrNextShadow = ReadDeclAs(); - UsingShadowDecl *Pattern = ReadDeclAs(); + auto *Pattern = ReadDeclAs(); if (Pattern) Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern); mergeRedeclarable(D, Redecl); @@ -1622,9 +1664,9 @@ void ASTDeclReader::ReadCXXDefinitionData( Data.FirstFriend = ReadDeclID(); if (Data.IsLambda) { - typedef LambdaCapture Capture; - CXXRecordDecl::LambdaDefinitionData &Lambda - = static_cast(Data); + using Capture = LambdaCapture; + + auto &Lambda = static_cast(Data); Lambda.Dependent = Record.readInt(); Lambda.IsGenericLambda = Record.readInt(); Lambda.CaptureDefault = Record.readInt(); @@ -1639,7 +1681,7 @@ void ASTDeclReader::ReadCXXDefinitionData( for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { SourceLocation Loc = ReadSourceLocation(); bool IsImplicit = Record.readInt(); - LambdaCaptureKind Kind = static_cast(Record.readInt()); + auto Kind = static_cast(Record.readInt()); switch (Kind) { case LCK_StarThis: case LCK_This: @@ -1648,7 +1690,7 @@ void ASTDeclReader::ReadCXXDefinitionData( break; case LCK_ByCopy: case LCK_ByRef: - VarDecl *Var = ReadDeclAs(); + auto *Var = ReadDeclAs(); SourceLocation EllipsisLoc = ReadSourceLocation(); *ToCapture++ = Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc); break; @@ -1834,7 +1876,7 @@ ASTDeclReader::VisitCXXRecordDeclImpl(CXXRecordDecl *D) { break; case CXXRecTemplate: { // Merged when we merge the template. - ClassTemplateDecl *Template = ReadDeclAs(); + auto *Template = ReadDeclAs(); D->TemplateOrInstantiation = Template; if (!Template->getTemplatedDecl()) { // We've not actually loaded the ClassTemplateDecl yet, because we're @@ -1848,9 +1890,8 @@ ASTDeclReader::VisitCXXRecordDeclImpl(CXXRecordDecl *D) { break; } case CXXRecMemberSpecialization: { - CXXRecordDecl *RD = ReadDeclAs(); - TemplateSpecializationKind TSK = - (TemplateSpecializationKind)Record.readInt(); + auto *RD = ReadDeclAs(); + auto TSK = (TemplateSpecializationKind)Record.readInt(); SourceLocation POI = ReadSourceLocation(); MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK); MSI->setPointOfInstantiation(POI); @@ -1894,7 +1935,7 @@ void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) { while (NumOverridenMethods--) { // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod, // MD may be initializing. - if (CXXMethodDecl *MD = ReadDeclAs()) + if (auto *MD = ReadDeclAs()) Reader.getContext().addOverriddenMethod(D, MD->getCanonicalDecl()); } } else { @@ -1939,7 +1980,7 @@ void ASTDeclReader::VisitImportDecl(ImportDecl *D) { VisitDecl(D); D->ImportedAndComplete.setPointer(readModule()); D->ImportedAndComplete.setInt(Record.readInt()); - SourceLocation *StoredLocs = D->getTrailingObjects(); + auto *StoredLocs = D->getTrailingObjects(); for (unsigned I = 0, N = Record.back(); I != N; ++I) StoredLocs[I] = ReadSourceLocation(); Record.skipInts(1); // The number of stored source locations. @@ -1982,7 +2023,7 @@ DeclID ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) { VisitNamedDecl(D); DeclID PatternID = ReadDeclID(); - NamedDecl *TemplatedDecl = cast_or_null(Reader.GetDecl(PatternID)); + auto *TemplatedDecl = cast_or_null(Reader.GetDecl(PatternID)); TemplateParameterList *TemplateParams = Record.readTemplateParameterList(); // FIXME handle associated constraints D->init(TemplatedDecl, TemplateParams); @@ -2006,8 +2047,7 @@ ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { // If this is the first declaration of the template, fill in the information // for the 'common' pointer. if (ThisDeclID == Redecl.getFirstID()) { - if (RedeclarableTemplateDecl *RTD - = ReadDeclAs()) { + if (auto *RTD = ReadDeclAs()) { assert(RTD->getKind() == D->getKind() && "InstantiatedFromMemberTemplate kind mismatch"); D->setInstantiatedFromMemberTemplate(RTD); @@ -2075,15 +2115,15 @@ ASTDeclReader::VisitClassTemplateSpecializationDeclImpl( ASTContext &C = Reader.getContext(); if (Decl *InstD = ReadDecl()) { - if (ClassTemplateDecl *CTD = dyn_cast(InstD)) { + if (auto *CTD = dyn_cast(InstD)) { D->SpecializedTemplate = CTD; } else { SmallVector TemplArgs; Record.readTemplateArgumentList(TemplArgs); TemplateArgumentList *ArgList = TemplateArgumentList::CreateCopy(C, TemplArgs); - ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS - = new (C) ClassTemplateSpecializationDecl:: + auto *PS = + new (C) ClassTemplateSpecializationDecl:: SpecializedPartialSpecialization(); PS->PartialSpecialization = cast(InstD); @@ -2100,12 +2140,11 @@ ASTDeclReader::VisitClassTemplateSpecializationDeclImpl( bool writtenAsCanonicalDecl = Record.readInt(); if (writtenAsCanonicalDecl) { - ClassTemplateDecl *CanonPattern = ReadDeclAs(); + auto *CanonPattern = ReadDeclAs(); if (D->isCanonicalDecl()) { // It's kept in the folding set. // Set this as, or find, the canonical declaration for this specialization ClassTemplateSpecializationDecl *CanonSpec; - if (ClassTemplatePartialSpecializationDecl *Partial = - dyn_cast(D)) { + if (auto *Partial = dyn_cast(D)) { CanonSpec = CanonPattern->getCommonPtr()->PartialSpecializations .GetOrInsertNode(Partial); } else { @@ -2131,8 +2170,8 @@ ASTDeclReader::VisitClassTemplateSpecializationDeclImpl( // Explicit info. if (TypeSourceInfo *TyInfo = GetTypeSourceInfo()) { - ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo - = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo; + auto *ExplicitInfo = + new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo; ExplicitInfo->TypeAsWritten = TyInfo; ExplicitInfo->ExternLoc = ReadSourceLocation(); ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(); @@ -2186,14 +2225,14 @@ ASTDeclReader::VisitVarTemplateSpecializationDeclImpl( ASTContext &C = Reader.getContext(); if (Decl *InstD = ReadDecl()) { - if (VarTemplateDecl *VTD = dyn_cast(InstD)) { + if (auto *VTD = dyn_cast(InstD)) { D->SpecializedTemplate = VTD; } else { SmallVector TemplArgs; Record.readTemplateArgumentList(TemplArgs); TemplateArgumentList *ArgList = TemplateArgumentList::CreateCopy( C, TemplArgs); - VarTemplateSpecializationDecl::SpecializedPartialSpecialization *PS = + auto *PS = new (C) VarTemplateSpecializationDecl::SpecializedPartialSpecialization(); PS->PartialSpecialization = @@ -2205,7 +2244,7 @@ ASTDeclReader::VisitVarTemplateSpecializationDeclImpl( // Explicit info. if (TypeSourceInfo *TyInfo = GetTypeSourceInfo()) { - VarTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo = + auto *ExplicitInfo = new (C) VarTemplateSpecializationDecl::ExplicitSpecializationInfo; ExplicitInfo->TypeAsWritten = TyInfo; ExplicitInfo->ExternLoc = ReadSourceLocation(); @@ -2222,11 +2261,10 @@ ASTDeclReader::VisitVarTemplateSpecializationDeclImpl( bool writtenAsCanonicalDecl = Record.readInt(); if (writtenAsCanonicalDecl) { - VarTemplateDecl *CanonPattern = ReadDeclAs(); + auto *CanonPattern = ReadDeclAs(); if (D->isCanonicalDecl()) { // It's kept in the folding set. // FIXME: If it's already present, merge it. - if (VarTemplatePartialSpecializationDecl *Partial = - dyn_cast(D)) { + if (auto *Partial = dyn_cast(D)) { CanonPattern->getCommonPtr()->PartialSpecializations .GetOrInsertNode(Partial); } else { @@ -2293,8 +2331,7 @@ void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { D->setDepth(Record.readInt()); D->setPosition(Record.readInt()); if (D->isExpandedParameterPack()) { - TemplateParameterList **Data = - D->getTrailingObjects(); + auto **Data = D->getTrailingObjects(); for (unsigned I = 0, N = D->getNumExpansionTemplateParameters(); I != N; ++I) Data[I] = Record.readTemplateParameterList(); @@ -2368,7 +2405,7 @@ ASTDeclReader::VisitRedeclarable(Redeclarable *D) { (void)ReadDecl(); } - T *FirstDecl = cast_or_null(Reader.GetDecl(FirstDeclID)); + auto *FirstDecl = cast_or_null(Reader.GetDecl(FirstDeclID)); if (FirstDecl != D) { // We delay loading of the redeclaration chain to avoid deeply nested calls. // We temporarily set the first (canonical) declaration as the previous one @@ -2378,7 +2415,7 @@ ASTDeclReader::VisitRedeclarable(Redeclarable *D) { D->First = FirstDecl->getCanonicalDecl(); } - T *DAsT = static_cast(D); + auto *DAsT = static_cast(D); // Note that we need to load local redeclarations of this decl and build a // decl chain for them. This must happen *after* we perform the preloading @@ -2404,7 +2441,7 @@ void ASTDeclReader::mergeRedeclarable(Redeclarable *DBase, if (!DBase->isFirstDecl()) return; - T *D = static_cast(DBase); + auto *D = static_cast(DBase); if (auto *Existing = Redecl.getKnownMergeTarget()) // We already know of an existing declaration we should merge with. @@ -2470,7 +2507,7 @@ template void ASTDeclReader::mergeRedeclarable(Redeclarable *DBase, T *Existing, RedeclarableResult &Redecl, DeclID TemplatePatternID) { - T *D = static_cast(DBase); + auto *D = static_cast(DBase); T *ExistingCanon = Existing->getCanonicalDecl(); T *DCanon = D->getCanonicalDecl(); if (ExistingCanon != DCanon) { @@ -2559,7 +2596,7 @@ void ASTDeclReader::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) { void ASTReader::ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs) { for (unsigned i = 0, e = Record.readInt(); i != e; ++i) { Attr *New = nullptr; - attr::Kind Kind = (attr::Kind)Record.readInt(); + auto Kind = (attr::Kind)Record.readInt(); SourceRange Range = Record.readSourceRange(); ASTContext &Context = getContext(); @@ -2585,7 +2622,6 @@ inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) { DeclsLoaded[Index] = D; } - /// \brief Determine whether the consumer will be interested in seeing /// this declaration (via HandleTopLevelDecl). /// @@ -2614,10 +2650,10 @@ static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody) { return true; if (isa(D) || isa(D)) return !D->getDeclContext()->isFunctionOrMethod(); - if (VarDecl *Var = dyn_cast(D)) + if (const auto *Var = dyn_cast(D)) return Var->isFileVarDecl() && Var->isThisDeclarationADefinition() == VarDecl::Definition; - if (FunctionDecl *Func = dyn_cast(D)) + if (const auto *Func = dyn_cast(D)) return Func->doesThisDeclarationHaveABody() || HasBody; if (auto *ES = D->getASTContext().getExternalSource()) @@ -2640,8 +2676,7 @@ ASTReader::DeclCursorForID(DeclID ID, SourceLocation &Loc) { } ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) { - ContinuousRangeMap::iterator I - = GlobalBitOffsetsMap.find(GlobalOffset); + auto I = GlobalBitOffsetsMap.find(GlobalOffset); assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map"); return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset); @@ -2661,19 +2696,19 @@ static bool isSameTemplateParameter(const NamedDecl *X, if (X->getKind() != Y->getKind()) return false; - if (const TemplateTypeParmDecl *TX = dyn_cast(X)) { - const TemplateTypeParmDecl *TY = cast(Y); + if (const auto *TX = dyn_cast(X)) { + const auto *TY = cast(Y); return TX->isParameterPack() == TY->isParameterPack(); } - if (const NonTypeTemplateParmDecl *TX = dyn_cast(X)) { - const NonTypeTemplateParmDecl *TY = cast(Y); + if (const auto *TX = dyn_cast(X)) { + const auto *TY = cast(Y); return TX->isParameterPack() == TY->isParameterPack() && TX->getASTContext().hasSameType(TX->getType(), TY->getType()); } - const TemplateTemplateParmDecl *TX = cast(X); - const TemplateTemplateParmDecl *TY = cast(Y); + const auto *TX = cast(X); + const auto *TY = cast(Y); return TX->isParameterPack() == TY->isParameterPack() && isSameTemplateParameterList(TX->getTemplateParameters(), TY->getTemplateParameters()); @@ -2793,8 +2828,8 @@ static bool isSameEntity(NamedDecl *X, NamedDecl *Y) { // Two typedefs refer to the same entity if they have the same underlying // type. - if (TypedefNameDecl *TypedefX = dyn_cast(X)) - if (TypedefNameDecl *TypedefY = dyn_cast(Y)) + if (const auto *TypedefX = dyn_cast(X)) + if (const auto *TypedefY = dyn_cast(Y)) return X->getASTContext().hasSameType(TypedefX->getUnderlyingType(), TypedefY->getUnderlyingType()); @@ -2813,8 +2848,8 @@ static bool isSameEntity(NamedDecl *X, NamedDecl *Y) { } // Compatible tags match. - if (TagDecl *TagX = dyn_cast(X)) { - TagDecl *TagY = cast(Y); + if (const auto *TagX = dyn_cast(X)) { + const auto *TagY = cast(Y); return (TagX->getTagKind() == TagY->getTagKind()) || ((TagX->getTagKind() == TTK_Struct || TagX->getTagKind() == TTK_Class || TagX->getTagKind() == TTK_Interface) && @@ -2825,10 +2860,10 @@ static bool isSameEntity(NamedDecl *X, NamedDecl *Y) { // Functions with the same type and linkage match. // FIXME: This needs to cope with merging of prototyped/non-prototyped // functions, etc. - if (FunctionDecl *FuncX = dyn_cast(X)) { - FunctionDecl *FuncY = cast(Y); - if (CXXConstructorDecl *CtorX = dyn_cast(X)) { - CXXConstructorDecl *CtorY = cast(Y); + if (const auto *FuncX = dyn_cast(X)) { + const auto *FuncY = cast(Y); + if (const auto *CtorX = dyn_cast(X)) { + const auto *CtorY = cast(Y); if (CtorX->getInheritedConstructor() && !isSameEntity(CtorX->getInheritedConstructor().getConstructor(), CtorY->getInheritedConstructor().getConstructor())) @@ -2870,8 +2905,8 @@ static bool isSameEntity(NamedDecl *X, NamedDecl *Y) { } // Variables with the same type and linkage match. - if (VarDecl *VarX = dyn_cast(X)) { - VarDecl *VarY = cast(Y); + if (const auto *VarX = dyn_cast(X)) { + const auto *VarY = cast(Y); if (VarX->getLinkageInternal() == VarY->getLinkageInternal()) { ASTContext &C = VarX->getASTContext(); if (C.hasSameType(VarX->getType(), VarY->getType())) @@ -2893,15 +2928,15 @@ static bool isSameEntity(NamedDecl *X, NamedDecl *Y) { } // Namespaces with the same name and inlinedness match. - if (NamespaceDecl *NamespaceX = dyn_cast(X)) { - NamespaceDecl *NamespaceY = cast(Y); + if (const auto *NamespaceX = dyn_cast(X)) { + const auto *NamespaceY = cast(Y); return NamespaceX->isInline() == NamespaceY->isInline(); } // Identical template names and kinds match if their template parameter lists // and patterns match. - if (TemplateDecl *TemplateX = dyn_cast(X)) { - TemplateDecl *TemplateY = cast(Y); + if (const auto *TemplateX = dyn_cast(X)) { + const auto *TemplateY = cast(Y); return isSameEntity(TemplateX->getTemplatedDecl(), TemplateY->getTemplatedDecl()) && isSameTemplateParameterList(TemplateX->getTemplateParameters(), @@ -2909,15 +2944,15 @@ static bool isSameEntity(NamedDecl *X, NamedDecl *Y) { } // Fields with the same name and the same type match. - if (FieldDecl *FDX = dyn_cast(X)) { - FieldDecl *FDY = cast(Y); + if (const auto *FDX = dyn_cast(X)) { + const auto *FDY = cast(Y); // FIXME: Also check the bitwidth is odr-equivalent, if any. return X->getASTContext().hasSameType(FDX->getType(), FDY->getType()); } // Indirect fields with the same target field match. - if (auto *IFDX = dyn_cast(X)) { - auto *IFDY = cast(Y); + if (const auto *IFDX = dyn_cast(X)) { + const auto *IFDY = cast(Y); return IFDX->getAnonField()->getCanonicalDecl() == IFDY->getAnonField()->getCanonicalDecl(); } @@ -2928,32 +2963,32 @@ static bool isSameEntity(NamedDecl *X, NamedDecl *Y) { return true; // Using shadow declarations with the same target match. - if (UsingShadowDecl *USX = dyn_cast(X)) { - UsingShadowDecl *USY = cast(Y); + if (const auto *USX = dyn_cast(X)) { + const auto *USY = cast(Y); return USX->getTargetDecl() == USY->getTargetDecl(); } // Using declarations with the same qualifier match. (We already know that // the name matches.) - if (auto *UX = dyn_cast(X)) { - auto *UY = cast(Y); + if (const auto *UX = dyn_cast(X)) { + const auto *UY = cast(Y); return isSameQualifier(UX->getQualifier(), UY->getQualifier()) && UX->hasTypename() == UY->hasTypename() && UX->isAccessDeclaration() == UY->isAccessDeclaration(); } - if (auto *UX = dyn_cast(X)) { - auto *UY = cast(Y); + if (const auto *UX = dyn_cast(X)) { + const auto *UY = cast(Y); return isSameQualifier(UX->getQualifier(), UY->getQualifier()) && UX->isAccessDeclaration() == UY->isAccessDeclaration(); } - if (auto *UX = dyn_cast(X)) + if (const auto *UX = dyn_cast(X)) return isSameQualifier( UX->getQualifier(), cast(Y)->getQualifier()); // Namespace alias definitions with the same target match. - if (auto *NAX = dyn_cast(X)) { - auto *NAY = cast(Y); + if (const auto *NAX = dyn_cast(X)) { + const auto *NAY = cast(Y); return NAX->getNamespace()->Equals(NAY->getNamespace()); } @@ -2964,10 +2999,10 @@ static bool isSameEntity(NamedDecl *X, NamedDecl *Y) { /// looking for declarations to merge. DeclContext *ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader, DeclContext *DC) { - if (NamespaceDecl *ND = dyn_cast(DC)) + if (auto *ND = dyn_cast(DC)) return ND->getOriginalNamespace(); - if (CXXRecordDecl *RD = dyn_cast(DC)) { + if (auto *RD = dyn_cast(DC)) { // Try to dig out the definition. auto *DD = RD->DefinitionData; if (!DD) @@ -2991,7 +3026,7 @@ DeclContext *ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader, return DD->Definition; } - if (EnumDecl *ED = dyn_cast(DC)) + if (auto *ED = dyn_cast(DC)) return ED->getASTContext().getLangOpts().CPlusPlus? ED->getDefinition() : nullptr; @@ -3134,12 +3169,10 @@ ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) { // cause additional lookups here. class UpToDateIdentifierRAII { IdentifierInfo *II; - bool WasOutToDate; + bool WasOutToDate = false; public: - explicit UpToDateIdentifierRAII(IdentifierInfo *II) - : II(II), WasOutToDate(false) - { + explicit UpToDateIdentifierRAII(IdentifierInfo *II) : II(II) { if (II) { WasOutToDate = II->isOutOfDate(); if (WasOutToDate) @@ -3192,6 +3225,7 @@ template Decl *ASTDeclReader::getMostRecentDeclImpl(Redeclarable *D) { return D->RedeclLink.getLatestNotUpdated(); } + Decl *ASTDeclReader::getMostRecentDeclImpl(...) { llvm_unreachable("getMostRecentDecl on non-redeclarable declaration"); } @@ -3222,12 +3256,13 @@ void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, } namespace clang { + template<> void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, Redeclarable *D, Decl *Previous, Decl *Canon) { - VarDecl *VD = static_cast(D); - VarDecl *PrevVD = cast(Previous); + auto *VD = static_cast(D); + auto *PrevVD = cast(Previous); D->RedeclLink.setPrevious(PrevVD); D->First = PrevVD->First; @@ -3249,8 +3284,8 @@ template<> void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, Redeclarable *D, Decl *Previous, Decl *Canon) { - FunctionDecl *FD = static_cast(D); - FunctionDecl *PrevFD = cast(Previous); + auto *FD = static_cast(D); + auto *PrevFD = cast(Previous); FD->RedeclLink.setPrevious(PrevFD); FD->First = PrevFD->First; @@ -3289,7 +3324,8 @@ void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, std::make_pair(Canon, IsUnresolved ? PrevFD : FD)); } } -} // end namespace clang + +} // namespace clang void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, ...) { llvm_unreachable("attachPreviousDecl on non-redeclarable declaration"); @@ -3358,7 +3394,7 @@ void ASTDeclReader::attachPreviousDecl(ASTReader &Reader, Decl *D, // If the declaration declares a template, it may inherit default arguments // from the previous declaration. - if (TemplateDecl *TD = dyn_cast(D)) + if (auto *TD = dyn_cast(D)) inheritDefaultTemplateArguments(Reader.getContext(), cast(Previous), TD); } @@ -3367,6 +3403,7 @@ template void ASTDeclReader::attachLatestDeclImpl(Redeclarable *D, Decl *Latest) { D->RedeclLink.setLatest(cast(Latest)); } + void ASTDeclReader::attachLatestDeclImpl(...) { llvm_unreachable("attachLatestDecl on non-redeclarable declaration"); } @@ -3388,6 +3425,7 @@ template void ASTDeclReader::markIncompleteDeclChainImpl(Redeclarable *D) { D->RedeclLink.markIncomplete(); } + void ASTDeclReader::markIncompleteDeclChainImpl(...) { llvm_unreachable("markIncompleteDeclChain on non-redeclarable declaration"); } @@ -3671,7 +3709,7 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) { // If this declaration is also a declaration context, get the // offsets for its tables of lexical and visible declarations. - if (DeclContext *DC = dyn_cast(D)) { + if (auto *DC = dyn_cast(D)) { std::pair Offsets = Reader.VisitDeclContext(DC); if (Offsets.first && ReadLexicalDeclContextStorage(*Loc.F, DeclsCursor, Offsets.first, DC)) @@ -3687,7 +3725,7 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) { PendingUpdateRecord(ID, D, /*JustLoaded=*/true)); // Load the categories after recursive loading is finished. - if (ObjCInterfaceDecl *Class = dyn_cast(D)) + if (auto *Class = dyn_cast(D)) // If we already have a definition when deserializing the ObjCInterfaceDecl, // we put the Decl in PendingDefinitions so we can pull the categories here. if (Class->isThisDeclarationADefinition() || @@ -3738,7 +3776,7 @@ void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) { ProcessingUpdatesRAIIObj ProcessingUpdates(*this); DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID); - llvm::SmallVector PendingLazySpecializationIDs; + SmallVector PendingLazySpecializationIDs; if (UpdI != DeclUpdateOffsets.end()) { auto UpdateOffsets = std::move(UpdI->second); @@ -3795,7 +3833,7 @@ void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) { PendingVisibleUpdates.erase(I); auto *DC = cast(D)->getPrimaryContext(); - for (const PendingVisibleUpdate &Update : VisibleUpdates) + for (const auto &Update : VisibleUpdates) Lookups[DC].Table.add( Update.Mod, Update.Data, reader::ASTDeclContextNameLookupTrait(*this, *Update.Mod)); @@ -3844,13 +3882,14 @@ void ASTReader::loadPendingDeclChain(Decl *FirstLocal, uint64_t LocalOffset) { } namespace { + /// \brief Given an ObjC interface, goes through the modules and links to the /// interface all the categories for it. class ObjCCategoriesVisitor { ASTReader &Reader; ObjCInterfaceDecl *Interface; llvm::SmallPtrSetImpl &Deserialized; - ObjCCategoryDecl *Tail; + ObjCCategoryDecl *Tail = nullptr; llvm::DenseMap NameCategoryMap; serialization::GlobalDeclID InterfaceID; unsigned PreviousGeneration; @@ -3900,10 +3939,8 @@ namespace { llvm::SmallPtrSetImpl &Deserialized, serialization::GlobalDeclID InterfaceID, unsigned PreviousGeneration) - : Reader(Reader), Interface(Interface), Deserialized(Deserialized), - Tail(nullptr), InterfaceID(InterfaceID), - PreviousGeneration(PreviousGeneration) - { + : Reader(Reader), Interface(Interface), Deserialized(Deserialized), + InterfaceID(InterfaceID), PreviousGeneration(PreviousGeneration) { // Populate the name -> category map with the set of known categories. for (auto *Cat : Interface->known_categories()) { if (Cat->getDeclName()) @@ -3952,7 +3989,8 @@ namespace { return true; } }; -} // end anonymous namespace + +} // namespace void ASTReader::loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D, @@ -4005,13 +4043,13 @@ void ASTDeclReader::UpdateDecl(Decl *D, break; case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: { - NamespaceDecl *Anon = ReadDeclAs(); + auto *Anon = ReadDeclAs(); // Each module has its own anonymous namespace, which is disjoint from // any other module's anonymous namespaces, so don't attach the anonymous // namespace at all. if (!Record.isModule()) { - if (TranslationUnitDecl *TU = dyn_cast(D)) + if (auto *TU = dyn_cast(D)) TU->setAnonymousNamespace(Anon); else cast(D)->setAnonymousNamespace(Anon); @@ -4020,7 +4058,7 @@ void ASTDeclReader::UpdateDecl(Decl *D, } case UPD_CXX_ADDED_VAR_DEFINITION: { - VarDecl *VD = cast(D); + auto *VD = cast(D); VD->NonParmVarDeclBits.IsInline = Record.readInt(); VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt(); uint64_t Val = Record.readInt(); @@ -4037,8 +4075,7 @@ void ASTDeclReader::UpdateDecl(Decl *D, case UPD_CXX_POINT_OF_INSTANTIATION: { SourceLocation POI = Record.readSourceLocation(); - if (VarTemplateSpecializationDecl *VTSD = - dyn_cast(D)) { + if (auto *VTSD = dyn_cast(D)) { VTSD->setPointOfInstantiation(POI); } else if (auto *VD = dyn_cast(D)) { VD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); @@ -4055,12 +4092,12 @@ void ASTDeclReader::UpdateDecl(Decl *D, } case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: { - auto Param = cast(D); + auto *Param = cast(D); // We have to read the default argument regardless of whether we use it // so that hypothetical further update records aren't messed up. // TODO: Add a function to skip over the next expr record. - auto DefaultArg = Record.readExpr(); + auto *DefaultArg = Record.readExpr(); // Only apply the update if the parameter still has an uninstantiated // default argument. @@ -4070,8 +4107,8 @@ void ASTDeclReader::UpdateDecl(Decl *D, } case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER: { - auto FD = cast(D); - auto DefaultInit = Record.readExpr(); + auto *FD = cast(D); + auto *DefaultInit = Record.readExpr(); // Only apply the update if the field still has an uninstantiated // default member initializer. @@ -4087,7 +4124,7 @@ void ASTDeclReader::UpdateDecl(Decl *D, } case UPD_CXX_ADDED_FUNCTION_DEFINITION: { - FunctionDecl *FD = cast(D); + auto *FD = cast(D); if (Reader.PendingBodies[FD]) { // FIXME: Maybe check for ODR violations. // It's safe to stop now because this update record is always last. @@ -4133,13 +4170,12 @@ void ASTDeclReader::UpdateDecl(Decl *D, MSInfo->setTemplateSpecializationKind(TSK); MSInfo->setPointOfInstantiation(POI); } else { - ClassTemplateSpecializationDecl *Spec = - cast(RD); + auto *Spec = cast(RD); Spec->setTemplateSpecializationKind(TSK); Spec->setPointOfInstantiation(POI); if (Record.readInt()) { - auto PartialSpec = + auto *PartialSpec = ReadDeclAs(); SmallVector TemplArgs; Record.readTemplateArgumentList(TemplArgs); @@ -4212,18 +4248,17 @@ void ASTDeclReader::UpdateDecl(Decl *D, QualType DeducedResultType = Record.readType(); for (auto *Redecl : merged_redecls(D)) { // FIXME: If the return type is already deduced, check that it matches. - FunctionDecl *FD = cast(Redecl); + auto *FD = cast(Redecl); Reader.getContext().adjustDeducedFunctionResultType(FD, DeducedResultType); } break; } - case UPD_DECL_MARKED_USED: { + case UPD_DECL_MARKED_USED: // Maintain AST consistency: any later redeclarations are used too. D->markUsed(Reader.getContext()); break; - } case UPD_MANGLING_NUMBER: Reader.getContext().setManglingNumber(cast(D), diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index a1ae6a4..8b07940 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -1,4 +1,4 @@ -//===--- ASTReaderStmt.cpp - Stmt/Expr Deserialization ----------*- C++ -*-===// +//===- ASTReaderStmt.cpp - Stmt/Expr Deserialization ----------------------===// // // The LLVM Compiler Infrastructure // @@ -14,13 +14,55 @@ #include "clang/Serialization/ASTReader.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/AttrIterator.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclAccessPair.h" #include "clang/AST/DeclCXX.h" +#include "clang/AST/DeclGroup.h" +#include "clang/AST/DeclObjC.h" #include "clang/AST/DeclTemplate.h" +#include "clang/AST/DeclarationName.h" +#include "clang/AST/Expr.h" +#include "clang/AST/ExprCXX.h" +#include "clang/AST/ExprObjC.h" +#include "clang/AST/ExprOpenMP.h" +#include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/OpenMPClause.h" +#include "clang/AST/OperationKinds.h" +#include "clang/AST/Stmt.h" +#include "clang/AST/StmtCXX.h" +#include "clang/AST/StmtObjC.h" +#include "clang/AST/StmtOpenMP.h" #include "clang/AST/StmtVisitor.h" +#include "clang/AST/TemplateBase.h" +#include "clang/AST/Type.h" +#include "clang/AST/UnresolvedSet.h" +#include "clang/Basic/CapturedStmt.h" +#include "clang/Basic/ExpressionTraits.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/Lambda.h" +#include "clang/Basic/LangOptions.h" +#include "clang/Basic/OpenMPKinds.h" +#include "clang/Basic/OperatorKinds.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/Specifiers.h" +#include "clang/Basic/TypeTraits.h" #include "clang/Lex/Token.h" +#include "clang/Serialization/ASTBitCodes.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Bitcode/BitstreamReader.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/ErrorHandling.h" +#include +#include +#include +#include + using namespace clang; -using namespace clang::serialization; +using namespace serialization; namespace clang { @@ -80,6 +122,7 @@ namespace clang { void ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo &Args, TemplateArgumentLoc *ArgsLocArray, unsigned NumTemplateArgs); + /// \brief Read and initialize a ExplicitTemplateArgumentList structure. void ReadExplicitTemplateArgumentList(ASTTemplateArgumentListInfo &ArgList, unsigned NumTemplateArgs); @@ -89,7 +132,8 @@ namespace clang { void Visit##Type(Type *); #include "clang/AST/StmtNodes.inc" }; -} + +} // namespace clang void ASTStmtReader::ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo &Args, TemplateArgumentLoc *ArgsLocArray, @@ -146,7 +190,7 @@ void ASTStmtReader::VisitDefaultStmt(DefaultStmt *S) { void ASTStmtReader::VisitLabelStmt(LabelStmt *S) { VisitStmt(S); - LabelDecl *LD = ReadDeclAs(); + auto *LD = ReadDeclAs(); LD->setStmt(S); S->setDecl(LD); S->setSubStmt(Record.readSubStmt()); @@ -508,8 +552,7 @@ void ASTStmtReader::VisitStringLiteral(StringLiteral *E) { assert(Record.peekInt() == E->getNumConcatenated() && "Wrong number of concatenated tokens!"); Record.skipInts(1); - StringLiteral::StringKind kind = - static_cast(Record.readInt()); + auto kind = static_cast(Record.readInt()); bool isPascal = Record.readInt(); // Read string data @@ -550,13 +593,13 @@ void ASTStmtReader::VisitParenListExpr(ParenListExpr *E) { void ASTStmtReader::VisitUnaryOperator(UnaryOperator *E) { VisitExpr(E); - E->setSubExpr(Record.readSubExpr()); - E->setOpcode((UnaryOperator::Opcode)Record.readInt()); - E->setOperatorLoc(ReadSourceLocation()); - E->setCanOverflow(Record.readInt()); -} - -void ASTStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) { + E->setSubExpr(Record.readSubExpr()); + E->setOpcode((UnaryOperator::Opcode)Record.readInt()); + E->setOperatorLoc(ReadSourceLocation()); + E->setCanOverflow(Record.readInt()); +} + +void ASTStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) { VisitExpr(E); assert(E->getNumComponents() == Record.peekInt()); Record.skipInts(1); @@ -566,7 +609,7 @@ void ASTStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) { E->setRParenLoc(ReadSourceLocation()); E->setTypeSourceInfo(GetTypeSourceInfo()); for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { - OffsetOfNode::Kind Kind = static_cast(Record.readInt()); + auto Kind = static_cast(Record.readInt()); SourceLocation Start = ReadSourceLocation(); SourceLocation End = ReadSourceLocation(); switch (Kind) { @@ -586,7 +629,7 @@ void ASTStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) { break; case OffsetOfNode::Base: { - CXXBaseSpecifier *Base = new (Record.getContext()) CXXBaseSpecifier(); + auto *Base = new (Record.getContext()) CXXBaseSpecifier(); *Base = Record.readCXXBaseSpecifier(); E->setComponent(I, OffsetOfNode(Base)); break; @@ -676,7 +719,7 @@ void ASTStmtReader::VisitCastExpr(CastExpr *E) { E->setCastKind((CastKind)Record.readInt()); CastExpr::path_iterator BaseI = E->path_begin(); while (NumBaseSpecs--) { - CXXBaseSpecifier *BaseSpec = new (Record.getContext()) CXXBaseSpecifier; + auto *BaseSpec = new (Record.getContext()) CXXBaseSpecifier; *BaseSpec = Record.readCXXBaseSpecifier(); *BaseI++ = BaseSpec; } @@ -750,7 +793,7 @@ void ASTStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) { void ASTStmtReader::VisitInitListExpr(InitListExpr *E) { VisitExpr(E); - if (InitListExpr *SyntForm = cast_or_null(Record.readSubStmt())) + if (auto *SyntForm = cast_or_null(Record.readSubStmt())) E->setSyntacticForm(SyntForm); E->setLBraceLoc(ReadSourceLocation()); E->setRBraceLoc(ReadSourceLocation()); @@ -776,7 +819,7 @@ void ASTStmtReader::VisitInitListExpr(InitListExpr *E) { } void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) { - typedef DesignatedInitExpr::Designator Designator; + using Designator = DesignatedInitExpr::Designator; VisitExpr(E); unsigned NumSubExprs = Record.readInt(); @@ -790,7 +833,7 @@ void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) { while (Record.getIdx() < Record.size()) { switch ((DesignatorTypes)Record.readInt()) { case DESIG_FIELD_DECL: { - FieldDecl *Field = ReadDeclAs(); + auto *Field = ReadDeclAs(); SourceLocation DotLoc = ReadSourceLocation(); SourceLocation FieldLoc = ReadSourceLocation(); Designators.push_back(Designator(Field->getIdentifier(), DotLoc, @@ -995,9 +1038,9 @@ void ASTStmtReader::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) { assert(NumElements == E->getNumElements() && "Wrong number of elements"); bool HasPackExpansions = Record.readInt(); assert(HasPackExpansions == E->HasPackExpansions &&"Pack expansion mismatch"); - ObjCDictionaryLiteral::KeyValuePair *KeyValues = + auto *KeyValues = E->getTrailingObjects(); - ObjCDictionaryLiteral::ExpansionData *Expansions = + auto *Expansions = E->getTrailingObjects(); for (unsigned I = 0; I != NumElements; ++I) { KeyValues[I].Key = Record.readSubExpr(); @@ -1048,8 +1091,8 @@ void ASTStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { unsigned MethodRefFlags = Record.readInt(); bool Implicit = Record.readInt() != 0; if (Implicit) { - ObjCMethodDecl *Getter = ReadDeclAs(); - ObjCMethodDecl *Setter = ReadDeclAs(); + auto *Getter = ReadDeclAs(); + auto *Setter = ReadDeclAs(); E->setImplicitProperty(Getter, Setter, MethodRefFlags); } else { E->setExplicitProperty(ReadDeclAs(), MethodRefFlags); @@ -1086,8 +1129,7 @@ void ASTStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) { E->SelLocsKind = Record.readInt(); E->setDelegateInitCall(Record.readInt()); E->IsImplicit = Record.readInt(); - ObjCMessageExpr::ReceiverKind Kind - = static_cast(Record.readInt()); + auto Kind = static_cast(Record.readInt()); switch (Kind) { case ObjCMessageExpr::Instance: E->setInstanceReceiver(Record.readSubExpr()); @@ -1521,8 +1563,8 @@ void ASTStmtReader::VisitOverloadExpr(OverloadExpr *E) { unsigned NumDecls = Record.readInt(); UnresolvedSet<8> Decls; for (unsigned i = 0; i != NumDecls; ++i) { - NamedDecl *D = ReadDeclAs(); - AccessSpecifier AS = (AccessSpecifier)Record.readInt(); + auto *D = ReadDeclAs(); + auto AS = (AccessSpecifier)Record.readInt(); Decls.addDecl(D, AS); } E->initializeResults(Record.getContext(), Decls.begin(), Decls.end()); @@ -1556,7 +1598,7 @@ void ASTStmtReader::VisitTypeTraitExpr(TypeTraitExpr *E) { E->Loc = Range.getBegin(); E->RParenLoc = Range.getEnd(); - TypeSourceInfo **Args = E->getTrailingObjects(); + auto **Args = E->getTrailingObjects(); for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) Args[I] = GetTypeSourceInfo(); } @@ -1640,7 +1682,7 @@ void ASTStmtReader::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) { E->NumParameters = Record.readInt(); E->ParamPack = ReadDeclAs(); E->NameLoc = ReadSourceLocation(); - ParmVarDecl **Parms = E->getTrailingObjects(); + auto **Parms = E->getTrailingObjects(); for (unsigned i = 0, n = E->NumParameters; i != n; ++i) Parms[i] = ReadDeclAs(); } @@ -1648,7 +1690,7 @@ void ASTStmtReader::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) { void ASTStmtReader::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { VisitExpr(E); E->State = Record.readSubExpr(); - auto VD = ReadDeclAs(); + auto *VD = ReadDeclAs(); unsigned ManglingNumber = Record.readInt(); E->setExtendingDecl(VD, ManglingNumber); } @@ -1758,19 +1800,23 @@ void ASTStmtReader::VisitAsTypeExpr(AsTypeExpr *E) { //===----------------------------------------------------------------------===// namespace clang { + class OMPClauseReader : public OMPClauseVisitor { ASTStmtReader *Reader; ASTContext &Context; + public: OMPClauseReader(ASTStmtReader *R, ASTRecordReader &Record) : Reader(R), Context(Record.getContext()) {} + #define OPENMP_CLAUSE(Name, Class) void Visit##Class(Class *C); #include "clang/Basic/OpenMPKinds.def" OMPClause *readClause(); void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C); void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C); }; -} + +} // namespace clang OMPClause *OMPClauseReader::readClause() { OMPClause *C; @@ -2395,7 +2441,7 @@ void OMPClauseReader::VisitOMPMapClause(OMPMapClause *C) { Components.reserve(TotalComponents); for (unsigned i = 0; i < TotalComponents; ++i) { Expr *AssociatedExpr = Reader->Record.readSubExpr(); - ValueDecl *AssociatedDecl = Reader->Record.readDeclAs(); + auto *AssociatedDecl = Reader->Record.readDeclAs(); Components.push_back(OMPClauseMappableExprCommon::MappableComponent( AssociatedExpr, AssociatedDecl)); } @@ -2489,7 +2535,7 @@ void OMPClauseReader::VisitOMPToClause(OMPToClause *C) { Components.reserve(TotalComponents); for (unsigned i = 0; i < TotalComponents; ++i) { Expr *AssociatedExpr = Reader->Record.readSubExpr(); - ValueDecl *AssociatedDecl = Reader->Record.readDeclAs(); + auto *AssociatedDecl = Reader->Record.readDeclAs(); Components.push_back(OMPClauseMappableExprCommon::MappableComponent( AssociatedExpr, AssociatedDecl)); } @@ -2531,7 +2577,7 @@ void OMPClauseReader::VisitOMPFromClause(OMPFromClause *C) { Components.reserve(TotalComponents); for (unsigned i = 0; i < TotalComponents; ++i) { Expr *AssociatedExpr = Reader->Record.readSubExpr(); - ValueDecl *AssociatedDecl = Reader->Record.readDeclAs(); + auto *AssociatedDecl = Reader->Record.readDeclAs(); Components.push_back(OMPClauseMappableExprCommon::MappableComponent( AssociatedExpr, AssociatedDecl)); } @@ -2581,7 +2627,7 @@ void OMPClauseReader::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *C) { Components.reserve(TotalComponents); for (unsigned i = 0; i < TotalComponents; ++i) { Expr *AssociatedExpr = Reader->Record.readSubExpr(); - ValueDecl *AssociatedDecl = Reader->Record.readDeclAs(); + auto *AssociatedDecl = Reader->Record.readDeclAs(); Components.push_back(OMPClauseMappableExprCommon::MappableComponent( AssociatedExpr, AssociatedDecl)); } @@ -2624,7 +2670,7 @@ void OMPClauseReader::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) { Components.reserve(TotalComponents); for (unsigned i = 0; i < TotalComponents; ++i) { Expr *AssociatedExpr = Reader->Record.readSubExpr(); - ValueDecl *AssociatedDecl = Reader->Record.readDeclAs(); + auto *AssociatedDecl = Reader->Record.readDeclAs(); Components.push_back(OMPClauseMappableExprCommon::MappableComponent( AssociatedExpr, AssociatedDecl)); } @@ -2634,6 +2680,7 @@ void OMPClauseReader::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) { //===----------------------------------------------------------------------===// // OpenMP Directives. //===----------------------------------------------------------------------===// + void ASTStmtReader::VisitOMPExecutableDirective(OMPExecutableDirective *E) { E->setLocStart(ReadSourceLocation()); E->setLocEnd(ReadSourceLocation()); @@ -2919,6 +2966,7 @@ void ASTStmtReader::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) { Record.skipInts(1); VisitOMPExecutableDirective(D); } + void ASTStmtReader::VisitOMPDistributeParallelForDirective( OMPDistributeParallelForDirective *D) { VisitOMPLoopDirective(D); @@ -3027,7 +3075,6 @@ Expr *ASTReader::ReadSubExpr() { // stack. Evaluation terminates when we see a STMT_STOP record, and // the single remaining expression on the stack is our result. Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { - ReadingKindTracker ReadingKind(Read_Stmt, *this); llvm::BitstreamCursor &Cursor = F.DeclsCursor; @@ -3256,15 +3303,15 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { bool HadMultipleCandidates = Record.readInt(); - NamedDecl *FoundD = Record.readDeclAs(); - AccessSpecifier AS = (AccessSpecifier)Record.readInt(); + auto *FoundD = Record.readDeclAs(); + auto AS = (AccessSpecifier)Record.readInt(); DeclAccessPair FoundDecl = DeclAccessPair::make(FoundD, AS); QualType T = Record.readType(); - ExprValueKind VK = static_cast(Record.readInt()); - ExprObjectKind OK = static_cast(Record.readInt()); + auto VK = static_cast(Record.readInt()); + auto OK = static_cast(Record.readInt()); Expr *Base = ReadSubExpr(); - ValueDecl *MemberD = Record.readDeclAs(); + auto *MemberD = Record.readDeclAs(); SourceLocation MemberLoc = Record.readSourceLocation(); DeclarationNameInfo MemberNameInfo(MemberD->getDeclName(), MemberLoc); bool IsArrow = Record.readInt(); @@ -3384,93 +3431,121 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { case EXPR_OBJC_STRING_LITERAL: S = new (Context) ObjCStringLiteral(Empty); break; + case EXPR_OBJC_BOXED_EXPRESSION: S = new (Context) ObjCBoxedExpr(Empty); break; + case EXPR_OBJC_ARRAY_LITERAL: S = ObjCArrayLiteral::CreateEmpty(Context, Record[ASTStmtReader::NumExprFields]); break; + case EXPR_OBJC_DICTIONARY_LITERAL: S = ObjCDictionaryLiteral::CreateEmpty(Context, Record[ASTStmtReader::NumExprFields], Record[ASTStmtReader::NumExprFields + 1]); break; + case EXPR_OBJC_ENCODE: S = new (Context) ObjCEncodeExpr(Empty); break; + case EXPR_OBJC_SELECTOR_EXPR: S = new (Context) ObjCSelectorExpr(Empty); break; + case EXPR_OBJC_PROTOCOL_EXPR: S = new (Context) ObjCProtocolExpr(Empty); break; + case EXPR_OBJC_IVAR_REF_EXPR: S = new (Context) ObjCIvarRefExpr(Empty); break; + case EXPR_OBJC_PROPERTY_REF_EXPR: S = new (Context) ObjCPropertyRefExpr(Empty); break; + case EXPR_OBJC_SUBSCRIPT_REF_EXPR: S = new (Context) ObjCSubscriptRefExpr(Empty); break; + case EXPR_OBJC_KVC_REF_EXPR: llvm_unreachable("mismatching AST file"); + case EXPR_OBJC_MESSAGE_EXPR: S = ObjCMessageExpr::CreateEmpty(Context, Record[ASTStmtReader::NumExprFields], Record[ASTStmtReader::NumExprFields + 1]); break; + case EXPR_OBJC_ISA: S = new (Context) ObjCIsaExpr(Empty); break; + case EXPR_OBJC_INDIRECT_COPY_RESTORE: S = new (Context) ObjCIndirectCopyRestoreExpr(Empty); break; + case EXPR_OBJC_BRIDGED_CAST: S = new (Context) ObjCBridgedCastExpr(Empty); break; + case STMT_OBJC_FOR_COLLECTION: S = new (Context) ObjCForCollectionStmt(Empty); break; + case STMT_OBJC_CATCH: S = new (Context) ObjCAtCatchStmt(Empty); break; + case STMT_OBJC_FINALLY: S = new (Context) ObjCAtFinallyStmt(Empty); break; + case STMT_OBJC_AT_TRY: S = ObjCAtTryStmt::CreateEmpty(Context, Record[ASTStmtReader::NumStmtFields], Record[ASTStmtReader::NumStmtFields + 1]); break; + case STMT_OBJC_AT_SYNCHRONIZED: S = new (Context) ObjCAtSynchronizedStmt(Empty); break; + case STMT_OBJC_AT_THROW: S = new (Context) ObjCAtThrowStmt(Empty); break; + case STMT_OBJC_AUTORELEASE_POOL: S = new (Context) ObjCAutoreleasePoolStmt(Empty); break; + case EXPR_OBJC_BOOL_LITERAL: S = new (Context) ObjCBoolLiteralExpr(Empty); break; + case EXPR_OBJC_AVAILABILITY_CHECK: S = new (Context) ObjCAvailabilityCheckExpr(Empty); break; + case STMT_SEH_LEAVE: S = new (Context) SEHLeaveStmt(Empty); break; + case STMT_SEH_EXCEPT: S = new (Context) SEHExceptStmt(Empty); break; + case STMT_SEH_FINALLY: S = new (Context) SEHFinallyStmt(Empty); break; + case STMT_SEH_TRY: S = new (Context) SEHTryStmt(Empty); break; + case STMT_CXX_CATCH: S = new (Context) CXXCatchStmt(Empty); break; @@ -3752,11 +3827,10 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { break; } - case STMT_OMP_TARGET_TEAMS_DIRECTIVE: { + case STMT_OMP_TARGET_TEAMS_DIRECTIVE: S = OMPTargetTeamsDirective::CreateEmpty( Context, Record[ASTStmtReader::NumStmtFields], Empty); break; - } case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE: { auto NumClauses = Record[ASTStmtReader::NumStmtFields]; @@ -3849,36 +3923,47 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { case EXPR_CXX_NULL_PTR_LITERAL: S = new (Context) CXXNullPtrLiteralExpr(Empty); break; + case EXPR_CXX_TYPEID_EXPR: S = new (Context) CXXTypeidExpr(Empty, true); break; + case EXPR_CXX_TYPEID_TYPE: S = new (Context) CXXTypeidExpr(Empty, false); break; + case EXPR_CXX_UUIDOF_EXPR: S = new (Context) CXXUuidofExpr(Empty, true); break; + case EXPR_CXX_PROPERTY_REF_EXPR: S = new (Context) MSPropertyRefExpr(Empty); break; + case EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR: S = new (Context) MSPropertySubscriptExpr(Empty); break; + case EXPR_CXX_UUIDOF_TYPE: S = new (Context) CXXUuidofExpr(Empty, false); break; + case EXPR_CXX_THIS: S = new (Context) CXXThisExpr(Empty); break; + case EXPR_CXX_THROW: S = new (Context) CXXThrowExpr(Empty); break; + case EXPR_CXX_DEFAULT_ARG: S = new (Context) CXXDefaultArgExpr(Empty); break; + case EXPR_CXX_DEFAULT_INIT: S = new (Context) CXXDefaultInitExpr(Empty); break; + case EXPR_CXX_BIND_TEMPORARY: S = new (Context) CXXBindTemporaryExpr(Empty); break; @@ -3886,12 +3971,15 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { case EXPR_CXX_SCALAR_VALUE_INIT: S = new (Context) CXXScalarValueInitExpr(Empty); break; + case EXPR_CXX_NEW: S = new (Context) CXXNewExpr(Empty); break; + case EXPR_CXX_DELETE: S = new (Context) CXXDeleteExpr(Empty); break; + case EXPR_CXX_PSEUDO_DESTRUCTOR: S = new (Context) CXXPseudoDestructorExpr(Empty); break; @@ -4035,7 +4123,6 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { case EXPR_DEPENDENT_COAWAIT: S = new (Context) DependentCoawaitExpr(Empty); break; - } // We hit a STMT_STOP, so we're done with this expression. diff --git a/clang/lib/Serialization/Module.cpp b/clang/lib/Serialization/Module.cpp index 5a44d26..f0ada80 100644 --- a/clang/lib/Serialization/Module.cpp +++ b/clang/lib/Serialization/Module.cpp @@ -1,4 +1,4 @@ -//===--- Module.cpp - Module description ------------------------*- C++ -*-===// +//===- Module.cpp - Module description ------------------------------------===// // // The LLVM Compiler Infrastructure // @@ -11,8 +11,12 @@ // been loaded from an AST file. // //===----------------------------------------------------------------------===// + #include "clang/Serialization/Module.h" #include "ASTReaderInternals.h" +#include "clang/Serialization/ContinuousRangeMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/raw_ostream.h" using namespace clang; @@ -32,7 +36,8 @@ dumpLocalRemap(StringRef Name, if (Map.begin() == Map.end()) return; - typedef ContinuousRangeMap MapType; + using MapType = ContinuousRangeMap; + llvm::errs() << " " << Name << ":\n"; for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); I != IEnd; ++I) {