From: Hubert Tong Date: Sat, 30 Jul 2016 22:33:34 +0000 (+0000) Subject: Reapply r276069 with workaround for MSVC 2013 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e4a0c0ec78ed24bd564276f9af5dff1233ad4094;p=platform%2Fupstream%2Fllvm.git Reapply r276069 with workaround for MSVC 2013 llvm-svn: 277286 --- diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 10ec5aa..35356e7 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -46,7 +46,8 @@ typedef llvm::PointerUnion3 { + : private llvm::TrailingObjects { /// The location of the 'template' keyword. SourceLocation TemplateLoc; @@ -56,26 +57,36 @@ class TemplateParameterList final /// The number of template parameters in this template /// parameter list. - unsigned NumParams : 31; + unsigned NumParams : 30; /// Whether this template parameter list contains an unexpanded parameter /// pack. unsigned ContainsUnexpandedParameterPack : 1; + /// Whether this template parameter list has an associated requires-clause + unsigned HasRequiresClause : 1; + protected: size_t numTrailingObjects(OverloadToken) const { return NumParams; } + size_t numTrailingObjects(OverloadToken) const { + return HasRequiresClause; + } + TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc, - ArrayRef Params, SourceLocation RAngleLoc); + ArrayRef Params, SourceLocation RAngleLoc, + Expr *RequiresClause); public: + // FIXME: remove default argument for RequiresClause static TemplateParameterList *Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef Params, - SourceLocation RAngleLoc); + SourceLocation RAngleLoc, + Expr *RequiresClause = nullptr); /// \brief Iterates through the template parameters in this list. typedef NamedDecl** iterator; @@ -127,6 +138,16 @@ public: return ContainsUnexpandedParameterPack; } + /// \brief The constraint-expression of the associated requires-clause. + Expr *getRequiresClause() { + return HasRequiresClause ? *getTrailingObjects() : nullptr; + } + + /// \brief The constraint-expression of the associated requires-clause. + const Expr *getRequiresClause() const { + return HasRequiresClause ? *getTrailingObjects() : nullptr; + } + SourceLocation getTemplateLoc() const { return TemplateLoc; } SourceLocation getLAngleLoc() const { return LAngleLoc; } SourceLocation getRAngleLoc() const { return RAngleLoc; } @@ -136,36 +157,37 @@ public: } friend TrailingObjects; - template friend class FixedSizeTemplateParameterListStorage; + + template + friend class FixedSizeTemplateParameterListStorage; + +public: + // FIXME: workaround for MSVC 2013; remove when no longer needed + using FixedSizeStorageOwner = TrailingObjects::FixedSizeStorageOwner; }; -/// \brief Stores a list of template parameters for a TemplateDecl and its -/// derived classes. Suitable for creating on the stack. -template class FixedSizeTemplateParameterListStorage { - // This is kinda ugly: TemplateParameterList usually gets allocated - // in a block of memory with NamedDecls appended to it. Here, to get - // it stack allocated, we include the params as a separate - // variable. After allocation, the TemplateParameterList object - // treats them as part of itself. - TemplateParameterList List; - NamedDecl *Params[N]; +/// \brief Stores a list of template parameters and the associated +/// requires-clause (if any) for a TemplateDecl and its derived classes. +/// Suitable for creating on the stack. +template +class FixedSizeTemplateParameterListStorage + : public TemplateParameterList::FixedSizeStorageOwner { + typename TemplateParameterList::FixedSizeStorage< + NamedDecl *, Expr *>::with_counts< + N, HasRequiresClause ? 1u : 0u + >::type storage; public: FixedSizeTemplateParameterListStorage(SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef Params, - SourceLocation RAngleLoc) - : List(TemplateLoc, LAngleLoc, Params, RAngleLoc) { - // Because we're doing an evil layout hack above, have some - // asserts, just to double-check everything is laid out like - // expected. - assert(sizeof(*this) == - TemplateParameterList::totalSizeToAlloc(N) && - "Object layout not as expected"); - assert(this->Params == List.getTrailingObjects() && - "Object layout not as expected"); - } - TemplateParameterList *get() { return &List; } + SourceLocation RAngleLoc, + Expr *RequiresClause) + : FixedSizeStorageOwner( + (assert(N == Params.size()), + assert(HasRequiresClause == static_cast(RequiresClause)), + new (static_cast(&storage)) TemplateParameterList( + TemplateLoc, LAngleLoc, Params, RAngleLoc, RequiresClause))) {} }; /// \brief A template argument list. @@ -353,6 +375,11 @@ public: return TemplateParams; } + /// Get the constraint-expression from the associated requires-clause (if any) + const Expr *getRequiresClause() const { + return TemplateParams ? TemplateParams->getRequiresClause() : nullptr; + } + /// Get the underlying, templated declaration. NamedDecl *getTemplatedDecl() const { return TemplatedDecl.getPointer(); } diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 0d6ad9d..2aa6a14 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -651,6 +651,10 @@ ASTContext::getCanonicalTemplateTemplateParmDecl( cast(*P))); } + assert(!TTP->getRequiresClause() && + "Unexpected requires-clause on template template-parameter"); + LLVM_CONSTEXPR Expr *const CanonRequiresClause = nullptr; + TemplateTemplateParmDecl *CanonTTP = TemplateTemplateParmDecl::Create(*this, getTranslationUnitDecl(), SourceLocation(), TTP->getDepth(), @@ -660,7 +664,8 @@ ASTContext::getCanonicalTemplateTemplateParmDecl( TemplateParameterList::Create(*this, SourceLocation(), SourceLocation(), CanonParams, - SourceLocation())); + SourceLocation(), + CanonRequiresClause)); // Get the new insert position for the node we care about. Canonical = CanonTemplateTemplateParms.FindNodeOrInsertPos(ID, InsertPos); diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index bc1f9f9..76b495f8 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -2262,11 +2262,21 @@ TemplateParameterList *ASTNodeImporter::ImportTemplateParameterList( ToParams.push_back(cast(To)); } + Expr *ToRequiresClause; + if (Expr *const R = Params->getRequiresClause()) { + ToRequiresClause = Importer.Import(R); + if (!ToRequiresClause) + return nullptr; + } else { + ToRequiresClause = nullptr; + } + return TemplateParameterList::Create(Importer.getToContext(), Importer.Import(Params->getTemplateLoc()), Importer.Import(Params->getLAngleLoc()), ToParams, - Importer.Import(Params->getRAngleLoc())); + Importer.Import(Params->getRAngleLoc()), + ToRequiresClause); } TemplateArgument diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 37943cd..bcc8878 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -31,9 +31,11 @@ using namespace clang; TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef Params, - SourceLocation RAngleLoc) + SourceLocation RAngleLoc, + Expr *RequiresClause) : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc), - NumParams(Params.size()), ContainsUnexpandedParameterPack(false) { + NumParams(Params.size()), ContainsUnexpandedParameterPack(false), + HasRequiresClause(static_cast(RequiresClause)) { assert(this->NumParams == NumParams && "Too many template parameters"); for (unsigned Idx = 0; Idx < NumParams; ++Idx) { NamedDecl *P = Params[Idx]; @@ -52,15 +54,21 @@ TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc, // template parameter list does too. } } + if (RequiresClause) { + *getTrailingObjects() = RequiresClause; + } } -TemplateParameterList *TemplateParameterList::Create( - const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, - ArrayRef Params, SourceLocation RAngleLoc) { - void *Mem = C.Allocate(totalSizeToAlloc(Params.size()), +TemplateParameterList * +TemplateParameterList::Create(const ASTContext &C, SourceLocation TemplateLoc, + SourceLocation LAngleLoc, + ArrayRef Params, + SourceLocation RAngleLoc, Expr *RequiresClause) { + void *Mem = C.Allocate(totalSizeToAlloc( + Params.size(), RequiresClause ? 1u : 0u), llvm::alignOf()); return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params, - RAngleLoc); + RAngleLoc, RequiresClause); } unsigned TemplateParameterList::getMinRequiredArguments() const { @@ -1169,7 +1177,7 @@ createMakeIntegerSeqParameterList(const ASTContext &C, DeclContext *DC) { // NamedDecl *P[2] = {T, N}; auto *TPL = TemplateParameterList::Create( - C, SourceLocation(), SourceLocation(), P, SourceLocation()); + C, SourceLocation(), SourceLocation(), P, SourceLocation(), nullptr); // template class IntSeq auto *TemplateTemplateParm = TemplateTemplateParmDecl::Create( @@ -1194,7 +1202,7 @@ createMakeIntegerSeqParameterList(const ASTContext &C, DeclContext *DC) { // template