From: Hubert Tong Date: Wed, 20 Jul 2016 01:05:31 +0000 (+0000) Subject: Revert r276069: MSVC bots not happy X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=06a1ffe84a23ff5d11dcf3f42ea024a6aee594bd;p=clang Revert r276069: MSVC bots not happy git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276074 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h index e70b29e53a..10ec5aa9fc 100644 --- a/include/clang/AST/DeclTemplate.h +++ b/include/clang/AST/DeclTemplate.h @@ -46,8 +46,7 @@ typedef llvm::PointerUnion3 { + : private llvm::TrailingObjects { /// The location of the 'template' keyword. SourceLocation TemplateLoc; @@ -57,36 +56,26 @@ class TemplateParameterList final /// The number of template parameters in this template /// parameter list. - unsigned NumParams : 30; + unsigned NumParams : 31; /// 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, - Expr *RequiresClause); + ArrayRef Params, SourceLocation RAngleLoc); public: - // FIXME: remove default argument for RequiresClause static TemplateParameterList *Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef Params, - SourceLocation RAngleLoc, - Expr *RequiresClause = nullptr); + SourceLocation RAngleLoc); /// \brief Iterates through the template parameters in this list. typedef NamedDecl** iterator; @@ -138,16 +127,6 @@ 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; } @@ -157,33 +136,36 @@ public: } friend TrailingObjects; - - template - friend class FixedSizeTemplateParameterListStorage; + template friend class FixedSizeTemplateParameterListStorage; }; -/// \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; +/// \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]; public: FixedSizeTemplateParameterListStorage(SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef Params, - SourceLocation RAngleLoc, - Expr *RequiresClause) - : FixedSizeStorageOwner( - (assert(N == Params.size()), - assert(HasRequiresClause == static_cast(RequiresClause)), - new (static_cast(&storage)) TemplateParameterList( - TemplateLoc, LAngleLoc, Params, RAngleLoc, RequiresClause))) {} + 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; } }; /// \brief A template argument list. @@ -371,11 +353,6 @@ 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/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 05b30a4cd6..e54c88fc05 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -651,10 +651,6 @@ 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(), @@ -664,8 +660,7 @@ ASTContext::getCanonicalTemplateTemplateParmDecl( TemplateParameterList::Create(*this, SourceLocation(), SourceLocation(), CanonParams, - SourceLocation(), - CanonRequiresClause)); + SourceLocation())); // Get the new insert position for the node we care about. Canonical = CanonTemplateTemplateParms.FindNodeOrInsertPos(ID, InsertPos); diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index 76b495f84d..bc1f9f96a0 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -2262,21 +2262,11 @@ 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()), - ToRequiresClause); + Importer.Import(Params->getRAngleLoc())); } TemplateArgument diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp index bcc8878eea..37943cdd5b 100644 --- a/lib/AST/DeclTemplate.cpp +++ b/lib/AST/DeclTemplate.cpp @@ -31,11 +31,9 @@ using namespace clang; TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef Params, - SourceLocation RAngleLoc, - Expr *RequiresClause) + SourceLocation RAngleLoc) : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc), - NumParams(Params.size()), ContainsUnexpandedParameterPack(false), - HasRequiresClause(static_cast(RequiresClause)) { + NumParams(Params.size()), ContainsUnexpandedParameterPack(false) { assert(this->NumParams == NumParams && "Too many template parameters"); for (unsigned Idx = 0; Idx < NumParams; ++Idx) { NamedDecl *P = Params[Idx]; @@ -54,21 +52,15 @@ 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, Expr *RequiresClause) { - void *Mem = C.Allocate(totalSizeToAlloc( - Params.size(), RequiresClause ? 1u : 0u), +TemplateParameterList *TemplateParameterList::Create( + const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, + ArrayRef Params, SourceLocation RAngleLoc) { + void *Mem = C.Allocate(totalSizeToAlloc(Params.size()), llvm::alignOf()); return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params, - RAngleLoc, RequiresClause); + RAngleLoc); } unsigned TemplateParameterList::getMinRequiredArguments() const { @@ -1177,7 +1169,7 @@ createMakeIntegerSeqParameterList(const ASTContext &C, DeclContext *DC) { // NamedDecl *P[2] = {T, N}; auto *TPL = TemplateParameterList::Create( - C, SourceLocation(), SourceLocation(), P, SourceLocation(), nullptr); + C, SourceLocation(), SourceLocation(), P, SourceLocation()); // template class IntSeq auto *TemplateTemplateParm = TemplateTemplateParmDecl::Create( @@ -1202,7 +1194,7 @@ createMakeIntegerSeqParameterList(const ASTContext &C, DeclContext *DC) { // template