[clang] 19fccc5 - [Concepts] Fix incorrect control flow when TryAnnotateTypeConstraint annotates an invalid template-id

2020-03-16 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-03-17T01:49:42+02:00
New Revision: 19fccc52ff2c1da1f93d9317c34769bd9bab8ac8

URL: 
https://github.com/llvm/llvm-project/commit/19fccc52ff2c1da1f93d9317c34769bd9bab8ac8
DIFF: 
https://github.com/llvm/llvm-project/commit/19fccc52ff2c1da1f93d9317c34769bd9bab8ac8.diff

LOG: [Concepts] Fix incorrect control flow when TryAnnotateTypeConstraint 
annotates an invalid template-id

TryAnnotateTypeConstraint could annotate a template-id which doesn't end up 
being a type-constraint,
in which case control flow would incorrectly flow into ParseImplicitInt.

Reenter the loop in this case.
Enable relevant tests for C++20. This required disabling typo-correction during 
TryAnnotateTypeConstraint
and changing a test case which is broken due to a separate bug (will be 
reported and handled separately).

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseTemplate.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/SemaCXX/invalid-member-expr.cpp
clang/test/SemaCXX/typo-correction.cpp
clang/test/SemaTemplate/ms-lookup-template-base-classes.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index fd58c00640b0..121ceb7e5d36 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -6986,7 +6986,8 @@ class Sema final {
   QualType ObjectType, bool EnteringContext,
   bool ,
   SourceLocation TemplateKWLoc = SourceLocation(),
-  AssumedTemplateKind *ATK = nullptr);
+  AssumedTemplateKind *ATK = nullptr,
+  bool Disambiguation = false);
 
   TemplateNameKind isTemplateName(Scope *S,
   CXXScopeSpec ,
@@ -6995,7 +6996,8 @@ class Sema final {
   ParsedType ObjectType,
   bool EnteringContext,
   TemplateTy ,
-  bool );
+  bool ,
+  bool Disambiguation = false);
 
   /// Try to resolve an undeclared template name as a type template.
   ///

diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 6356d82f2d46..09d1732739b8 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3253,6 +3253,9 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec ,
   goto DoneWithDeclSpec;
 if (isTypeConstraintAnnotation())
   continue;
+if (NextToken().is(tok::annot_template_id))
+  // Might have been annotated by TryAnnotateTypeConstraint.
+  continue;
 // Eat the scope spec so the identifier is current.
 ConsumeAnnotationToken();
 ParsedAttributesWithRange Attrs(AttrFactory);
@@ -3406,6 +3409,9 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec ,
   goto DoneWithDeclSpec;
 if (isTypeConstraintAnnotation())
   continue;
+if (Tok.is(tok::annot_template_id))
+  // Might have been annotated by TryAnnotateTypeConstraint.
+  continue;
 ParsedAttributesWithRange Attrs(AttrFactory);
 if (ParseImplicitInt(DS, nullptr, TemplateInfo, AS, DSContext, Attrs)) 
{
   if (!Attrs.empty()) {

diff  --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index 53c4829f43f4..0406820f74a3 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -710,7 +710,8 @@ bool Parser::TryAnnotateTypeConstraint() {
   /*ObjectType=*/ParsedType(),
   /*EnteringContext=*/false,
   PossibleConcept,
-  MemberOfUnknownSpecialization);
+  MemberOfUnknownSpecialization,
+  /*Disambiguation=*/true);
 if (MemberOfUnknownSpecialization || !PossibleConcept ||
 TNK != TNK_Concept_template) {
   if (SS.isNotEmpty())

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 4923d0a6dad2..1ba66d4a976a 100755
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -174,7 +174,8 @@ TemplateNameKind Sema::isTemplateName(Scope *S,
   ParsedType ObjectTypePtr,
   bool EnteringContext,
   TemplateTy ,
-  bool ) {
+  bool ,
+  bool Disambiguation) {
   assert(getLangOpts().CPlusPlus && "No template names in C!");
 
   DeclarationName TName;

[clang] 9769e1e - [Concepts] Fix incorrect DeclContext for transformed RequiresExprBodyDecl

2020-03-10 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-03-10T23:17:00+02:00
New Revision: 9769e1ee9acc33638449b50ac394b5ee2d4efb60

URL: 
https://github.com/llvm/llvm-project/commit/9769e1ee9acc33638449b50ac394b5ee2d4efb60
DIFF: 
https://github.com/llvm/llvm-project/commit/9769e1ee9acc33638449b50ac394b5ee2d4efb60.diff

LOG: [Concepts] Fix incorrect DeclContext for transformed RequiresExprBodyDecl

We would assign the incorrect DeclContext when transforming the 
RequiresExprBodyDecl, causing incorrect
handling of 'this' inside RequiresExprBodyDecls (bug #45162).

Assign the current context as the DeclContext of the transformed decl.

Added: 


Modified: 
clang/lib/Sema/TreeTransform.h
clang/test/SemaTemplate/instantiate-requires-expr.cpp

Removed: 




diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 002b73c3a1dd..0497a0df149a 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -11380,7 +11380,7 @@ 
TreeTransform::TransformRequiresExpr(RequiresExpr *E) {
   SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
 
   RequiresExprBodyDecl *Body = RequiresExprBodyDecl::Create(
-  getSema().Context, E->getBody()->getDeclContext(),
+  getSema().Context, getSema().CurContext,
   E->getBody()->getBeginLoc());
 
   Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);

diff  --git a/clang/test/SemaTemplate/instantiate-requires-expr.cpp 
b/clang/test/SemaTemplate/instantiate-requires-expr.cpp
index 927bc1bf8f12..ba82fc1313fc 100644
--- a/clang/test/SemaTemplate/instantiate-requires-expr.cpp
+++ b/clang/test/SemaTemplate/instantiate-requires-expr.cpp
@@ -164,6 +164,19 @@ namespace expr_requirement {
   struct r3 {};
 
   using r3i = r3; // expected-error{{constraints not 
satisfied for class template 'r3' [with Ts = ]}}
+
+  template
+  struct r4 {
+  constexpr int foo() {
+if constexpr (requires { this->invalid(); })
+  return 1;
+else
+  return 0;
+  }
+
+  constexpr void invalid() requires false { }
+  };
+  static_assert(r4{}.foo() == 0);
 }
 
 namespace nested_requirement {



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7fb562c - [Concepts] Add constraints checks to isSameEntity

2020-03-10 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-03-10T22:05:36+02:00
New Revision: 7fb562c1ab373a3d4e14003e40556791ec032bab

URL: 
https://github.com/llvm/llvm-project/commit/7fb562c1ab373a3d4e14003e40556791ec032bab
DIFF: 
https://github.com/llvm/llvm-project/commit/7fb562c1ab373a3d4e14003e40556791ec032bab.diff

LOG: [Concepts] Add constraints checks to isSameEntity

isSameEntity was missing constraints checking, causing constrained overloads
to not travel well accross serialization. (bug #45115)

Add constraints checking to isSameEntity.

Added: 
clang/test/PCH/cxx2a-constraints.cpp

Modified: 
clang/lib/Serialization/ASTReaderDecl.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 362d3eaebdd2..828f4a172b05 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -2870,7 +2870,8 @@ uint64_t ASTReader::getGlobalBitOffset(ModuleFile , 
uint32_t LocalOffset) {
   return LocalOffset + M.GlobalBitOffset;
 }
 
-static bool isSameTemplateParameterList(const TemplateParameterList *X,
+static bool isSameTemplateParameterList(const ASTContext ,
+const TemplateParameterList *X,
 const TemplateParameterList *Y);
 
 /// Determine whether two template parameters are similar enough
@@ -2882,7 +2883,32 @@ static bool isSameTemplateParameter(const NamedDecl *X,
 
   if (const auto *TX = dyn_cast(X)) {
 const auto *TY = cast(Y);
-return TX->isParameterPack() == TY->isParameterPack();
+if (TX->isParameterPack() != TY->isParameterPack())
+  return false;
+if (TX->hasTypeConstraint() != TY->hasTypeConstraint())
+  return false;
+if (TX->hasTypeConstraint()) {
+  const TypeConstraint *TXTC = TX->getTypeConstraint();
+  const TypeConstraint *TYTC = TY->getTypeConstraint();
+  if (TXTC->getNamedConcept() != TYTC->getNamedConcept())
+return false;
+  if (TXTC->hasExplicitTemplateArgs() != TYTC->hasExplicitTemplateArgs())
+return false;
+  if (TXTC->hasExplicitTemplateArgs()) {
+const auto *TXTCArgs = TXTC->getTemplateArgsAsWritten();
+const auto *TYTCArgs = TYTC->getTemplateArgsAsWritten();
+if (TXTCArgs->NumTemplateArgs != TYTCArgs->NumTemplateArgs)
+  return false;
+llvm::FoldingSetNodeID XID, YID;
+for (const auto  : TXTCArgs->arguments())
+  ArgLoc.getArgument().Profile(XID, X->getASTContext());
+for (const auto  : TYTCArgs->arguments())
+  ArgLoc.getArgument().Profile(YID, Y->getASTContext());
+if (XID != YID)
+  return false;
+  }
+}
+return true;
   }
 
   if (const auto *TX = dyn_cast(X)) {
@@ -2894,7 +2920,8 @@ static bool isSameTemplateParameter(const NamedDecl *X,
   const auto *TX = cast(X);
   const auto *TY = cast(Y);
   return TX->isParameterPack() == TY->isParameterPack() &&
- isSameTemplateParameterList(TX->getTemplateParameters(),
+ isSameTemplateParameterList(TX->getASTContext(),
+ TX->getTemplateParameters(),
  TY->getTemplateParameters());
 }
 
@@ -2947,7 +2974,8 @@ static bool isSameQualifier(const NestedNameSpecifier *X,
 
 /// Determine whether two template parameter lists are similar enough
 /// that they may be used in declarations of the same template.
-static bool isSameTemplateParameterList(const TemplateParameterList *X,
+static bool isSameTemplateParameterList(const ASTContext ,
+const TemplateParameterList *X,
 const TemplateParameterList *Y) {
   if (X->size() != Y->size())
 return false;
@@ -2956,6 +2984,18 @@ static bool isSameTemplateParameterList(const 
TemplateParameterList *X,
 if (!isSameTemplateParameter(X->getParam(I), Y->getParam(I)))
   return false;
 
+  const Expr *XRC = X->getRequiresClause();
+  const Expr *YRC = Y->getRequiresClause();
+  if (!XRC != !YRC)
+return false;
+  if (XRC) {
+llvm::FoldingSetNodeID XRCID, YRCID;
+XRC->Profile(XRCID, C, /*Canonical=*/true);
+YRC->Profile(YRCID, C, /*Canonical=*/true);
+if (XRCID != YRCID)
+  return false;
+  }
+
   return true;
 }
 
@@ -2992,7 +3032,7 @@ static bool hasSameOverloadableAttrs(const FunctionDecl 
*A,
   return true;
 }
 
-/// Determine whether the two declarations refer to the same entity.
+/// Determine whether the two declarations refer to the same entity.pr
 static bool isSameEntity(NamedDecl *X, NamedDecl *Y) {
   assert(X->getDeclName() == Y->getDeclName() && "Declaration name mismatch!");
 
@@ -3067,6 +3107,19 @@ static bool isSameEntity(NamedDecl *X, NamedDecl *Y) {
 }
 
 ASTContext  = FuncX->getASTContext();
+
+const Expr *XRC = FuncX->getTrailingRequiresClause();
+

[clang] f9e6389 - [Concepts] Add FoundDecl to ConceptSpecializationExpr serialization

2020-03-10 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-03-10T22:04:11+02:00
New Revision: f9e63891597630405a4655298f06b193e4ceb384

URL: 
https://github.com/llvm/llvm-project/commit/f9e63891597630405a4655298f06b193e4ceb384
DIFF: 
https://github.com/llvm/llvm-project/commit/f9e63891597630405a4655298f06b193e4ceb384.diff

LOG: [Concepts] Add FoundDecl to ConceptSpecializationExpr serialization

FoundDecl was missing from ConceptSpecializationExpr serialization - add it.

Added: 


Modified: 
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReaderStmt.cpp 
b/clang/lib/Serialization/ASTReaderStmt.cpp
index 42803b1a3918..975b7580d861 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -768,6 +768,7 @@ void ASTStmtReader::VisitConceptSpecializationExpr(
   E->TemplateKWLoc = Record.readSourceLocation();
   E->ConceptName = Record.readDeclarationNameInfo();
   E->NamedConcept = readDeclAs();
+  E->FoundDecl = Record.readDeclAs();
   E->ArgsAsWritten = Record.readASTTemplateArgumentListInfo();
   llvm::SmallVector Args;
   for (unsigned I = 0; I < NumTemplateArgs; ++I)

diff  --git a/clang/lib/Serialization/ASTWriterStmt.cpp 
b/clang/lib/Serialization/ASTWriterStmt.cpp
index d2b1fc2becf1..0aadeaa9a615 100644
--- a/clang/lib/Serialization/ASTWriterStmt.cpp
+++ b/clang/lib/Serialization/ASTWriterStmt.cpp
@@ -429,6 +429,7 @@ void ASTStmtWriter::VisitConceptSpecializationExpr(
   Record.AddSourceLocation(E->getTemplateKWLoc());
   Record.AddDeclarationNameInfo(E->getConceptNameInfo());
   Record.AddDeclRef(E->getNamedConcept());
+  Record.AddDeclRef(E->getFoundDecl());
   Record.AddASTTemplateArgumentListInfo(E->getTemplateArgsAsWritten());
   for (const TemplateArgument  : TemplateArgs)
 Record.AddTemplateArgument(Arg);



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 865456d - [Concepts] Add null check for TemplateTypeParmType::getDecl() in GetContainedInventedTypeParmVisitor

2020-03-06 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-03-06T19:32:10+02:00
New Revision: 865456d589e093582acaafd17d58ad1c0cce66af

URL: 
https://github.com/llvm/llvm-project/commit/865456d589e093582acaafd17d58ad1c0cce66af
DIFF: 
https://github.com/llvm/llvm-project/commit/865456d589e093582acaafd17d58ad1c0cce66af.diff

LOG: [Concepts] Add null check for TemplateTypeParmType::getDecl() in 
GetContainedInventedTypeParmVisitor

GetContainedInventedTypeParmVisitor would not account for the case where 
TemplateTypeParmType::getDecl() is
nullptr, causing bug #45102.

Add the nullptr check.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/SemaTemplate/instantiate-abbreviated-template.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 3ae2822a9803..b37b4bbba783 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2162,7 +2162,7 @@ namespace {
 // The deduced type itself.
 TemplateTypeParmDecl *VisitTemplateTypeParmType(
 const TemplateTypeParmType *T) {
-  if (!T->getDecl()->isImplicit())
+  if (!T->getDecl() || !T->getDecl()->isImplicit())
 return nullptr;
   return T->getDecl();
 }

diff  --git a/clang/test/SemaTemplate/instantiate-abbreviated-template.cpp 
b/clang/test/SemaTemplate/instantiate-abbreviated-template.cpp
index 99801115626f..1f2171a25ebb 100644
--- a/clang/test/SemaTemplate/instantiate-abbreviated-template.cpp
+++ b/clang/test/SemaTemplate/instantiate-abbreviated-template.cpp
@@ -31,3 +31,15 @@ struct G {
 
 using gf1 = decltype(G::foo1('a', 1, 2, 3, 4)); // 
expected-error{{no matching function}}
 using gf2 = decltype(G::foo2('a', 1, 2)); // expected-error{{no 
matching function}}
+
+
+// Regression (bug #45102): check that instantiation works where there is no
+// TemplateTypeParmDecl
+template  using id = T;
+
+template 
+constexpr void g() {
+  id f;
+}
+
+static_assert((g(), true));
\ No newline at end of file



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 271e495 - [Concepts] Add missing TPA commit to requires expression parsing

2020-02-12 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-02-12T16:26:34+02:00
New Revision: 271e495399170d69627c1acd591c9298cb0b5b4b

URL: 
https://github.com/llvm/llvm-project/commit/271e495399170d69627c1acd591c9298cb0b5b4b
DIFF: 
https://github.com/llvm/llvm-project/commit/271e495399170d69627c1acd591c9298cb0b5b4b.diff

LOG: [Concepts] Add missing TPA commit to requires expression parsing

If an error had occurred when annotating a scope spec during the tentative parse
for a type-requirement, we would not revert nor commit the tentative parse, 
triggerring
an assertion failure.

Commit the TPA in this case and then do error recovery.

Added: 


Modified: 
clang/lib/Parse/ParseExprCXX.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseExprCXX.cpp 
b/clang/lib/Parse/ParseExprCXX.cpp
index 617c2917d8ad..550bf7045425 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3486,6 +3486,7 @@ ExprResult Parser::ParseRequiresExpression() {
   // We need to consume the typename to allow 'requires { typename a; 
}'
   SourceLocation TypenameKWLoc = ConsumeToken();
   if (TryAnnotateCXXScopeToken()) {
+TPA.Commit();
 SkipUntil(tok::semi, tok::r_brace, 
SkipUntilFlags::StopBeforeMatch);
 break;
   }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5fef14d - [Concepts] Do not check constraints if not all template arguments have been deduced

2020-02-12 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-02-12T16:02:12+02:00
New Revision: 5fef14d932fe602bf998b8fb8a809ff85ca1e245

URL: 
https://github.com/llvm/llvm-project/commit/5fef14d932fe602bf998b8fb8a809ff85ca1e245
DIFF: 
https://github.com/llvm/llvm-project/commit/5fef14d932fe602bf998b8fb8a809ff85ca1e245.diff

LOG: [Concepts] Do not check constraints if not all template arguments have 
been deduced

We previously checked the constraints of instantiated function templates even 
in cases where
PartialOverloading was true and not all template arguments have been deduced, 
which caused crashes
in clangd (bug 44714).

We now check if all arguments have been deduced before checking constraints in 
partial overloading
scenarios.

Added: 
clang/test/CXX/temp/temp.deduct/p5.cpp

Modified: 
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 24019bf7975b..a0b92cdf3a5e 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3439,13 +3439,16 @@ Sema::TemplateDeductionResult 
Sema::FinishTemplateArgumentDeduction(
   //   ([temp.constr.decl]), those constraints are checked for satisfaction
   //   ([temp.constr.constr]). If the constraints are not satisfied, type
   //   deduction fails.
-  if (CheckInstantiatedFunctionTemplateConstraints(Info.getLocation(),
-  Specialization, Builder, Info.AssociatedConstraintsSatisfaction))
-return TDK_MiscellaneousDeductionFailure;
+  if (!PartialOverloading ||
+  (Builder.size() == FunctionTemplate->getTemplateParameters()->size())) {
+if (CheckInstantiatedFunctionTemplateConstraints(Info.getLocation(),
+Specialization, Builder, Info.AssociatedConstraintsSatisfaction))
+  return TDK_MiscellaneousDeductionFailure;
 
-  if (!Info.AssociatedConstraintsSatisfaction.IsSatisfied) {
-Info.reset(TemplateArgumentList::CreateCopy(Context, Builder));
-return TDK_ConstraintsNotSatisfied;
+if (!Info.AssociatedConstraintsSatisfaction.IsSatisfied) {
+  Info.reset(TemplateArgumentList::CreateCopy(Context, Builder));
+  return TDK_ConstraintsNotSatisfied;
+}
   }
 
   if (OriginalCallArgs) {

diff  --git a/clang/test/CXX/temp/temp.deduct/p5.cpp 
b/clang/test/CXX/temp/temp.deduct/p5.cpp
new file mode 100644
index ..0c998b19f181
--- /dev/null
+++ b/clang/test/CXX/temp/temp.deduct/p5.cpp
@@ -0,0 +1,6 @@
+// RUN:  %clang_cc1 -std=c++2a -verify %s -code-completion-at=%s:6:16
+// expected-no-diagnostics
+
+template  concept C = true;
+void bar(C auto foo);
+int y = bar(
\ No newline at end of file



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 38fd699 - [Concepts] Fix incorrect check when instantiating abbreviated template type-constraints

2020-02-06 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-02-06T23:29:07+02:00
New Revision: 38fd69995fc5a6f16e0aa132a46e5ccdbc2eebb3

URL: 
https://github.com/llvm/llvm-project/commit/38fd69995fc5a6f16e0aa132a46e5ccdbc2eebb3
DIFF: 
https://github.com/llvm/llvm-project/commit/38fd69995fc5a6f16e0aa132a46e5ccdbc2eebb3.diff

LOG: [Concepts] Fix incorrect check when instantiating abbreviated template 
type-constraints

We would incorrectly check whether the type-constraint had already been 
initialized, causing us
to ignore the invented template type constraints entirely.

Also, TemplateParameterList would store incorrect information about invented 
type parameters
when it observed them before their type-constraint was initialized, so we 
recreate it after
initializing the function type of an abbreviated template.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/instantiate-abbreviated-template.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a9357ede700e..568f5404dc0b 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2290,12 +2290,12 @@ ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl 
*OldParm,
   if (TemplateTypeParmDecl *TTP =
   GetContainedInventedTypeParmVisitor().Visit(OldDI->getType())) {
 if (const TypeConstraint *TC = TTP->getTypeConstraint()) {
-  auto *Inst = cast(
+  auto *Inst = cast_or_null(
   FindInstantiatedDecl(TTP->getLocation(), TTP, TemplateArgs));
   // We will first get here when instantiating the abbreviated function
   // template's described function, but we might also get here later.
   // Make sure we do not instantiate the TypeConstraint more than once.
-  if (Inst && !Inst->hasTypeConstraint()) {
+  if (Inst && !Inst->getTypeConstraint()) {
 // TODO: Concepts: do not instantiate the constraint (delayed 
constraint
 // substitution)
 const ASTTemplateArgumentListInfo *TemplArgInfo

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 7094462e74c9..37dace3bee7f 100755
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1837,6 +1837,23 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
 return nullptr;
   QualType T = adjustFunctionTypeForInstantiation(SemaRef.Context, D, TInfo);
 
+  if (TemplateParams && TemplateParams->size()) {
+auto *LastParam =
+dyn_cast(TemplateParams->asArray().back());
+if (LastParam && LastParam->isImplicit() &&
+LastParam->hasTypeConstraint()) {
+  // In abbreviated templates, the type-constraints of invented template
+  // type parameters are instantiated with the function type, invalidating
+  // the TemplateParameterList which relied on the template type parameter
+  // not having a type constraint. Recreate the TemplateParameterList with
+  // the updated parameter list.
+  TemplateParams = TemplateParameterList::Create(
+  SemaRef.Context, TemplateParams->getTemplateLoc(),
+  TemplateParams->getLAngleLoc(), TemplateParams->asArray(),
+  TemplateParams->getRAngleLoc(), TemplateParams->getRequiresClause());
+}
+  }
+
   NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc();
   if (QualifierLoc) {
 QualifierLoc = SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc,
@@ -2177,6 +2194,23 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl(
 return nullptr;
   QualType T = adjustFunctionTypeForInstantiation(SemaRef.Context, D, TInfo);
 
+  if (TemplateParams && TemplateParams->size()) {
+auto *LastParam =
+dyn_cast(TemplateParams->asArray().back());
+if (LastParam && LastParam->isImplicit() &&
+LastParam->hasTypeConstraint()) {
+  // In abbreviated templates, the type-constraints of invented template
+  // type parameters are instantiated with the function type, invalidating
+  // the TemplateParameterList which relied on the template type parameter
+  // not having a type constraint. Recreate the TemplateParameterList with
+  // the updated parameter list.
+  TemplateParams = TemplateParameterList::Create(
+  SemaRef.Context, TemplateParams->getTemplateLoc(),
+  TemplateParams->getLAngleLoc(), TemplateParams->asArray(),
+  TemplateParams->getRAngleLoc(), TemplateParams->getRequiresClause());
+}
+  }
+
   NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc();
   if (QualifierLoc) {
 QualifierLoc = SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc,

diff  --git a/clang/test/SemaTemplate/instantiate-abbreviated-template.cpp 
b/clang/test/SemaTemplate/instantiate-abbreviated-template.cpp
index 

[clang] 6c23244 - [Concepts] Add missing CXXThisScope to function template constraint substitution

2020-02-04 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-02-05T01:10:35+02:00
New Revision: 6c232441564f8934477e418347bf0c217abb0a00

URL: 
https://github.com/llvm/llvm-project/commit/6c232441564f8934477e418347bf0c217abb0a00
DIFF: 
https://github.com/llvm/llvm-project/commit/6c232441564f8934477e418347bf0c217abb0a00.diff

LOG: [Concepts] Add missing CXXThisScope to function template constraint 
substitution

We did not have a CXXThisScope around constraint checking of functions and
function template specializations, causing a crash when checking a constraint
that had a 'this' (bug 44689).

Recommit after fixing test.

Added: 


Modified: 
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/instantiate-requires-clause.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 39169664dad5..290e4cbff4fd 100755
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -329,6 +329,13 @@ bool Sema::CheckFunctionConstraints(const FunctionDecl *FD,
 Satisfaction.IsSatisfied = true;
 return false;
   }
+  Qualifiers ThisQuals;
+  CXXRecordDecl *Record = nullptr;
+  if (auto *Method = dyn_cast(FD)) {
+ThisQuals = Method->getMethodQualifiers();
+Record = const_cast(Method->getParent());
+  }
+  CXXThisScopeRAII ThisScope(*this, Record, ThisQuals, Record != nullptr);
   // We substitute with empty arguments in order to rebuild the atomic
   // constraint in a constant-evaluated context.
   // FIXME: Should this be a dedicated TreeTransform?

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 0e1d5fa77c69..7094462e74c9 100755
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4271,7 +4271,13 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints(
 Scope, MLTAL))
   return true;
   }
-
+  Qualifiers ThisQuals;
+  CXXRecordDecl *Record = nullptr;
+  if (auto *Method = dyn_cast(Decl)) {
+ThisQuals = Method->getMethodQualifiers();
+Record = Method->getParent();
+  }
+  CXXThisScopeRAII ThisScope(*this, Record, ThisQuals, Record != nullptr);
   return CheckConstraintSatisfaction(Template, TemplateAC, TemplateArgs,
  PointOfInstantiation, Satisfaction);
 }

diff  --git a/clang/test/SemaTemplate/instantiate-requires-clause.cpp 
b/clang/test/SemaTemplate/instantiate-requires-clause.cpp
index 8e9d5bffa906..a4d1b6597201 100644
--- a/clang/test/SemaTemplate/instantiate-requires-clause.cpp
+++ b/clang/test/SemaTemplate/instantiate-requires-clause.cpp
@@ -57,4 +57,13 @@ struct S3 {
static constexpr void f(Args...) { }
 };
 
-static_assert((S3::f(), true));
\ No newline at end of file
+static_assert((S3::f(), true));
+
+template
+struct S4 {
+template
+constexpr void foo() requires (*this, true) { }
+constexpr void goo() requires (*this, true) { }
+};
+
+static_assert((S4{}.foo(), S4{}.goo(), true));



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c348fb1 - Revert "[Concepts] Add missing CXXThisScope to function template constraint substitution"

2020-02-04 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-02-05T00:58:02+02:00
New Revision: c348fb1786ba62a69ec0ee9e9ed4a77fc46e071f

URL: 
https://github.com/llvm/llvm-project/commit/c348fb1786ba62a69ec0ee9e9ed4a77fc46e071f
DIFF: 
https://github.com/llvm/llvm-project/commit/c348fb1786ba62a69ec0ee9e9ed4a77fc46e071f.diff

LOG: Revert "[Concepts] Add missing CXXThisScope to function template 
constraint substitution"

This reverts commit 0c67cfdb114b4c2f5c7ec374cf12118c7fa9d768 which has a broken 
test.

Added: 


Modified: 
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/instantiate-requires-clause.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 290e4cbff4fd..39169664dad5 100755
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -329,13 +329,6 @@ bool Sema::CheckFunctionConstraints(const FunctionDecl *FD,
 Satisfaction.IsSatisfied = true;
 return false;
   }
-  Qualifiers ThisQuals;
-  CXXRecordDecl *Record = nullptr;
-  if (auto *Method = dyn_cast(FD)) {
-ThisQuals = Method->getMethodQualifiers();
-Record = const_cast(Method->getParent());
-  }
-  CXXThisScopeRAII ThisScope(*this, Record, ThisQuals, Record != nullptr);
   // We substitute with empty arguments in order to rebuild the atomic
   // constraint in a constant-evaluated context.
   // FIXME: Should this be a dedicated TreeTransform?

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 7094462e74c9..0e1d5fa77c69 100755
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4271,13 +4271,7 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints(
 Scope, MLTAL))
   return true;
   }
-  Qualifiers ThisQuals;
-  CXXRecordDecl *Record = nullptr;
-  if (auto *Method = dyn_cast(Decl)) {
-ThisQuals = Method->getMethodQualifiers();
-Record = Method->getParent();
-  }
-  CXXThisScopeRAII ThisScope(*this, Record, ThisQuals, Record != nullptr);
+
   return CheckConstraintSatisfaction(Template, TemplateAC, TemplateArgs,
  PointOfInstantiation, Satisfaction);
 }

diff  --git a/clang/test/SemaTemplate/instantiate-requires-clause.cpp 
b/clang/test/SemaTemplate/instantiate-requires-clause.cpp
index 2a42e2410fc3..8e9d5bffa906 100644
--- a/clang/test/SemaTemplate/instantiate-requires-clause.cpp
+++ b/clang/test/SemaTemplate/instantiate-requires-clause.cpp
@@ -57,13 +57,4 @@ struct S3 {
static constexpr void f(Args...) { }
 };
 
-static_assert((S3::f(), true));
-
-template
-struct S4 {
-template
-void foo() requires (*this, true) { }
-void goo() requires (*this, true) { }
-};
-
-static_assert((S4{}.foo(), S4{}.goo(), true));
+static_assert((S3::f(), true));
\ No newline at end of file



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0c67cfd - [Concepts] Add missing CXXThisScope to function template constraint substitution

2020-02-04 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-02-05T00:55:14+02:00
New Revision: 0c67cfdb114b4c2f5c7ec374cf12118c7fa9d768

URL: 
https://github.com/llvm/llvm-project/commit/0c67cfdb114b4c2f5c7ec374cf12118c7fa9d768
DIFF: 
https://github.com/llvm/llvm-project/commit/0c67cfdb114b4c2f5c7ec374cf12118c7fa9d768.diff

LOG: [Concepts] Add missing CXXThisScope to function template constraint 
substitution

We did not have a CXXThisScope around constraint checking of functions and
function template specializations, causing a crash when checking a constraint
that had a 'this' (bug 44689)

Added: 


Modified: 
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/instantiate-requires-clause.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 39169664dad5..290e4cbff4fd 100755
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -329,6 +329,13 @@ bool Sema::CheckFunctionConstraints(const FunctionDecl *FD,
 Satisfaction.IsSatisfied = true;
 return false;
   }
+  Qualifiers ThisQuals;
+  CXXRecordDecl *Record = nullptr;
+  if (auto *Method = dyn_cast(FD)) {
+ThisQuals = Method->getMethodQualifiers();
+Record = const_cast(Method->getParent());
+  }
+  CXXThisScopeRAII ThisScope(*this, Record, ThisQuals, Record != nullptr);
   // We substitute with empty arguments in order to rebuild the atomic
   // constraint in a constant-evaluated context.
   // FIXME: Should this be a dedicated TreeTransform?

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 0e1d5fa77c69..7094462e74c9 100755
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4271,7 +4271,13 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints(
 Scope, MLTAL))
   return true;
   }
-
+  Qualifiers ThisQuals;
+  CXXRecordDecl *Record = nullptr;
+  if (auto *Method = dyn_cast(Decl)) {
+ThisQuals = Method->getMethodQualifiers();
+Record = Method->getParent();
+  }
+  CXXThisScopeRAII ThisScope(*this, Record, ThisQuals, Record != nullptr);
   return CheckConstraintSatisfaction(Template, TemplateAC, TemplateArgs,
  PointOfInstantiation, Satisfaction);
 }

diff  --git a/clang/test/SemaTemplate/instantiate-requires-clause.cpp 
b/clang/test/SemaTemplate/instantiate-requires-clause.cpp
index 8e9d5bffa906..2a42e2410fc3 100644
--- a/clang/test/SemaTemplate/instantiate-requires-clause.cpp
+++ b/clang/test/SemaTemplate/instantiate-requires-clause.cpp
@@ -57,4 +57,13 @@ struct S3 {
static constexpr void f(Args...) { }
 };
 
-static_assert((S3::f(), true));
\ No newline at end of file
+static_assert((S3::f(), true));
+
+template
+struct S4 {
+template
+void foo() requires (*this, true) { }
+void goo() requires (*this, true) { }
+};
+
+static_assert((S4{}.foo(), S4{}.goo(), true));



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 84959ae - [Concepts] Instantiate invented template type parameter type-constraint along with function parameters

2020-02-03 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-02-03T16:51:49+02:00
New Revision: 84959ae47f447fca9d56a9c61e8c46e993d0387a

URL: 
https://github.com/llvm/llvm-project/commit/84959ae47f447fca9d56a9c61e8c46e993d0387a
DIFF: 
https://github.com/llvm/llvm-project/commit/84959ae47f447fca9d56a9c61e8c46e993d0387a.diff

LOG: [Concepts] Instantiate invented template type parameter type-constraint 
along with function parameters

We previously instantiated type-constraints of template type parameters along 
with the type parameter itself,
this caused problems when the type-constraints created by abbreviated templates 
refreneced other parameters
in the abbreviated templates.

When encountering a template type parameter with a type constraint, if it is 
implicit, delay instantiation of
the type-constraint until the function parameter which created the invented 
template type parameter is
instantiated.

Reland after fixing bug caused by another flow reaching SubstParmVarDecl and 
instantiating the TypeConstraint
a second time.

Added: 
clang/test/SemaTemplate/instantiate-abbreviated-template.cpp

Modified: 
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index dff336f2ff2d..a9357ede700e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/PrettyDeclStackTrace.h"
+#include "clang/AST/TypeVisitor.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/Stack.h"
 #include "clang/Sema/DeclSpec.h"
@@ -2145,6 +2146,94 @@ void Sema::SubstExceptionSpec(FunctionDecl *New, const 
FunctionProtoType *Proto,
   UpdateExceptionSpec(New, ESI);
 }
 
+namespace {
+
+  struct GetContainedInventedTypeParmVisitor :
+public TypeVisitor {
+using TypeVisitor::Visit;
+
+TemplateTypeParmDecl *Visit(QualType T) {
+  if (T.isNull())
+return nullptr;
+  return Visit(T.getTypePtr());
+}
+// The deduced type itself.
+TemplateTypeParmDecl *VisitTemplateTypeParmType(
+const TemplateTypeParmType *T) {
+  if (!T->getDecl()->isImplicit())
+return nullptr;
+  return T->getDecl();
+}
+
+// Only these types can contain 'auto' types, and subsequently be replaced
+// by references to invented parameters.
+
+TemplateTypeParmDecl *VisitElaboratedType(const ElaboratedType *T) {
+  return Visit(T->getNamedType());
+}
+
+TemplateTypeParmDecl *VisitPointerType(const PointerType *T) {
+  return Visit(T->getPointeeType());
+}
+
+TemplateTypeParmDecl *VisitBlockPointerType(const BlockPointerType *T) {
+  return Visit(T->getPointeeType());
+}
+
+TemplateTypeParmDecl *VisitReferenceType(const ReferenceType *T) {
+  return Visit(T->getPointeeTypeAsWritten());
+}
+
+TemplateTypeParmDecl *VisitMemberPointerType(const MemberPointerType *T) {
+  return Visit(T->getPointeeType());
+}
+
+TemplateTypeParmDecl *VisitArrayType(const ArrayType *T) {
+  return Visit(T->getElementType());
+}
+
+TemplateTypeParmDecl *VisitDependentSizedExtVectorType(
+  const DependentSizedExtVectorType *T) {
+  return Visit(T->getElementType());
+}
+
+TemplateTypeParmDecl *VisitVectorType(const VectorType *T) {
+  return Visit(T->getElementType());
+}
+
+TemplateTypeParmDecl *VisitFunctionProtoType(const FunctionProtoType *T) {
+  return VisitFunctionType(T);
+}
+
+TemplateTypeParmDecl *VisitFunctionType(const FunctionType *T) {
+  return Visit(T->getReturnType());
+}
+
+TemplateTypeParmDecl *VisitParenType(const ParenType *T) {
+  return Visit(T->getInnerType());
+}
+
+TemplateTypeParmDecl *VisitAttributedType(const AttributedType *T) {
+  return Visit(T->getModifiedType());
+}
+
+TemplateTypeParmDecl *VisitMacroQualifiedType(const MacroQualifiedType *T) 
{
+  return Visit(T->getUnderlyingType());
+}
+
+TemplateTypeParmDecl *VisitAdjustedType(const AdjustedType *T) {
+  return Visit(T->getOriginalType());
+}
+
+TemplateTypeParmDecl *VisitPackExpansionType(const PackExpansionType *T) {
+  return Visit(T->getPattern());
+}
+  };
+
+} // namespace
+
 ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm,
 const MultiLevelTemplateArgumentList ,
 int indexAdjustment,
@@ -2192,6 +2281,46 @@ ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm,
 return nullptr;
   }
 
+  // In abbreviated templates, TemplateTypeParmDecls with possible
+  // TypeConstraints are created when the parameter list is originally parsed.
+  // The TypeConstraints can therefore reference other functions 

[clang] 8c16d8b - Revert "[Concepts] Instantiate invented template type parameter type-constraint along with function parameters"

2020-02-03 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-02-03T16:04:48+02:00
New Revision: 8c16d8b235b997389a26d0ac7efe7840e208bb4d

URL: 
https://github.com/llvm/llvm-project/commit/8c16d8b235b997389a26d0ac7efe7840e208bb4d
DIFF: 
https://github.com/llvm/llvm-project/commit/8c16d8b235b997389a26d0ac7efe7840e208bb4d.diff

LOG: Revert "[Concepts] Instantiate invented template type parameter 
type-constraint along with function parameters"

This temporarily reverts commit eacca4824463d8b96e2e1c9f8bbf886055218a16, which 
caused some test failures.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 
clang/test/SemaTemplate/instantiate-abbreviated-template.cpp



diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 8c312c9d2c5a..dff336f2ff2d 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -18,7 +18,6 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/PrettyDeclStackTrace.h"
-#include "clang/AST/TypeVisitor.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/Stack.h"
 #include "clang/Sema/DeclSpec.h"
@@ -2146,94 +2145,6 @@ void Sema::SubstExceptionSpec(FunctionDecl *New, const 
FunctionProtoType *Proto,
   UpdateExceptionSpec(New, ESI);
 }
 
-namespace {
-
-  struct GetContainedInventedTypeParmVisitor :
-public TypeVisitor {
-using TypeVisitor::Visit;
-
-TemplateTypeParmDecl *Visit(QualType T) {
-  if (T.isNull())
-return nullptr;
-  return Visit(T.getTypePtr());
-}
-// The deduced type itself.
-TemplateTypeParmDecl *VisitTemplateTypeParmType(
-const TemplateTypeParmType *T) {
-  if (!T->getDecl()->isImplicit())
-return nullptr;
-  return T->getDecl();
-}
-
-// Only these types can contain 'auto' types, and subsequently be replaced
-// by references to invented parameters.
-
-TemplateTypeParmDecl *VisitElaboratedType(const ElaboratedType *T) {
-  return Visit(T->getNamedType());
-}
-
-TemplateTypeParmDecl *VisitPointerType(const PointerType *T) {
-  return Visit(T->getPointeeType());
-}
-
-TemplateTypeParmDecl *VisitBlockPointerType(const BlockPointerType *T) {
-  return Visit(T->getPointeeType());
-}
-
-TemplateTypeParmDecl *VisitReferenceType(const ReferenceType *T) {
-  return Visit(T->getPointeeTypeAsWritten());
-}
-
-TemplateTypeParmDecl *VisitMemberPointerType(const MemberPointerType *T) {
-  return Visit(T->getPointeeType());
-}
-
-TemplateTypeParmDecl *VisitArrayType(const ArrayType *T) {
-  return Visit(T->getElementType());
-}
-
-TemplateTypeParmDecl *VisitDependentSizedExtVectorType(
-  const DependentSizedExtVectorType *T) {
-  return Visit(T->getElementType());
-}
-
-TemplateTypeParmDecl *VisitVectorType(const VectorType *T) {
-  return Visit(T->getElementType());
-}
-
-TemplateTypeParmDecl *VisitFunctionProtoType(const FunctionProtoType *T) {
-  return VisitFunctionType(T);
-}
-
-TemplateTypeParmDecl *VisitFunctionType(const FunctionType *T) {
-  return Visit(T->getReturnType());
-}
-
-TemplateTypeParmDecl *VisitParenType(const ParenType *T) {
-  return Visit(T->getInnerType());
-}
-
-TemplateTypeParmDecl *VisitAttributedType(const AttributedType *T) {
-  return Visit(T->getModifiedType());
-}
-
-TemplateTypeParmDecl *VisitMacroQualifiedType(const MacroQualifiedType *T) 
{
-  return Visit(T->getUnderlyingType());
-}
-
-TemplateTypeParmDecl *VisitAdjustedType(const AdjustedType *T) {
-  return Visit(T->getOriginalType());
-}
-
-TemplateTypeParmDecl *VisitPackExpansionType(const PackExpansionType *T) {
-  return Visit(T->getPattern());
-}
-  };
-
-} // namespace
-
 ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm,
 const MultiLevelTemplateArgumentList ,
 int indexAdjustment,
@@ -2281,41 +2192,6 @@ ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm,
 return nullptr;
   }
 
-  // In abbreviated templates, TemplateTypeParmDecls with possible
-  // TypeConstraints are created when the parameter list is originally parsed.
-  // The TypeConstraints can therefore reference other functions parameters in
-  // the abbreviated function template, which is why we must instantiate them
-  // here, when the instantiated versions of those referenced parameters are in
-  // scope.
-  if (TemplateTypeParmDecl *TTP =
-  GetContainedInventedTypeParmVisitor().Visit(OldDI->getType())) {
-if (const TypeConstraint *TC = TTP->getTypeConstraint()) {
-  // TODO: Concepts: do not instantiate the constraint (delayed constraint
-  // substitution)
-  const 

[clang] eacca48 - [Concepts] Instantiate invented template type parameter type-constraint along with function parameters

2020-02-03 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-02-03T15:47:32+02:00
New Revision: eacca4824463d8b96e2e1c9f8bbf886055218a16

URL: 
https://github.com/llvm/llvm-project/commit/eacca4824463d8b96e2e1c9f8bbf886055218a16
DIFF: 
https://github.com/llvm/llvm-project/commit/eacca4824463d8b96e2e1c9f8bbf886055218a16.diff

LOG: [Concepts] Instantiate invented template type parameter type-constraint 
along with function parameters

We previously instantiated type-constraints of template type parameters along 
with the type parameter itself,
this caused problems when the type-constraints created by abbreviated templates 
refreneced other parameters
in the abbreviated templates.

When encountering a template type parameter with a type constraint, if it is 
implicit, delay instantiation of
the type-constraint until the function parameter which created the invented 
template type parameter is
instantiated.

Added: 
clang/test/SemaTemplate/instantiate-abbreviated-template.cpp

Modified: 
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index dff336f2ff2d..8c312c9d2c5a 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/PrettyDeclStackTrace.h"
+#include "clang/AST/TypeVisitor.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/Stack.h"
 #include "clang/Sema/DeclSpec.h"
@@ -2145,6 +2146,94 @@ void Sema::SubstExceptionSpec(FunctionDecl *New, const 
FunctionProtoType *Proto,
   UpdateExceptionSpec(New, ESI);
 }
 
+namespace {
+
+  struct GetContainedInventedTypeParmVisitor :
+public TypeVisitor {
+using TypeVisitor::Visit;
+
+TemplateTypeParmDecl *Visit(QualType T) {
+  if (T.isNull())
+return nullptr;
+  return Visit(T.getTypePtr());
+}
+// The deduced type itself.
+TemplateTypeParmDecl *VisitTemplateTypeParmType(
+const TemplateTypeParmType *T) {
+  if (!T->getDecl()->isImplicit())
+return nullptr;
+  return T->getDecl();
+}
+
+// Only these types can contain 'auto' types, and subsequently be replaced
+// by references to invented parameters.
+
+TemplateTypeParmDecl *VisitElaboratedType(const ElaboratedType *T) {
+  return Visit(T->getNamedType());
+}
+
+TemplateTypeParmDecl *VisitPointerType(const PointerType *T) {
+  return Visit(T->getPointeeType());
+}
+
+TemplateTypeParmDecl *VisitBlockPointerType(const BlockPointerType *T) {
+  return Visit(T->getPointeeType());
+}
+
+TemplateTypeParmDecl *VisitReferenceType(const ReferenceType *T) {
+  return Visit(T->getPointeeTypeAsWritten());
+}
+
+TemplateTypeParmDecl *VisitMemberPointerType(const MemberPointerType *T) {
+  return Visit(T->getPointeeType());
+}
+
+TemplateTypeParmDecl *VisitArrayType(const ArrayType *T) {
+  return Visit(T->getElementType());
+}
+
+TemplateTypeParmDecl *VisitDependentSizedExtVectorType(
+  const DependentSizedExtVectorType *T) {
+  return Visit(T->getElementType());
+}
+
+TemplateTypeParmDecl *VisitVectorType(const VectorType *T) {
+  return Visit(T->getElementType());
+}
+
+TemplateTypeParmDecl *VisitFunctionProtoType(const FunctionProtoType *T) {
+  return VisitFunctionType(T);
+}
+
+TemplateTypeParmDecl *VisitFunctionType(const FunctionType *T) {
+  return Visit(T->getReturnType());
+}
+
+TemplateTypeParmDecl *VisitParenType(const ParenType *T) {
+  return Visit(T->getInnerType());
+}
+
+TemplateTypeParmDecl *VisitAttributedType(const AttributedType *T) {
+  return Visit(T->getModifiedType());
+}
+
+TemplateTypeParmDecl *VisitMacroQualifiedType(const MacroQualifiedType *T) 
{
+  return Visit(T->getUnderlyingType());
+}
+
+TemplateTypeParmDecl *VisitAdjustedType(const AdjustedType *T) {
+  return Visit(T->getOriginalType());
+}
+
+TemplateTypeParmDecl *VisitPackExpansionType(const PackExpansionType *T) {
+  return Visit(T->getPattern());
+}
+  };
+
+} // namespace
+
 ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm,
 const MultiLevelTemplateArgumentList ,
 int indexAdjustment,
@@ -2192,6 +2281,41 @@ ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm,
 return nullptr;
   }
 
+  // In abbreviated templates, TemplateTypeParmDecls with possible
+  // TypeConstraints are created when the parameter list is originally parsed.
+  // The TypeConstraints can therefore reference other functions parameters in
+  // the abbreviated function template, which is why we must instantiate them
+  // here, when the instantiated 

[clang] b7ce85a - [Concepts] Fix isDeclarationSpecifier to detect type-constraints correctly

2020-01-31 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-31T20:08:13+02:00
New Revision: b7ce85a130789d23c69156f4b899962458d1f05d

URL: 
https://github.com/llvm/llvm-project/commit/b7ce85a130789d23c69156f4b899962458d1f05d
DIFF: 
https://github.com/llvm/llvm-project/commit/b7ce85a130789d23c69156f4b899962458d1f05d.diff

LOG: [Concepts] Fix isDeclarationSpecifier to detect type-constraints correctly

isDeclarationSpecifiers did not handle some cases of 
placeholder-type-specifiers with
type-constraints, causing parsing bugs in abbreviated constructor templates.

Add comprehensive handling of type-constraints to isDeclarationSpecifier.

Added: 


Modified: 
clang/lib/Parse/ParseDecl.cpp
clang/test/Parser/cxx2a-abbreviated-templates.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 871ca2512598..af6e105ca61f 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -5061,6 +5061,8 @@ bool Parser::isDeclarationSpecifier(bool 
DisambiguatingWithExpression) {
 // recurse to handle whatever we get.
 if (TryAnnotateTypeOrScopeToken())
   return true;
+if (TryAnnotateTypeConstraint())
+  return true;
 if (Tok.is(tok::identifier))
   return false;
 
@@ -5193,11 +5195,14 @@ bool Parser::isDeclarationSpecifier(bool 
DisambiguatingWithExpression) {
 
 // placeholder-type-specifier
   case tok::annot_template_id: {
-TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
-return TemplateId->Kind == TNK_Concept_template &&
+return isTypeConstraintAnnotation() &&
 (NextToken().is(tok::kw_auto) || NextToken().is(tok::kw_decltype));
   }
-
+  case tok::annot_cxxscope:
+if (NextToken().is(tok::identifier) && TryAnnotateTypeConstraint())
+  return true;
+return isTypeConstraintAnnotation() &&
+GetLookAheadToken(2).isOneOf(tok::kw_auto, tok::kw_decltype);
   case tok::kw___declspec:
   case tok::kw___cdecl:
   case tok::kw___stdcall:

diff  --git a/clang/test/Parser/cxx2a-abbreviated-templates.cpp 
b/clang/test/Parser/cxx2a-abbreviated-templates.cpp
index e2b3803c807e..6562389f7676 100644
--- a/clang/test/Parser/cxx2a-abbreviated-templates.cpp
+++ b/clang/test/Parser/cxx2a-abbreviated-templates.cpp
@@ -9,11 +9,36 @@ namespace ns {
   concept D = true;
 }
 
-void foo(C auto a,
- C auto b,
- ns::D auto c,
- ns::D auto d,
- const C auto e,
- const C auto f,
- const ns::D auto g,
- const ns::D auto h);
\ No newline at end of file
+void foo1(C auto a,
+  C auto b,
+  ns::D auto c,
+  ns::D auto d,
+  const C auto e,
+  const C auto f,
+  const ns::D auto g,
+  const ns::D auto h);
+void foo2(C auto a);
+void foo3(C auto b);
+void foo4(ns::D auto c);
+void foo5(ns::D auto d);
+void foo6(const C auto e);
+void foo7(const C auto f);
+void foo8(const ns::D auto g);
+void foo9(const ns::D auto h);
+
+struct S1 { S1(C auto a,
+   C auto b,
+   ns::D auto c,
+   ns::D auto d,
+   const C auto e,
+   const C auto f,
+   const ns::D auto g,
+   const ns::D auto h); };
+struct S2 { S2(C auto a); };
+struct S3 { S3(C auto b); };
+struct S4 { S4(ns::D auto c); };
+struct S5 { S5(ns::D auto d); };
+struct S6 { S6(const C auto e); };
+struct S7 { S7(const C auto f); };
+struct S8 { S8(const ns::D auto g); };
+struct S9 { S9(const ns::D auto h); };
\ No newline at end of file



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ba1f3db - [Concepts] Correctly form initial parameter mapping for parameter packs, support substitution into SubstNonTypeTemplateParmExpr

2020-01-31 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-31T15:59:42+02:00
New Revision: ba1f3db4b0729ad932aa4f091e9578132d98a0c8

URL: 
https://github.com/llvm/llvm-project/commit/ba1f3db4b0729ad932aa4f091e9578132d98a0c8
DIFF: 
https://github.com/llvm/llvm-project/commit/ba1f3db4b0729ad932aa4f091e9578132d98a0c8.diff

LOG: [Concepts] Correctly form initial parameter mapping for parameter packs, 
support substitution into SubstNonTypeTemplateParmExpr

We previously would not correctly for the initial parameter mapping for 
variadic template parameters in Concepts.
Testing this lead to the discovery that with the normalization process we would 
need to substitute into already-substituted-into
template arguments, which means we need to add NonTypeTemplateParmExpr support 
to TemplateInstantiator.
We do that by substituting into the replacement and the type separately, and 
then re-checking the expression against the NTTP
with the new type, in order to form any new required implicit casts (for cases 
where the type of the NTTP was dependent).

Added: 
clang/test/SemaTemplate/instantiate-template-argument.cpp

Modified: 
clang/include/clang/Sema/Sema.h
clang/include/clang/Sema/SemaConcept.h
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 39b070edea52..0de12a0ebe33 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -7019,7 +7019,7 @@ class Sema final {
   /// Get a template argument mapping the given template parameter to itself,
   /// e.g. for X in \c template, this would return an expression 
template
   /// argument referencing X.
-  TemplateArgumentLoc getIdentityTemplateArgumentLoc(Decl *Param,
+  TemplateArgumentLoc getIdentityTemplateArgumentLoc(NamedDecl *Param,
  SourceLocation Location);
 
   void translateTemplateArguments(const ASTTemplateArgsPtr ,

diff  --git a/clang/include/clang/Sema/SemaConcept.h 
b/clang/include/clang/Sema/SemaConcept.h
index 7fc42a4816ec..c5f9fc45612a 100644
--- a/clang/include/clang/Sema/SemaConcept.h
+++ b/clang/include/clang/Sema/SemaConcept.h
@@ -43,11 +43,15 @@ struct AtomicConstraint {
 if (ParameterMapping->size() != Other.ParameterMapping->size())
   return false;
 
-for (unsigned I = 0, S = ParameterMapping->size(); I < S; ++I)
-  if (!C.getCanonicalTemplateArgument((*ParameterMapping)[I].getArgument())
-   .structurallyEquals(C.getCanonicalTemplateArgument(
-  (*Other.ParameterMapping)[I].getArgument(
+for (unsigned I = 0, S = ParameterMapping->size(); I < S; ++I) {
+  llvm::FoldingSetNodeID IDA, IDB;
+  C.getCanonicalTemplateArgument((*ParameterMapping)[I].getArgument())
+  .Profile(IDA, C);
+  
C.getCanonicalTemplateArgument((*Other.ParameterMapping)[I].getArgument())
+  .Profile(IDB, C);
+  if (IDA != IDB)
 return false;
+}
 return true;
   }
 

diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 8fdc6023040f..39169664dad5 100755
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -676,6 +676,10 @@ static bool substituteParameterMappings(Sema , 
NormalizedConstraint ,
   
ArgsAsWritten->arguments().back().getSourceRange().getEnd()));
   if (S.SubstTemplateArguments(*Atomic.ParameterMapping, MLTAL, SubstArgs))
 return true;
+  Atomic.ParameterMapping.emplace(
+MutableArrayRef(
+new (S.Context) TemplateArgumentLoc[SubstArgs.size()],
+SubstArgs.size()));
   std::copy(SubstArgs.arguments().begin(), SubstArgs.arguments().end(),
 N.getAtomicConstraint()->ParameterMapping->begin());
   return false;

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 394c81c82794..1a71f270679d 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2488,7 +2488,7 @@ Sema::getTrivialTemplateArgumentLoc(const 
TemplateArgument ,
 case TemplateArgument::Template:
 case TemplateArgument::TemplateExpansion: {
   NestedNameSpecifierLocBuilder Builder;
-  TemplateName Template = Arg.getAsTemplate();
+  TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
   if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
 Builder.MakeTrivial(Context, DTN->getQualifier(), Loc);
   else if (QualifiedTemplateName *QTN =
@@ -2514,27 +2514,10 @@ Sema::getTrivialTemplateArgumentLoc(const 
TemplateArgument ,
 }
 
 TemplateArgumentLoc
-Sema::getIdentityTemplateArgumentLoc(Decl *TemplateParm,
+Sema::getIdentityTemplateArgumentLoc(NamedDecl 

[clang] 980517b - [Concepts] Check function constraints before deducing auto return type

2020-01-30 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-31T03:51:26+02:00
New Revision: 980517b3530ffb7faa1a23fdc007d78f5b45ae3c

URL: 
https://github.com/llvm/llvm-project/commit/980517b3530ffb7faa1a23fdc007d78f5b45ae3c
DIFF: 
https://github.com/llvm/llvm-project/commit/980517b3530ffb7faa1a23fdc007d78f5b45ae3c.diff

LOG: [Concepts] Check function constraints before deducing auto return type

A constrained function with an auto return type would have it's definition
instantiated in order to deduce the auto return type before the constraints
are checked.

Move the constraints check after the return type deduction.

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/CXX/expr/expr.prim/expr.prim.id/p4.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 248757682057..2380a6b8d67f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -245,8 +245,8 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, 
ArrayRef Locs,
 return true;
   }
 
-  // See if this is a deleted function.
   if (FunctionDecl *FD = dyn_cast(D)) {
+// See if this is a deleted function.
 if (FD->isDeleted()) {
   auto *Ctor = dyn_cast(FD);
   if (Ctor && Ctor->isInheritingConstructor())
@@ -259,6 +259,29 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, 
ArrayRef Locs,
   return true;
 }
 
+// [expr.prim.id]p4
+//   A program that refers explicitly or implicitly to a function with a
+//   trailing requires-clause whose constraint-expression is not satisfied,
+//   other than to declare it, is ill-formed. [...]
+//
+// See if this is a function with constraints that need to be satisfied.
+// Check this before deducing the return type, as it might instantiate the
+// definition.
+if (FD->getTrailingRequiresClause()) {
+  ConstraintSatisfaction Satisfaction;
+  if (CheckFunctionConstraints(FD, Satisfaction, Loc))
+// A diagnostic will have already been generated (non-constant
+// constraint expression, for example)
+return true;
+  if (!Satisfaction.IsSatisfied) {
+Diag(Loc,
+ diag::err_reference_to_function_with_unsatisfied_constraints)
+<< D;
+DiagnoseUnsatisfiedConstraint(Satisfaction);
+return true;
+  }
+}
+
 // If the function has a deduced return type, and we can't deduce it,
 // then we can't use it either.
 if (getLangOpts().CPlusPlus14 && FD->getReturnType()->isUndeducedType() &&
@@ -326,29 +349,6 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, 
ArrayRef Locs,
 
   diagnoseUseOfInternalDeclInInlineFunction(*this, D, Loc);
 
-  // [expr.prim.id]p4
-  //   A program that refers explicitly or implicitly to a function with a
-  //   trailing requires-clause whose constraint-expression is not satisfied,
-  //   other than to declare it, is ill-formed. [...]
-  //
-  // See if this is a function with constraints that need to be satisfied.
-  if (FunctionDecl *FD = dyn_cast(D)) {
-if (FD->getTrailingRequiresClause()) {
-  ConstraintSatisfaction Satisfaction;
-  if (CheckFunctionConstraints(FD, Satisfaction, Loc))
-// A diagnostic will have already been generated (non-constant
-// constraint expression, for example)
-return true;
-  if (!Satisfaction.IsSatisfied) {
-Diag(Loc,
- diag::err_reference_to_function_with_unsatisfied_constraints)
-<< D;
-DiagnoseUnsatisfiedConstraint(Satisfaction);
-return true;
-  }
-}
-  }
-
   if (isa(D) && isa(D->getDeclContext()) &&
   !isUnevaluatedContext()) {
 // C++ [expr.prim.req.nested] p3

diff  --git a/clang/test/CXX/expr/expr.prim/expr.prim.id/p4.cpp 
b/clang/test/CXX/expr/expr.prim/expr.prim.id/p4.cpp
index f4c38c73d255..d3dde10ff2b2 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.id/p4.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.id/p4.cpp
@@ -26,11 +26,14 @@ namespace methods
   struct A {
 static void foo(int) requires (sizeof(T) == 1) {} // expected-note 
3{{because 'sizeof(char [2]) == 1' (2 == 1) evaluated to false}}
 static void bar(int) requires (sizeof(T) == 2) {} // expected-note 
3{{because 'sizeof(char) == 2' (1 == 2) evaluated to false}}
+// Make sure the function body is not instantiated before constraints are 
checked.
+static auto baz(int) requires (sizeof(T) == 2) { return T::foo(); } // 
expected-note{{because 'sizeof(char) == 2' (1 == 2) evaluated to false}}
   };
 
   void baz() {
 A::foo(1);
 A::bar(1); // expected-error{{invalid reference to function 'bar': 
constraints not satisfied}}
+A::baz(1); // expected-error{{invalid reference to function 'baz': 
constraints not satisfied}}
 A::foo(1); // expected-error{{invalid reference to function 
'foo': constraints not satisfied}}
 A::bar(1);
 void (*p1)(int) = A::foo;




[clang] 60f5da7 - [Concepts] Add 'this' context to instantiation of member requires clause

2020-01-30 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-30T20:47:59+02:00
New Revision: 60f5da79e3de49b2074446e656a72970499a8d78

URL: 
https://github.com/llvm/llvm-project/commit/60f5da79e3de49b2074446e656a72970499a8d78
DIFF: 
https://github.com/llvm/llvm-project/commit/60f5da79e3de49b2074446e656a72970499a8d78.diff

LOG: [Concepts] Add 'this' context to instantiation of member requires clause

'this' context was missing in instantiation of member requires clause.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 2e437cbe44d3..2637b4cb6dca 100755
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2190,6 +2190,9 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl(
   if (TrailingRequiresClause) {
 EnterExpressionEvaluationContext ConstantEvaluated(
 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
+auto *ThisContext = dyn_cast_or_null(Owner);
+Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext,
+ D->getMethodQualifiers(), ThisContext);
 ExprResult SubstRC = SemaRef.SubstExpr(TrailingRequiresClause,
TemplateArgs);
 if (SubstRC.isInvalid())



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a424ef9 - [Concepts] Add check for dependent RC when checking function constraints

2020-01-30 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-30T20:46:32+02:00
New Revision: a424ef99e7b9821ec80564af3d3a8f091323a38c

URL: 
https://github.com/llvm/llvm-project/commit/a424ef99e7b9821ec80564af3d3a8f091323a38c
DIFF: 
https://github.com/llvm/llvm-project/commit/a424ef99e7b9821ec80564af3d3a8f091323a38c.diff

LOG: [Concepts] Add check for dependent RC when checking function constraints

Do not attempt to check a dependent requires clause in a function constraint
(may be triggered by, for example, DiagnoseUseOfDecl).

Added: 


Modified: 
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index e5c0fa28c11f..8fdc6023040f 100755
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -325,9 +325,10 @@ bool Sema::CheckFunctionConstraints(const FunctionDecl *FD,
 ConstraintSatisfaction ,
 SourceLocation UsageLoc) {
   const Expr *RC = FD->getTrailingRequiresClause();
-  assert(!RC->isInstantiationDependent() &&
- "CheckFunctionConstraints can only be used with functions with "
- "non-dependent constraints");
+  if (RC->isInstantiationDependent()) {
+Satisfaction.IsSatisfied = true;
+return false;
+  }
   // We substitute with empty arguments in order to rebuild the atomic
   // constraint in a constant-evaluated context.
   // FIXME: Should this be a dedicated TreeTransform?

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index b063247bf1df..81eee22af4ee 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -333,11 +333,9 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, 
ArrayRef Locs,
   //
   // See if this is a function with constraints that need to be satisfied.
   if (FunctionDecl *FD = dyn_cast(D)) {
-if (Expr *RC = FD->getTrailingRequiresClause()) {
+if (FD->getTrailingRequiresClause()) {
   ConstraintSatisfaction Satisfaction;
-  bool Failed = CheckConstraintSatisfaction(FD, {RC}, /*TemplateArgs=*/{},
-SourceRange(Loc), 
Satisfaction);
-  if (Failed)
+  if (CheckFunctionConstraints(FD, Satisfaction, Loc))
 // A diagnostic will have already been generated (non-constant
 // constraint expression, for example)
 return true;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c83d9be - [Concept] Fix incorrect check for containsUnexpandedParameterPack in CSE

2020-01-30 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-30T20:45:44+02:00
New Revision: c83d9bedc0cc430dc620e7a807daeb985d390325

URL: 
https://github.com/llvm/llvm-project/commit/c83d9bedc0cc430dc620e7a807daeb985d390325
DIFF: 
https://github.com/llvm/llvm-project/commit/c83d9bedc0cc430dc620e7a807daeb985d390325.diff

LOG: [Concept] Fix incorrect check for containsUnexpandedParameterPack in CSE

We previously checked for containsUnexpandedParameterPack in CSEs by observing 
the property
in the converted arguments of the CSE. This may not work if the argument is an 
expanded
type-alias that contains a pack-expansion (see added test).

Check the as-written arguments when determining containsUnexpandedParameterPack 
and isInstantiationDependent.

Added: 


Modified: 
clang/include/clang/AST/ExprConcepts.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ExprConcepts.cpp
clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ExprConcepts.h 
b/clang/include/clang/AST/ExprConcepts.h
index 2a64326e8604..271d487e2fc9 100644
--- a/clang/include/clang/AST/ExprConcepts.h
+++ b/clang/include/clang/AST/ExprConcepts.h
@@ -63,6 +63,12 @@ class ConceptSpecializationExpr final : public Expr, public 
ConceptReference,
 ArrayRef ConvertedArgs,
 const ConstraintSatisfaction *Satisfaction);
 
+  ConceptSpecializationExpr(const ASTContext , ConceptDecl *NamedConcept,
+ArrayRef ConvertedArgs,
+const ConstraintSatisfaction *Satisfaction,
+bool Dependent,
+bool ContainsUnexpandedParameterPack);
+
   ConceptSpecializationExpr(EmptyShell Empty, unsigned NumTemplateArgs);
 
 public:
@@ -75,6 +81,13 @@ class ConceptSpecializationExpr final : public Expr, public 
ConceptReference,
  ArrayRef ConvertedArgs,
  const ConstraintSatisfaction *Satisfaction);
 
+  static ConceptSpecializationExpr *
+  Create(const ASTContext , ConceptDecl *NamedConcept,
+ ArrayRef ConvertedArgs,
+ const ConstraintSatisfaction *Satisfaction,
+ bool Dependent,
+ bool ContainsUnexpandedParameterPack);
+
   static ConceptSpecializationExpr *
   Create(ASTContext , EmptyShell Empty, unsigned NumTemplateArgs);
 

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 72969490e32d..c80d3948d003 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -731,12 +731,8 @@ canonicalizeImmediatelyDeclaredConstraint(const ASTContext 
, Expr *IDC,
   NewConverted.push_back(Arg);
   }
   Expr *NewIDC = ConceptSpecializationExpr::Create(
-  C, NestedNameSpecifierLoc(), /*TemplateKWLoc=*/SourceLocation(),
-  CSE->getConceptNameInfo(), /*FoundDecl=*/CSE->getNamedConcept(),
-  CSE->getNamedConcept(),
-  // Actually canonicalizing a TemplateArgumentLoc is 
diff icult so we
-  // simply omit the ArgsAsWritten
-  /*ArgsAsWritten=*/nullptr, NewConverted, nullptr);
+  C, CSE->getNamedConcept(), NewConverted, nullptr,
+  CSE->isInstantiationDependent(), CSE->containsUnexpandedParameterPack());
 
   if (auto *OrigFold = dyn_cast(IDC))
 NewIDC = new (C) CXXFoldExpr(OrigFold->getType(), SourceLocation(), NewIDC,

diff  --git a/clang/lib/AST/ExprConcepts.cpp b/clang/lib/AST/ExprConcepts.cpp
index 76d57ed5d5b1..b5a3686dc99a 100644
--- a/clang/lib/AST/ExprConcepts.cpp
+++ b/clang/lib/AST/ExprConcepts.cpp
@@ -46,24 +46,12 @@ ConceptSpecializationExpr::ConceptSpecializationExpr(const 
ASTContext ,
ASTConstraintSatisfaction::Create(C, *Satisfaction) :
nullptr) {
   setTemplateArguments(ConvertedArgs);
-}
-
-ConceptSpecializationExpr::ConceptSpecializationExpr(EmptyShell Empty,
-unsigned NumTemplateArgs)
-: Expr(ConceptSpecializationExprClass, Empty), ConceptReference(),
-  NumTemplateArgs(NumTemplateArgs) { }
-
-void ConceptSpecializationExpr::setTemplateArguments(
-ArrayRef Converted) {
-  assert(Converted.size() == NumTemplateArgs);
-  std::uninitialized_copy(Converted.begin(), Converted.end(),
-  getTrailingObjects());
   bool IsInstantiationDependent = false;
   bool ContainsUnexpandedParameterPack = false;
-  for (const TemplateArgument& Arg : Converted) {
-if (Arg.isInstantiationDependent())
+  for (const TemplateArgumentLoc& ArgLoc : ArgsAsWritten->arguments()) {
+if (ArgLoc.getArgument().isInstantiationDependent())
   IsInstantiationDependent = true;
-if (Arg.containsUnexpandedParameterPack())
+if (ArgLoc.getArgument().containsUnexpandedParameterPack())
   ContainsUnexpandedParameterPack = true;
 if (ContainsUnexpandedParameterPack && IsInstantiationDependent)
   break;
@@ -80,6 +68,18 @@ void ConceptSpecializationExpr::setTemplateArguments(
  

[clang] 9c24fca - [Concepts] Fix incorrect TemplateArgs for introduction of local parameters

2020-01-26 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-27T00:59:37+02:00
New Revision: 9c24fca2a33fc0fd059e278bb95c84803dfff9ae

URL: 
https://github.com/llvm/llvm-project/commit/9c24fca2a33fc0fd059e278bb95c84803dfff9ae
DIFF: 
https://github.com/llvm/llvm-project/commit/9c24fca2a33fc0fd059e278bb95c84803dfff9ae.diff

LOG: [Concepts] Fix incorrect TemplateArgs for introduction of local parameters

The wrong set of TemplateArgs was being provided to 
addInstantiatedParametersToScope.
Caused bug #44658.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/instantiate-requires-clause.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index fbbab8f00703..2e437cbe44d3 100755
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4246,18 +4246,17 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints(
   Sema::ContextRAII savedContext(*this, Decl);
   LocalInstantiationScope Scope(*this);
 
-  MultiLevelTemplateArgumentList MLTAL =
-getTemplateInstantiationArgs(Decl, nullptr, /*RelativeToPrimary*/true);
-
   // If this is not an explicit specialization - we need to get the 
instantiated
   // version of the template arguments and add them to scope for the
   // substitution.
   if (Decl->isTemplateInstantiation()) {
 InstantiatingTemplate Inst(*this, Decl->getPointOfInstantiation(),
 InstantiatingTemplate::ConstraintsCheck{}, Decl->getPrimaryTemplate(),
-MLTAL.getInnermost(), SourceRange());
+TemplateArgs, SourceRange());
 if (Inst.isInvalid())
   return true;
+MultiLevelTemplateArgumentList MLTAL(
+*Decl->getTemplateSpecializationArgs());
 if (addInstantiatedParametersToScope(
 *this, Decl, Decl->getPrimaryTemplate()->getTemplatedDecl(),
 Scope, MLTAL))

diff  --git a/clang/test/SemaTemplate/instantiate-requires-clause.cpp 
b/clang/test/SemaTemplate/instantiate-requires-clause.cpp
index 31cf484d564c..8e9d5bffa906 100644
--- a/clang/test/SemaTemplate/instantiate-requires-clause.cpp
+++ b/clang/test/SemaTemplate/instantiate-requires-clause.cpp
@@ -51,3 +51,10 @@ struct S2 {
 
 static_assert((S2::f(), true));
 
+template
+struct S3 {
+   template requires true
+   static constexpr void f(Args...) { }
+};
+
+static_assert((S3::f(), true));
\ No newline at end of file



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a8d096a - [Concepts] Add missing null check to transformConstructor

2020-01-26 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-27T00:15:42+02:00
New Revision: a8d096aff6b1930ad57bd0c30077d2b4920b5025

URL: 
https://github.com/llvm/llvm-project/commit/a8d096aff6b1930ad57bd0c30077d2b4920b5025
DIFF: 
https://github.com/llvm/llvm-project/commit/a8d096aff6b1930ad57bd0c30077d2b4920b5025.diff

LOG: [Concepts] Add missing null check to transformConstructor

Caused bug 44671 when transforming a constructor with a type-constraint with no 
explicit template args.

Added: 


Modified: 
clang/lib/Sema/SemaTemplate.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index ba4cd7632f3c..4d38d07a6213 100755
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2047,12 +2047,14 @@ struct ConvertConstructorToDeductionGuideTransform {
   if (const auto *TC = TTP->getTypeConstraint()) {
 TemplateArgumentListInfo TransformedArgs;
 const auto *ArgsAsWritten = TC->getTemplateArgsAsWritten();
-if (SemaRef.Subst(ArgsAsWritten->getTemplateArgs(),
+if (!ArgsAsWritten ||
+SemaRef.Subst(ArgsAsWritten->getTemplateArgs(),
   ArgsAsWritten->NumTemplateArgs, TransformedArgs,
   Args))
   SemaRef.AttachTypeConstraint(
   TC->getNestedNameSpecifierLoc(), TC->getConceptNameInfo(),
-  TC->getNamedConcept(), , NewTTP,
+  TC->getNamedConcept(), ArgsAsWritten ?  : 
nullptr,
+  NewTTP,
   NewTTP->isParameterPack()
  ? cast(TC->getImmediatelyDeclaredConstraint())
  ->getEllipsisLoc()



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5043962 - [Concepts] Fix parsing of scope specifier in compound-requirements, add more tests for scope specifiers in type-constraints

2020-01-26 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-26T20:46:53+02:00
New Revision: 5043962dd3150c6ac72b75174b9460a510d1b5c3

URL: 
https://github.com/llvm/llvm-project/commit/5043962dd3150c6ac72b75174b9460a510d1b5c3
DIFF: 
https://github.com/llvm/llvm-project/commit/5043962dd3150c6ac72b75174b9460a510d1b5c3.diff

LOG: [Concepts] Fix parsing of scope specifier in compound-requirements, add 
more tests for scope specifiers in type-constraints

The code for parsing of type-constraints in compound-requirements was not 
adapted for the new TryAnnotateTypeConstraint which
caused compound-requirements with scope specifiers to ignore them.

Also add regression tests for scope specifiers in type-constraints in more 
contexts.

Added: 
clang/test/Parser/cxx2a-abbreviated-templates.cpp

Modified: 
clang/lib/Parse/ParseExprCXX.cpp
clang/test/Parser/cxx2a-concepts-requires-expr.cpp
clang/test/Parser/cxx2a-placeholder-type-constraint.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseExprCXX.cpp 
b/clang/lib/Parse/ParseExprCXX.cpp
index 73d15cbc20c1..5b604f940ab8 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3383,25 +3383,6 @@ ExprResult Parser::ParseRequiresExpression() {
   Diag(Tok, diag::err_requires_expr_missing_arrow)
   << FixItHint::CreateInsertion(Tok.getLocation(), "->");
 // Try to parse a 'type-constraint'
-CXXScopeSpec SS;
-if (ParseOptionalCXXScopeSpecifier(SS, ParsedType(),
-   /*EnteringContext=*/false,
-   /*MayBePseudoDestructor=*/nullptr,
-   // If this is not a type-constraint,
-   // then this scope-spec is part of
-   // the typename of a non-type
-   // template parameter
-   /*IsTypename=*/true,
-   /*LastII=*/nullptr,
-   // We won't find concepts in
-   // non-namespaces anyway, so might 
as
-   // well parse this correctly for
-   // possible type names.
-   /*OnlyNamespace=*/false,
-   /*SuppressDiagnostic=*/true)) {
-  SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch);
-  break;
-}
 if (TryAnnotateTypeConstraint()) {
   SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch);
   break;
@@ -3411,8 +3392,13 @@ ExprResult Parser::ParseRequiresExpression() {
   SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch);
   break;
 }
-if (Tok.is(tok::annot_cxxscope))
+CXXScopeSpec SS;
+if (Tok.is(tok::annot_cxxscope)) {
+  
Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
+   
Tok.getAnnotationRange(),
+   SS);
   ConsumeAnnotationToken();
+}
 
 Req = Actions.ActOnCompoundRequirement(
 Expression.get(), NoexceptLoc, SS, takeTemplateIdAnnotation(Tok),

diff  --git a/clang/test/Parser/cxx2a-abbreviated-templates.cpp 
b/clang/test/Parser/cxx2a-abbreviated-templates.cpp
new file mode 100644
index ..e2b3803c807e
--- /dev/null
+++ b/clang/test/Parser/cxx2a-abbreviated-templates.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -std=c++2a -x c++ %s -verify
+// expected-no-diagnostics
+
+template
+concept C = true;
+
+namespace ns {
+  template
+  concept D = true;
+}
+
+void foo(C auto a,
+ C auto b,
+ ns::D auto c,
+ ns::D auto d,
+ const C auto e,
+ const C auto f,
+ const ns::D auto g,
+ const ns::D auto h);
\ No newline at end of file

diff  --git a/clang/test/Parser/cxx2a-concepts-requires-expr.cpp 
b/clang/test/Parser/cxx2a-concepts-requires-expr.cpp
index 6b4a5d62b407..fa42b0633850 100644
--- a/clang/test/Parser/cxx2a-concepts-requires-expr.cpp
+++ b/clang/test/Parser/cxx2a-concepts-requires-expr.cpp
@@ -108,34 +108,38 @@ bool r29 = requires { { 0 } noexcept C1; };
 
 bool r30 = requires { { 0 } noexcept -> C2; };
 
+namespace ns { template concept C = true; }
+
+bool r31 = requires { { 0 } noexcept -> ns::C; };
+
 template
 T i1 = 0;
 
-bool r31 = requires { requires false, 1; };
+bool r32 = requires { requires false, 1; };
 // expected-error@-1 {{expected ';' at end of requirement}}
 
-bool r32 = requires { 0 noexcept; };
+bool r33 = requires { 0 noexcept; };
 // expected-error@-1 {{'noexcept' can only be used in a 

[clang] 713562f - [Concepts] Transform constraints of non-template functions to ConstantEvaluated

2020-01-25 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-25T23:00:24+02:00
New Revision: 713562f54858f10bf8998ee21ff2c7e7bad0d177

URL: 
https://github.com/llvm/llvm-project/commit/713562f54858f10bf8998ee21ff2c7e7bad0d177
DIFF: 
https://github.com/llvm/llvm-project/commit/713562f54858f10bf8998ee21ff2c7e7bad0d177.diff

LOG: [Concepts] Transform constraints of non-template functions to 
ConstantEvaluated

We would previously try to evaluate atomic constraints of non-template 
functions as-is,
and since they are now unevaluated at first, this would cause incorrect 
evaluation (bugs #44657, #44656).

Substitute into atomic constraints of non-template functions as we would atomic 
constraints
of template functions, in order to rebuild the expressions in a 
constant-evaluated context.

Added: 


Modified: 
clang/include/clang/AST/ASTConcept.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTConcept.cpp
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/SemaTemplate/cxx2a-constraint-exprs.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTConcept.h 
b/clang/include/clang/AST/ASTConcept.h
index 30c4706d2a15..3ebaad4eafdd 100644
--- a/clang/include/clang/AST/ASTConcept.h
+++ b/clang/include/clang/AST/ASTConcept.h
@@ -29,14 +29,14 @@ class ConceptSpecializationExpr;
 class ConstraintSatisfaction : public llvm::FoldingSetNode {
   // The template-like entity that 'owns' the constraint checked here (can be a
   // constrained entity or a concept).
-  NamedDecl *ConstraintOwner = nullptr;
+  const NamedDecl *ConstraintOwner = nullptr;
   llvm::SmallVector TemplateArgs;
 
 public:
 
   ConstraintSatisfaction() = default;
 
-  ConstraintSatisfaction(NamedDecl *ConstraintOwner,
+  ConstraintSatisfaction(const NamedDecl *ConstraintOwner,
  ArrayRef TemplateArgs) :
   ConstraintOwner(ConstraintOwner), TemplateArgs(TemplateArgs.begin(),
  TemplateArgs.end()) { }
@@ -57,7 +57,7 @@ class ConstraintSatisfaction : public llvm::FoldingSetNode {
   }
 
   static void Profile(llvm::FoldingSetNodeID , const ASTContext ,
-  NamedDecl *ConstraintOwner,
+  const NamedDecl *ConstraintOwner,
   ArrayRef TemplateArgs);
 };
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b49c222c8fb7..5e88c6ee86ab 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4686,6 +4686,8 @@ def note_checking_constraints_for_var_spec_id_here : Note<
 def note_checking_constraints_for_class_spec_id_here : Note<
   "while checking constraint satisfaction for class template partial "
   "specialization '%0' required here">;
+def note_checking_constraints_for_function_here : Note<
+  "while checking constraint satisfaction for function '%0' required here">;
 def note_constraint_substitution_here : Note<
   "while substituting template arguments into constraint expression here">;
 def note_constraint_normalization_here : Note<

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5ab74e4cd662..64a6793aa411 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -6288,7 +6288,7 @@ class Sema final {
   /// \returns true if an error occurred and satisfaction could not be checked,
   /// false otherwise.
   bool CheckConstraintSatisfaction(
-  NamedDecl *Template, ArrayRef ConstraintExprs,
+  const NamedDecl *Template, ArrayRef ConstraintExprs,
   ArrayRef TemplateArgs,
   SourceRange TemplateIDRange, ConstraintSatisfaction );
 
@@ -6301,6 +6301,17 @@ class Sema final {
   bool CheckConstraintSatisfaction(const Expr *ConstraintExpr,
ConstraintSatisfaction );
 
+  /// Check whether the given function decl's trailing requires clause is
+  /// satisfied, if any. Returns false and updates Satisfaction with the
+  /// satisfaction verdict if successful, emits a diagnostic and returns true 
if
+  /// an error occured and satisfaction could not be determined.
+  ///
+  /// \returns true if an error occurred, false otherwise.
+  bool CheckFunctionConstraints(const FunctionDecl *FD,
+ConstraintSatisfaction ,
+SourceLocation UsageLoc = SourceLocation());
+
+
   /// \brief Ensure that the given template arguments satisfy the constraints
   /// associated with the given template, emitting a diagnostic if they do not.
   ///

diff  --git a/clang/lib/AST/ASTConcept.cpp b/clang/lib/AST/ASTConcept.cpp
index c28a06bdf0b2..549088ad4a8a 100644
--- 

[clang] f394d22 - [Concepts] Update cxx_status.html with Concepts support status

2020-01-23 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-24T03:00:38+02:00
New Revision: f394d22fa82df03eaf72bf1876e2d63bbe6cd00f

URL: 
https://github.com/llvm/llvm-project/commit/f394d22fa82df03eaf72bf1876e2d63bbe6cd00f
DIFF: 
https://github.com/llvm/llvm-project/commit/f394d22fa82df03eaf72bf1876e2d63bbe6cd00f.diff

LOG: [Concepts] Update cxx_status.html with Concepts support status

Concepts will be available with Clang 10 - update cxx_status.html to reflect
the papers that have been implemented.

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 50a9d000699c..606b8c956f16 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -871,7 +871,7 @@ C++2a implementation status
 
   Concepts
   https://wg21.link/p0734r0;>P0734R0
-  No
+  Clang 10
 

 https://wg21.link/p0857r0;>P0857R0
@@ -884,15 +884,18 @@ C++2a implementation status
   

 https://wg21.link/p0848r3;>P0848R3
+No
   
   
 https://wg21.link/p1616r1;>P1616R1
+Clang 10
   
   
 https://wg21.link/p1452r2;>P1452R2
   

 https://wg21.link/p1972r0;>P1972R0
+No
   
   
 https://wg21.link/p1980r0;>P1980R0



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 73eaf62 - [Concepts] Make constraint expressions unevaluated until satisfaction checking

2020-01-23 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-24T02:24:21+02:00
New Revision: 73eaf62463b4a29adf4194685af12d1a5d172987

URL: 
https://github.com/llvm/llvm-project/commit/73eaf62463b4a29adf4194685af12d1a5d172987
DIFF: 
https://github.com/llvm/llvm-project/commit/73eaf62463b4a29adf4194685af12d1a5d172987.diff

LOG: [Concepts] Make constraint expressions unevaluated until satisfaction 
checking

As per P1980R0, constraint expressions are unevaluated operands, and their 
constituent atomic
constraints only become constant evaluated during satisfaction checking.

Change the evaluation context during parsing and instantiation of constraints 
to unevaluated.

Added: 
clang/test/SemaTemplate/cxx2a-constraint-exprs.cpp

Modified: 
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index ba7525ecf527..e0c53df992e8 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -234,7 +234,7 @@ ExprResult Parser::ParseCaseExpression(SourceLocation 
CaseLoc) {
 /// \endverbatim
 ExprResult Parser::ParseConstraintExpression() {
   EnterExpressionEvaluationContext ConstantEvaluated(
-  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
+  Actions, Sema::ExpressionEvaluationContext::Unevaluated);
   ExprResult LHS(ParseCastExpression(AnyCastExpr));
   ExprResult Res(ParseRHSOfBinaryExpression(LHS, prec::LogicalOr));
   if (Res.isUsable() && !Actions.CheckConstraintExpression(Res.get())) {
@@ -256,7 +256,7 @@ ExprResult Parser::ParseConstraintExpression() {
 ExprResult
 Parser::ParseConstraintLogicalAndExpression(bool IsTrailingRequiresClause) {
   EnterExpressionEvaluationContext ConstantEvaluated(
-  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
+  Actions, Sema::ExpressionEvaluationContext::Unevaluated);
   bool NotPrimaryExpression = false;
   auto ParsePrimary = [&] () {
 ExprResult E = ParseCastExpression(PrimaryExprOnly,

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 92f6e0dc1c90..fbbab8f00703 100755
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1849,7 +1849,7 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
   Expr *TrailingRequiresClause = D->getTrailingRequiresClause();
   if (TrailingRequiresClause) {
 EnterExpressionEvaluationContext ConstantEvaluated(
-SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
+SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
 ExprResult SubstRC = SemaRef.SubstExpr(TrailingRequiresClause,
TemplateArgs);
 if (SubstRC.isInvalid())
@@ -2189,7 +2189,7 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl(
   Expr *TrailingRequiresClause = D->getTrailingRequiresClause();
   if (TrailingRequiresClause) {
 EnterExpressionEvaluationContext ConstantEvaluated(
-SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
+SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
 ExprResult SubstRC = SemaRef.SubstExpr(TrailingRequiresClause,
TemplateArgs);
 if (SubstRC.isInvalid())
@@ -2529,8 +2529,6 @@ Decl *TemplateDeclInstantiator::VisitTemplateTypeParmDecl(
 TemplateArgumentListInfo InstArgs;
 
 if (TemplArgInfo) {
-  EnterExpressionEvaluationContext ConstantEvaluated(
-SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
   InstArgs.setLAngleLoc(TemplArgInfo->LAngleLoc);
   InstArgs.setRAngleLoc(TemplArgInfo->RAngleLoc);
   if (SemaRef.Subst(TemplArgInfo->getTemplateArgs(),
@@ -3736,7 +3734,7 @@ 
TemplateDeclInstantiator::SubstTemplateParams(TemplateParameterList *L) {
   Expr *InstRequiresClause = nullptr;
   if (Expr *E = L->getRequiresClause()) {
 EnterExpressionEvaluationContext ConstantEvaluated(
-SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
+SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
 ExprResult Res = SemaRef.SubstExpr(E, TemplateArgs);
 if (Res.isInvalid() || !Res.isUsable()) {
   return nullptr;

diff  --git 
a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp 
b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
index bc093a0fc50e..b45b57f6b924 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
@@ -39,8 +39,9 @@ namespace std_example {
   using dc1 = D_check; // expected-error{{constraints not satisfied for 
class template 'D_check' [with T = short]}}
 
   template
-  concept C2 = requires (T a) { // 

[clang] 67c608a - [Concepts] Deprecate -fconcepts-ts, enable Concepts under -std=c++2a

2020-01-23 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-24T00:48:59+02:00
New Revision: 67c608a9695496cfc9d3fdf9d0b12b554ac6b4df

URL: 
https://github.com/llvm/llvm-project/commit/67c608a9695496cfc9d3fdf9d0b12b554ac6b4df
DIFF: 
https://github.com/llvm/llvm-project/commit/67c608a9695496cfc9d3fdf9d0b12b554ac6b4df.diff

LOG: [Concepts] Deprecate -fconcepts-ts, enable Concepts under -std=c++2a

Now with concepts support merged and mostly complete, we do not need 
-fconcepts-ts
(which was also misleading as we were not implementing the TS) and can enable
concepts features under C++2a. A warning will be generated if users still 
attempt
to use -fconcepts-ts.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/TokenKinds.def
clang/include/clang/Driver/CC1Options.td
clang/lib/AST/DeclTemplate.cpp
clang/lib/Basic/IdentifierTable.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Parse/ParseTemplate.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CXX/class.derived/class.virtual/p6.cpp
clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
clang/test/CXX/dcl/dcl.decl/p3.cpp
clang/test/CXX/dcl/dcl.fct/p17.cpp
clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
clang/test/CXX/expr/expr.prim/expr.prim.id/mixed-constraints.cpp
clang/test/CXX/expr/expr.prim/expr.prim.id/p4.cpp

clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.closure/p3.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/equivalence.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/p3.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/requires-expr.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/type-requirement.cpp
clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
clang/test/CXX/over/over.match/over.match.viable/p3.cpp
clang/test/CXX/over/over.over/p4-2a.cpp
clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
clang/test/CXX/temp/temp.constr/temp.constr.constr/function-templates.cpp

clang/test/CXX/temp/temp.constr/temp.constr.constr/non-function-templates.cpp

clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
clang/test/CXX/temp/temp.constr/temp.constr.decl/class-template-decl.cpp
clang/test/CXX/temp/temp.constr/temp.constr.decl/p3.cpp
clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp

clang/test/CXX/temp/temp.constr/temp.constr.order/class-template-partial-specializations.cpp
clang/test/CXX/temp/temp.constr/temp.constr.order/function-templates.cpp

clang/test/CXX/temp/temp.constr/temp.constr.order/var-template-partial-specializations.cpp
clang/test/CXX/temp/temp.explicit/p8.cpp
clang/test/CXX/temp/temp.param/p10-2a.cpp
clang/test/CodeGenCXX/mangle-concept.cpp
clang/test/Lexer/cxx-features.cpp
clang/test/Lexer/keywords_test.cpp
clang/test/PCH/cxx2a-requires-expr.cpp
clang/test/Parser/cxx-concept-declaration.cpp
clang/test/Parser/cxx-concepts-ambig-constraint-expr.cpp
clang/test/Parser/cxx-concepts-requires-clause.cpp
clang/test/Parser/cxx2a-concept-declaration.cpp
clang/test/Parser/cxx2a-concepts-requires-expr.cpp
clang/test/Parser/cxx2a-constrained-template-param-with-partial-id.cpp
clang/test/Parser/cxx2a-constrained-template-param.cpp
clang/test/Parser/cxx2a-placeholder-type-constraint.cpp
clang/test/SemaTemplate/cxx2a-constraint-caching.cpp
clang/test/SemaTemplate/instantiate-expanded-type-constraint.cpp
clang/test/SemaTemplate/instantiate-requires-clause.cpp
clang/test/SemaTemplate/instantiate-requires-expr.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index a798b498d4e9..ed2092fb4c84 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -105,6 +105,9 @@ def err_fe_invalid_wchar_type
 : Error<"invalid wchar_t type '%0'; must be one of 'char', 'short', 
'int'">;
 def err_fe_invalid_exception_model
: Error<"invalid exception model '%0' for target '%1'">;
+def warn_fe_concepts_ts_flag : Warning<
+  "-fconcepts-ts is deprecated - use '-std=c++2a' for Concepts support">,
+  InGroup;
 
 def warn_fe_serialized_diag_merge_failure : Warning<
 "unable to merge a subprocess's serialized diagnostics">,

diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index b8112eb26913..3319a3123976 100644
--- 

[clang] d42d5eb - [Concepts] Implement P1616R1 - Using unconstrained template template parameters with constrained templates

2020-01-23 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-23T23:32:03+02:00
New Revision: d42d5eb8ea77b3a3a502a60ba3f053fb81a897f3

URL: 
https://github.com/llvm/llvm-project/commit/d42d5eb8ea77b3a3a502a60ba3f053fb81a897f3
DIFF: 
https://github.com/llvm/llvm-project/commit/d42d5eb8ea77b3a3a502a60ba3f053fb81a897f3.diff

LOG: [Concepts] Implement P1616R1 - Using unconstrained template template 
parameters with constrained templates

Summary: Allow unconstrained template template parameters to accept 
constrainted templates as arguments.

Reviewers: rsmith

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73155

Added: 


Modified: 
clang/lib/Sema/SemaTemplate.cpp
clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 2f44f8f08d08..05dde46fffd3 100755
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -7164,6 +7164,11 @@ bool 
Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
   //   [temp.constr.order].
   SmallVector ParamsAC, TemplateAC;
   Params->getAssociatedConstraints(ParamsAC);
+  // C++2a[temp.arg.template]p3
+  //   [...] In this comparison, if P is unconstrained, the constraints on 
A
+  //   are not considered.
+  if (ParamsAC.empty())
+return false;
   Template->getAssociatedConstraints(TemplateAC);
   bool IsParamAtLeastAsConstrained;
   if (IsAtLeastAsConstrained(Param, ParamsAC, Template, TemplateAC,

diff  --git a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp 
b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
index 593336163fa1..e7feae31889e 100644
--- a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
+++ b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
@@ -7,9 +7,9 @@ template concept F = T::f();
 // expected-note@-1{{similar constraint expressions not considered equivalent}}
 template class P> struct S1 { }; // expected-note 2{{'P' declared 
here}}
 
-template struct X { }; // expected-note{{'X' declared here}}
+template struct X { };
 
-template struct Y { }; // expected-note 2{{'Y' declared here}}
+template struct Y { }; // expected-note{{'Y' declared here}}
 template struct Z { };
 template struct W { }; // expected-note{{'W' declared here}}
 
@@ -18,10 +18,10 @@ S1 s12; // expected-error{{template template argument 
'Y' is more constrained
 S1 s13;
 S1 s14; // expected-error{{template template argument 'W' is more 
constrained than template template parameter 'P'}}
 
-template class P> struct S2 { }; // expected-note 2{{'P' 
declared here}}
+template class P> struct S2 { };
 
-S2 s21; // expected-error{{template template argument 'X' is more 
constrained than template template parameter 'P'}}
-S2 s22; // expected-error{{template template argument 'Y' is more 
constrained than template template parameter 'P'}}
+S2 s21;
+S2 s22;
 S2 s23;
 
 template  class C>



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4d33a8d - [Concepts] Add ExpressionEvaluationContexts to instantiation of constraints

2020-01-23 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-23T23:24:56+02:00
New Revision: 4d33a8dfcf67e970ea4d150d514b27de02e79aee

URL: 
https://github.com/llvm/llvm-project/commit/4d33a8dfcf67e970ea4d150d514b27de02e79aee
DIFF: 
https://github.com/llvm/llvm-project/commit/4d33a8dfcf67e970ea4d150d514b27de02e79aee.diff

LOG: [Concepts] Add ExpressionEvaluationContexts to instantiation of constraints

Proper ExpressionEvaluationContext were not being entered when instantiating 
constraint
expressions, which caused assertion failures in certain cases, including bug 
#44614.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/instantiate-requires-clause.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 8fd7491c45e3..92f6e0dc1c90 100755
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1848,6 +1848,8 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
   // FIXME: Concepts: Do not substitute into constraint expressions
   Expr *TrailingRequiresClause = D->getTrailingRequiresClause();
   if (TrailingRequiresClause) {
+EnterExpressionEvaluationContext ConstantEvaluated(
+SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
 ExprResult SubstRC = SemaRef.SubstExpr(TrailingRequiresClause,
TemplateArgs);
 if (SubstRC.isInvalid())
@@ -2186,6 +2188,8 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl(
   // FIXME: Concepts: Do not substitute into constraint expressions
   Expr *TrailingRequiresClause = D->getTrailingRequiresClause();
   if (TrailingRequiresClause) {
+EnterExpressionEvaluationContext ConstantEvaluated(
+SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
 ExprResult SubstRC = SemaRef.SubstExpr(TrailingRequiresClause,
TemplateArgs);
 if (SubstRC.isInvalid())
@@ -2525,6 +2529,8 @@ Decl *TemplateDeclInstantiator::VisitTemplateTypeParmDecl(
 TemplateArgumentListInfo InstArgs;
 
 if (TemplArgInfo) {
+  EnterExpressionEvaluationContext ConstantEvaluated(
+SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
   InstArgs.setLAngleLoc(TemplArgInfo->LAngleLoc);
   InstArgs.setRAngleLoc(TemplArgInfo->RAngleLoc);
   if (SemaRef.Subst(TemplArgInfo->getTemplateArgs(),
@@ -3729,6 +3735,8 @@ 
TemplateDeclInstantiator::SubstTemplateParams(TemplateParameterList *L) {
   // checking satisfaction.
   Expr *InstRequiresClause = nullptr;
   if (Expr *E = L->getRequiresClause()) {
+EnterExpressionEvaluationContext ConstantEvaluated(
+SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
 ExprResult Res = SemaRef.SubstExpr(E, TemplateArgs);
 if (Res.isInvalid() || !Res.isUsable()) {
   return nullptr;

diff  --git a/clang/test/SemaTemplate/instantiate-requires-clause.cpp 
b/clang/test/SemaTemplate/instantiate-requires-clause.cpp
index 04b595717e6d..3b7dc3ddd740 100644
--- a/clang/test/SemaTemplate/instantiate-requires-clause.cpp
+++ b/clang/test/SemaTemplate/instantiate-requires-clause.cpp
@@ -39,3 +39,15 @@ struct S {
 };
 
 static_assert(S::f(1));
+
+constexpr auto value = 0;
+
+template
+struct S2 {
+  template requires(value, true)
+  static constexpr auto f() requires(value, true) {
+  }
+};
+
+static_assert((S2::f(), true));
+



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 62c221b - [Concepts] Profile TypeConstraints in ProfileTemplateParameterList

2020-01-23 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-23T09:59:51+02:00
New Revision: 62c221b5090c2e1d3ca408bcab6f69c4d9e175b7

URL: 
https://github.com/llvm/llvm-project/commit/62c221b5090c2e1d3ca408bcab6f69c4d9e175b7
DIFF: 
https://github.com/llvm/llvm-project/commit/62c221b5090c2e1d3ca408bcab6f69c4d9e175b7.diff

LOG: [Concepts] Profile TypeConstraints in ProfileTemplateParameterList

Profile TypeConstraints in ProfileTemplateParameterList so we can distinguish
between partial specializations which differ in their TemplateParameterList
type constraints.

Recommit, now profiling the IDC so that we can deal with situations where the
TemplateArgsAsWritten are nullptr (happens when canonicalizing type 
constraints).

Added: 


Modified: 
clang/lib/AST/DeclTemplate.cpp

clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp

Removed: 




diff  --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index e750bb8b6af7..9bd3b64feb4e 100755
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -488,7 +488,10 @@ static void ProfileTemplateParameterList(ASTContext ,
 if (const auto *TTP = dyn_cast(D)) {
   ID.AddInteger(1);
   ID.AddBoolean(TTP->isParameterPack());
-  // TODO: Concepts: profile type-constraints.
+  ID.AddBoolean(TTP->hasTypeConstraint());
+  if (const TypeConstraint *TC = TTP->getTypeConstraint())
+TC->getImmediatelyDeclaredConstraint()->Profile(ID, C,
+/*Canonical=*/true);
   continue;
 }
 const auto *TTP = cast(D);

diff  --git 
a/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
 
b/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
index 1ea4da29ee9f..9f3c21f99174 100644
--- 
a/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
+++ 
b/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
@@ -31,6 +31,23 @@ namespace class_templates
   // expected-note@-2{{during template argument deduction for class template 
partial specialization 'B' [with T = int *]}}
   // expected-note@-3{{during template argument deduction for class template 
partial specialization 'B' [with T = int]}}
   // expected-note@-4 2{{in instantiation of template class 
'class_templates::B' requested here}}
+
+  template
+  concept same_as = is_same::value;
+
+  template T> requires A::type
+  struct B {};
+  // expected-note@-1{{previous}}
+
+  template T> requires A::type
+  struct B {};
+  // expected-error@-1{{redefinition}}
+
+  template requires A::type
+  struct B {};
+
+  template T> requires A::type
+  struct B {};
 }
 
 namespace variable_templates



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c985e7b - Revert "[Concepts] Profile TypeConstraints in ProfileTemplateParameterList"

2020-01-22 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-23T09:57:20+02:00
New Revision: c985e7b07db2660b14508d3da45d55f3d4490019

URL: 
https://github.com/llvm/llvm-project/commit/c985e7b07db2660b14508d3da45d55f3d4490019
DIFF: 
https://github.com/llvm/llvm-project/commit/c985e7b07db2660b14508d3da45d55f3d4490019.diff

LOG: Revert "[Concepts] Profile TypeConstraints in ProfileTemplateParameterList"

This temporarily reverts commit 0e3ae353a47273825cd2f20f4777dcb5731cf8ec because
of a potential bug.

Added: 


Modified: 
clang/lib/AST/DeclTemplate.cpp

clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp

Removed: 




diff  --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index 02296d8aea16..e750bb8b6af7 100755
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -488,15 +488,7 @@ static void ProfileTemplateParameterList(ASTContext ,
 if (const auto *TTP = dyn_cast(D)) {
   ID.AddInteger(1);
   ID.AddBoolean(TTP->isParameterPack());
-  ID.AddBoolean(TTP->hasTypeConstraint());
-  if (const TypeConstraint *TC = TTP->getTypeConstraint()) {
-ID.AddPointer(TC->getNamedConcept()->getCanonicalDecl());
-ID.AddBoolean(TC->hasExplicitTemplateArgs());
-if (TC->hasExplicitTemplateArgs()) {
-  for (const auto  : TC->getTemplateArgsAsWritten()->arguments())
-Arg.getArgument().Profile(ID, C);
-}
-  }
+  // TODO: Concepts: profile type-constraints.
   continue;
 }
 const auto *TTP = cast(D);

diff  --git 
a/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
 
b/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
index 9f3c21f99174..1ea4da29ee9f 100644
--- 
a/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
+++ 
b/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
@@ -31,23 +31,6 @@ namespace class_templates
   // expected-note@-2{{during template argument deduction for class template 
partial specialization 'B' [with T = int *]}}
   // expected-note@-3{{during template argument deduction for class template 
partial specialization 'B' [with T = int]}}
   // expected-note@-4 2{{in instantiation of template class 
'class_templates::B' requested here}}
-
-  template
-  concept same_as = is_same::value;
-
-  template T> requires A::type
-  struct B {};
-  // expected-note@-1{{previous}}
-
-  template T> requires A::type
-  struct B {};
-  // expected-error@-1{{redefinition}}
-
-  template requires A::type
-  struct B {};
-
-  template T> requires A::type
-  struct B {};
 }
 
 namespace variable_templates



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0e3ae35 - [Concepts] Profile TypeConstraints in ProfileTemplateParameterList

2020-01-22 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-23T09:47:55+02:00
New Revision: 0e3ae353a47273825cd2f20f4777dcb5731cf8ec

URL: 
https://github.com/llvm/llvm-project/commit/0e3ae353a47273825cd2f20f4777dcb5731cf8ec
DIFF: 
https://github.com/llvm/llvm-project/commit/0e3ae353a47273825cd2f20f4777dcb5731cf8ec.diff

LOG: [Concepts] Profile TypeConstraints in ProfileTemplateParameterList

Profile TypeConstraints in ProfileTemplateParameterList so we can distinguish
between partial specializations which differ in their TemplateParameterList
type constraints

Added: 


Modified: 
clang/lib/AST/DeclTemplate.cpp

clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp

Removed: 




diff  --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index e750bb8b6af7..02296d8aea16 100755
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -488,7 +488,15 @@ static void ProfileTemplateParameterList(ASTContext ,
 if (const auto *TTP = dyn_cast(D)) {
   ID.AddInteger(1);
   ID.AddBoolean(TTP->isParameterPack());
-  // TODO: Concepts: profile type-constraints.
+  ID.AddBoolean(TTP->hasTypeConstraint());
+  if (const TypeConstraint *TC = TTP->getTypeConstraint()) {
+ID.AddPointer(TC->getNamedConcept()->getCanonicalDecl());
+ID.AddBoolean(TC->hasExplicitTemplateArgs());
+if (TC->hasExplicitTemplateArgs()) {
+  for (const auto  : TC->getTemplateArgsAsWritten()->arguments())
+Arg.getArgument().Profile(ID, C);
+}
+  }
   continue;
 }
 const auto *TTP = cast(D);

diff  --git 
a/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
 
b/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
index 1ea4da29ee9f..9f3c21f99174 100644
--- 
a/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
+++ 
b/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
@@ -31,6 +31,23 @@ namespace class_templates
   // expected-note@-2{{during template argument deduction for class template 
partial specialization 'B' [with T = int *]}}
   // expected-note@-3{{during template argument deduction for class template 
partial specialization 'B' [with T = int]}}
   // expected-note@-4 2{{in instantiation of template class 
'class_templates::B' requested here}}
+
+  template
+  concept same_as = is_same::value;
+
+  template T> requires A::type
+  struct B {};
+  // expected-note@-1{{previous}}
+
+  template T> requires A::type
+  struct B {};
+  // expected-error@-1{{redefinition}}
+
+  template requires A::type
+  struct B {};
+
+  template T> requires A::type
+  struct B {};
 }
 
 namespace variable_templates



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c2a250e - [Concepts] Fix bug when referencing function parameters in instantiated function template requires clause

2020-01-22 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-22T20:43:38+02:00
New Revision: c2a250e1c43c05925fe040dc9624403af7879453

URL: 
https://github.com/llvm/llvm-project/commit/c2a250e1c43c05925fe040dc9624403af7879453
DIFF: 
https://github.com/llvm/llvm-project/commit/c2a250e1c43c05925fe040dc9624403af7879453.diff

LOG: [Concepts] Fix bug when referencing function parameters in instantiated 
function template requires clause

Fixes bug #44613 - incorrect instantiated parameters were being added when 
checking instantiated function constraints

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/instantiate-requires-clause.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 2f2c06bb72de..8fd7491c45e3 100755
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4252,9 +4252,9 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints(
 MLTAL.getInnermost(), SourceRange());
 if (Inst.isInvalid())
   return true;
-if (addInstantiatedParametersToScope(*this, Decl,
-
Decl->getTemplateInstantiationPattern(),
- Scope, MLTAL))
+if (addInstantiatedParametersToScope(
+*this, Decl, Decl->getPrimaryTemplate()->getTemplatedDecl(),
+Scope, MLTAL))
   return true;
   }
 

diff  --git a/clang/test/SemaTemplate/instantiate-requires-clause.cpp 
b/clang/test/SemaTemplate/instantiate-requires-clause.cpp
index f36396b98db7..04b595717e6d 100644
--- a/clang/test/SemaTemplate/instantiate-requires-clause.cpp
+++ b/clang/test/SemaTemplate/instantiate-requires-clause.cpp
@@ -29,3 +29,13 @@ using f31 = decltype(f3('a'));
 using f32 = decltype(f3(1, 'b'));
 using f33 = decltype(f3(1, 'b', 2));
 // expected-error@-1 {{no matching function for call to 'f3'}}
+
+template
+struct S {
+   template
+   static constexpr auto f(U const index) requires(index, true) {
+   return true;
+   }
+};
+
+static_assert(S::f(1));



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7b81c3f - Revert "[Concepts] Fix bug when referencing function parameters in instantiated function template requires clause"

2020-01-22 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-22T12:16:35+02:00
New Revision: 7b81c3f8793d30a4285095a9b67dcfca2117916c

URL: 
https://github.com/llvm/llvm-project/commit/7b81c3f8793d30a4285095a9b67dcfca2117916c
DIFF: 
https://github.com/llvm/llvm-project/commit/7b81c3f8793d30a4285095a9b67dcfca2117916c.diff

LOG: Revert "[Concepts] Fix bug when referencing function parameters in 
instantiated function template requires clause"

This temporarily reverts commit 45538b5fb280e5b2903f7924fd4fa5b07a6dd3ea which 
breaks a test.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/instantiate-requires-clause.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 410e1f0f0984..2f2c06bb72de 100755
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1766,70 +1766,6 @@ Decl 
*TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) {
   return Record;
 }
 
-/// Introduce the instantiated function parameters into the local
-/// instantiation scope, and set the parameter names to those used
-/// in the template.
-static bool addInstantiatedParametersToScope(Sema , FunctionDecl *Function,
- const FunctionDecl *PatternDecl,
- LocalInstantiationScope ,
-   const MultiLevelTemplateArgumentList ) 
{
-  unsigned FParamIdx = 0;
-  for (unsigned I = 0, N = PatternDecl->getNumParams(); I != N; ++I) {
-const ParmVarDecl *PatternParam = PatternDecl->getParamDecl(I);
-if (!PatternParam->isParameterPack()) {
-  // Simple case: not a parameter pack.
-  assert(FParamIdx < Function->getNumParams());
-  ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx);
-  FunctionParam->setDeclName(PatternParam->getDeclName());
-  // If the parameter's type is not dependent, update it to match the type
-  // in the pattern. They can 
diff er in top-level cv-qualifiers, and we want
-  // the pattern's type here. If the type is dependent, they can't 
diff er,
-  // per core issue 1668. Substitute into the type from the pattern, in 
case
-  // it's instantiation-dependent.
-  // FIXME: Updating the type to work around this is at best fragile.
-  if (!PatternDecl->getType()->isDependentType()) {
-QualType T = S.SubstType(PatternParam->getType(), TemplateArgs,
- FunctionParam->getLocation(),
- FunctionParam->getDeclName());
-if (T.isNull())
-  return true;
-FunctionParam->setType(T);
-  }
-
-  Scope.InstantiatedLocal(PatternParam, FunctionParam);
-  ++FParamIdx;
-  continue;
-}
-
-// Expand the parameter pack.
-Scope.MakeInstantiatedLocalArgPack(PatternParam);
-Optional NumArgumentsInExpansion
-  = S.getNumArgumentsInExpansion(PatternParam->getType(), TemplateArgs);
-if (NumArgumentsInExpansion) {
-  QualType PatternType =
-  PatternParam->getType()->castAs()->getPattern();
-  for (unsigned Arg = 0; Arg < *NumArgumentsInExpansion; ++Arg) {
-ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx);
-FunctionParam->setDeclName(PatternParam->getDeclName());
-if (!PatternDecl->getType()->isDependentType()) {
-  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(S, Arg);
-  QualType T = S.SubstType(PatternType, TemplateArgs,
-   FunctionParam->getLocation(),
-   FunctionParam->getDeclName());
-  if (T.isNull())
-return true;
-  FunctionParam->setType(T);
-}
-
-Scope.InstantiatedLocalPackArg(PatternParam, FunctionParam);
-++FParamIdx;
-  }
-}
-  }
-
-  return false;
-}
-
 /// Adjust the given function type for an instantiation of the
 /// given declaration, to cope with modifications to the function's type that
 /// aren't reflected in the type-source information.
@@ -1912,11 +1848,6 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
   // FIXME: Concepts: Do not substitute into constraint expressions
   Expr *TrailingRequiresClause = D->getTrailingRequiresClause();
   if (TrailingRequiresClause) {
-if (D->isTemplateInstantiation() &&
-addInstantiatedParametersToScope(
-SemaRef, D, D->getTemplateInstantiationPattern(), Scope,
-TemplateArgs))
-  return nullptr;
 ExprResult SubstRC = SemaRef.SubstExpr(TrailingRequiresClause,
TemplateArgs);
 if (SubstRC.isInvalid())
@@ -4184,6 +4115,70 @@ TemplateDeclInstantiator::SubstFunctionType(FunctionDecl 
*D,
   return NewTInfo;
 }
 
+/// Introduce the instantiated function 

[clang] 45538b5 - [Concepts] Fix bug when referencing function parameters in instantiated function template requires clause

2020-01-22 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-22T11:25:27+02:00
New Revision: 45538b5fb280e5b2903f7924fd4fa5b07a6dd3ea

URL: 
https://github.com/llvm/llvm-project/commit/45538b5fb280e5b2903f7924fd4fa5b07a6dd3ea
DIFF: 
https://github.com/llvm/llvm-project/commit/45538b5fb280e5b2903f7924fd4fa5b07a6dd3ea.diff

LOG: [Concepts] Fix bug when referencing function parameters in instantiated 
function template requires clause

Fixes bug #44613 - instantiated parameters were not being added when 
instantiating the requires clauses.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/instantiate-requires-clause.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index a470cfc87440..bdea54de2414 100755
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1766,6 +1766,70 @@ Decl 
*TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) {
   return Record;
 }
 
+/// Introduce the instantiated function parameters into the local
+/// instantiation scope, and set the parameter names to those used
+/// in the template.
+static bool addInstantiatedParametersToScope(Sema , FunctionDecl *Function,
+ const FunctionDecl *PatternDecl,
+ LocalInstantiationScope ,
+   const MultiLevelTemplateArgumentList ) 
{
+  unsigned FParamIdx = 0;
+  for (unsigned I = 0, N = PatternDecl->getNumParams(); I != N; ++I) {
+const ParmVarDecl *PatternParam = PatternDecl->getParamDecl(I);
+if (!PatternParam->isParameterPack()) {
+  // Simple case: not a parameter pack.
+  assert(FParamIdx < Function->getNumParams());
+  ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx);
+  FunctionParam->setDeclName(PatternParam->getDeclName());
+  // If the parameter's type is not dependent, update it to match the type
+  // in the pattern. They can 
diff er in top-level cv-qualifiers, and we want
+  // the pattern's type here. If the type is dependent, they can't 
diff er,
+  // per core issue 1668. Substitute into the type from the pattern, in 
case
+  // it's instantiation-dependent.
+  // FIXME: Updating the type to work around this is at best fragile.
+  if (!PatternDecl->getType()->isDependentType()) {
+QualType T = S.SubstType(PatternParam->getType(), TemplateArgs,
+ FunctionParam->getLocation(),
+ FunctionParam->getDeclName());
+if (T.isNull())
+  return true;
+FunctionParam->setType(T);
+  }
+
+  Scope.InstantiatedLocal(PatternParam, FunctionParam);
+  ++FParamIdx;
+  continue;
+}
+
+// Expand the parameter pack.
+Scope.MakeInstantiatedLocalArgPack(PatternParam);
+Optional NumArgumentsInExpansion
+  = S.getNumArgumentsInExpansion(PatternParam->getType(), TemplateArgs);
+if (NumArgumentsInExpansion) {
+  QualType PatternType =
+  PatternParam->getType()->castAs()->getPattern();
+  for (unsigned Arg = 0; Arg < *NumArgumentsInExpansion; ++Arg) {
+ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx);
+FunctionParam->setDeclName(PatternParam->getDeclName());
+if (!PatternDecl->getType()->isDependentType()) {
+  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(S, Arg);
+  QualType T = S.SubstType(PatternType, TemplateArgs,
+   FunctionParam->getLocation(),
+   FunctionParam->getDeclName());
+  if (T.isNull())
+return true;
+  FunctionParam->setType(T);
+}
+
+Scope.InstantiatedLocalPackArg(PatternParam, FunctionParam);
+++FParamIdx;
+  }
+}
+  }
+
+  return false;
+}
+
 /// Adjust the given function type for an instantiation of the
 /// given declaration, to cope with modifications to the function's type that
 /// aren't reflected in the type-source information.
@@ -1848,6 +1912,11 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
   // FIXME: Concepts: Do not substitute into constraint expressions
   Expr *TrailingRequiresClause = D->getTrailingRequiresClause();
   if (TrailingRequiresClause) {
+if (D->isTemplateInstantiation() &&
+addInstantiatedParametersToScope(
+SemaRef, D, D->getTemplateInstantiationPattern(), Scope,
+TemplateArgs))
+  return nullptr;
 ExprResult SubstRC = SemaRef.SubstExpr(TrailingRequiresClause,
TemplateArgs);
 if (SubstRC.isInvalid())
@@ -4105,70 +4174,6 @@ TemplateDeclInstantiator::SubstFunctionType(FunctionDecl 
*D,
   return NewTInfo;
 }
 
-/// Introduce the instantiated function 

[clang] de51559 - [Concepts] Fix incorrect recovery in TryAnnotateTypeConstraint

2020-01-22 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-22T10:50:53+02:00
New Revision: de51559fa68049da73b696a4e89468154b12852a

URL: 
https://github.com/llvm/llvm-project/commit/de51559fa68049da73b696a4e89468154b12852a
DIFF: 
https://github.com/llvm/llvm-project/commit/de51559fa68049da73b696a4e89468154b12852a.diff

LOG: [Concepts] Fix incorrect recovery in TryAnnotateTypeConstraint

TryAnnotateTypeConstraint would not put the scope specifier back into the token 
stream when faced
with a non-concept name after a scope specifier.

Added: 


Modified: 
clang/lib/Parse/ParseTemplate.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index 0f7aefaa147a..2ac8be430c31 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -712,8 +712,11 @@ bool Parser::TryAnnotateTypeConstraint() {
   MemberOfUnknownSpecialization);
 assert(!MemberOfUnknownSpecialization
&& "Member when we only allowed namespace scope qualifiers??");
-if (!PossibleConcept || TNK != TNK_Concept_template)
+if (!PossibleConcept || TNK != TNK_Concept_template) {
+  if (SS.isNotEmpty())
+AnnotateScopeToken(SS, !WasScopeAnnotation);
   return false;
+}
 
 // At this point we're sure we're dealing with a constrained parameter. It
 // may or may not have a template parameter list following the concept



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] bb9b964 - [Concepts] Fix circular AST->Sema dependency in ASTConcept.cpp

2020-01-21 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-22T04:08:59+02:00
New Revision: bb9b964072eb42a09e76fe148b36eefcfff077b2

URL: 
https://github.com/llvm/llvm-project/commit/bb9b964072eb42a09e76fe148b36eefcfff077b2
DIFF: 
https://github.com/llvm/llvm-project/commit/bb9b964072eb42a09e76fe148b36eefcfff077b2.diff

LOG: [Concepts] Fix circular AST->Sema dependency in ASTConcept.cpp

Remove inappropriate Sema include in ASTConcept.cpp introduced by D72552 for 
the finer-grained includes actually needed.

Added: 


Modified: 
clang/lib/AST/ASTConcept.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTConcept.cpp b/clang/lib/AST/ASTConcept.cpp
index 66d272da7049..c28a06bdf0b2 100644
--- a/clang/lib/AST/ASTConcept.cpp
+++ b/clang/lib/AST/ASTConcept.cpp
@@ -14,7 +14,10 @@
 
 #include "clang/AST/ASTConcept.h"
 #include "clang/AST/ASTContext.h"
-#include "clang/Sema/SemaConcept.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/TemplateBase.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/FoldingSet.h"
 using namespace clang;
 
 ASTConstraintSatisfaction::ASTConstraintSatisfaction(const ASTContext ,



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b933d37 - [Concepts] Constraint Satisfaction Caching

2020-01-21 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-22T03:09:53+02:00
New Revision: b933d37cd3774e5431b35e82187eebb59b1ff59e

URL: 
https://github.com/llvm/llvm-project/commit/b933d37cd3774e5431b35e82187eebb59b1ff59e
DIFF: 
https://github.com/llvm/llvm-project/commit/b933d37cd3774e5431b35e82187eebb59b1ff59e.diff

LOG: [Concepts] Constraint Satisfaction Caching

Add a simple cache for constraint satisfaction results. Whether or not this 
simple caching
would be permitted in final C++2a is currently being discussed but it is 
required for
acceptable performance so we use it in the meantime, with the possibility of 
adding some
cache invalidation mechanisms later.

Differential Revision: https://reviews.llvm.org/D72552

Added: 
clang/test/SemaTemplate/cxx2a-constraint-caching.cpp

Modified: 
clang/include/clang/AST/ASTConcept.h
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/CC1Options.td
clang/include/clang/Sema/Sema.h
clang/include/clang/Sema/TemplateDeduction.h
clang/lib/AST/ASTConcept.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaConcept.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTConcept.h 
b/clang/include/clang/AST/ASTConcept.h
index 84a611c14e0b..30c4706d2a15 100644
--- a/clang/include/clang/AST/ASTConcept.h
+++ b/clang/include/clang/AST/ASTConcept.h
@@ -24,9 +24,23 @@ namespace clang {
 class ConceptDecl;
 class ConceptSpecializationExpr;
 
-/// \brief The result of a constraint satisfaction check, containing the
-/// necessary information to diagnose an unsatisfied constraint.
-struct ConstraintSatisfaction {
+/// The result of a constraint satisfaction check, containing the necessary
+/// information to diagnose an unsatisfied constraint.
+class ConstraintSatisfaction : public llvm::FoldingSetNode {
+  // The template-like entity that 'owns' the constraint checked here (can be a
+  // constrained entity or a concept).
+  NamedDecl *ConstraintOwner = nullptr;
+  llvm::SmallVector TemplateArgs;
+
+public:
+
+  ConstraintSatisfaction() = default;
+
+  ConstraintSatisfaction(NamedDecl *ConstraintOwner,
+ ArrayRef TemplateArgs) :
+  ConstraintOwner(ConstraintOwner), TemplateArgs(TemplateArgs.begin(),
+ TemplateArgs.end()) { }
+
   using SubstitutionDiagnostic = std::pair;
   using Detail = llvm::PointerUnion;
 
@@ -38,9 +52,13 @@ struct ConstraintSatisfaction {
   /// invalid expression.
   llvm::SmallVector, 4> Details;
 
-  // This can leak if used in an AST node, use ASTConstraintSatisfaction
-  // instead.
-  void *operator new(size_t bytes, ASTContext ) = delete;
+  void Profile(llvm::FoldingSetNodeID , const ASTContext ) {
+Profile(ID, C, ConstraintOwner, TemplateArgs);
+  }
+
+  static void Profile(llvm::FoldingSetNodeID , const ASTContext ,
+  NamedDecl *ConstraintOwner,
+  ArrayRef TemplateArgs);
 };
 
 /// Pairs of unsatisfied atomic constraint expressions along with the

diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 068f206f4484..b8112eb26913 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -238,6 +238,7 @@ LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
 LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are 
unavailable")
 LANGOPT(NewAlignOverride  , 32, 0, "maximum alignment guaranteed by 
'::operator new(size_t)'")
 LANGOPT(ConceptsTS , 1, 0, "enable C++ Extensions for Concepts")
+LANGOPT(ConceptSatisfactionCaching , 1, 1, "enable satisfaction caching for 
C++2a Concepts")
 BENIGN_LANGOPT(ModulesCodegen , 1, 0, "Modules code generation")
 BENIGN_LANGOPT(ModulesDebugInfo , 1, 0, "Modules debug info")
 BENIGN_LANGOPT(ElideConstructors , 1, 1, "C++ copy constructor elision")

diff  --git a/clang/include/clang/Driver/CC1Options.td 
b/clang/include/clang/Driver/CC1Options.td
index deb588fa256e..9d6b381a32a1 100644
--- a/clang/include/clang/Driver/CC1Options.td
+++ b/clang/include/clang/Driver/CC1Options.td
@@ -557,6 +557,9 @@ def ftest_module_file_extension_EQ :
"The argument is parsed as blockname:major:minor:hashed:user info">;
 def fconcepts_ts : Flag<["-"], "fconcepts-ts">,
   HelpText<"Enable C++ Extensions for Concepts.">;
+def fno_concept_satisfaction_caching : Flag<["-"],
+
"fno-concept-satisfaction-caching">,
+  HelpText<"Disable satisfaction caching for C++2a Concepts.">;
 
 let Group = Action_Group in {
 

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 7dfc11315ddd..ebd24b0d71da 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -6232,6 +6232,9 @@ class Sema final {
   llvm::DenseMap
   

[clang-tools-extra] 5fdad8e - [clang-tidy] Fix check for generic lambda invented template parameters

2020-01-21 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-22T02:46:39+02:00
New Revision: 5fdad8e3f803adce501ca25118f325184e54018d

URL: 
https://github.com/llvm/llvm-project/commit/5fdad8e3f803adce501ca25118f325184e54018d
DIFF: 
https://github.com/llvm/llvm-project/commit/5fdad8e3f803adce501ca25118f325184e54018d.diff

LOG: [clang-tidy] Fix check for generic lambda invented template parameters

clang-tidy previously relied on there being no identifier for a 
TemplateTypeParmDecl for checking
whether 'decltype(x)' should be inserted, instead of checking whether or not it 
is implicit.

D65042 added new names for invented generic lambda template parameters, 
rendering that check incorrect.

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp
index bf6f2f6ed035..8953f95159a9 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp
@@ -33,7 +33,7 @@ static void replaceMoveWithForward(const UnresolvedLookupExpr 
*Callee,
 
   if (CallRange.isValid()) {
 const std::string TypeName =
-TypeParmDecl->getIdentifier()
+(TypeParmDecl->getIdentifier() && !TypeParmDecl->isImplicit())
 ? TypeParmDecl->getName().str()
 : (llvm::Twine("decltype(") + ParmVar->getName() + ")").str();
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e68c1e0 - [Concepts] Fix name-type conflict compilation issues

2020-01-18 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-19T00:45:25+02:00
New Revision: e68c1e00eba4ae64d38e62eebebd581e3d3d6bd4

URL: 
https://github.com/llvm/llvm-project/commit/e68c1e00eba4ae64d38e62eebebd581e3d3d6bd4
DIFF: 
https://github.com/llvm/llvm-project/commit/e68c1e00eba4ae64d38e62eebebd581e3d3d6bd4.diff

LOG: [Concepts] Fix name-type conflict compilation issues

D50360 caused some platforms to not compile due to a parameter with the name of 
a type.

Rename the parameter.

Added: 


Modified: 
clang/lib/Parse/ParseDecl.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 178cb1b661c7..065a82b9298a 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -6612,7 +6612,7 @@ void Parser::ParseFunctionDeclaratorIdentifierList(
 /// [C++11] attribute-specifier-seq parameter-declaration
 ///
 void Parser::ParseParameterDeclarationClause(
-   DeclaratorContext DeclaratorContext,
+   DeclaratorContext DeclaratorCtx,
ParsedAttributes ,
SmallVectorImpl ,
SourceLocation ) {
@@ -6661,9 +6661,9 @@ void Parser::ParseParameterDeclarationClause(
 // "LambdaExprParameterContext", because we must accept either
 // 'declarator' or 'abstract-declarator' here.
 Declarator ParmDeclarator(
-DS, DeclaratorContext == DeclaratorContext::RequiresExprContext
+DS, DeclaratorCtx == DeclaratorContext::RequiresExprContext
 ? DeclaratorContext::RequiresExprContext
-: DeclaratorContext == DeclaratorContext::LambdaExprContext
+: DeclaratorCtx == DeclaratorContext::LambdaExprContext
   ? DeclaratorContext::LambdaExprParameterContext
   : DeclaratorContext::PrototypeContext);
 ParseDeclarator(ParmDeclarator);
@@ -6719,7 +6719,7 @@ void Parser::ParseParameterDeclarationClause(
 SourceLocation EqualLoc = Tok.getLocation();
 
 // Parse the default argument
-if (DeclaratorContext == DeclaratorContext::MemberContext) {
+if (DeclaratorCtx == DeclaratorContext::MemberContext) {
   // If we're inside a class definition, cache the tokens
   // corresponding to the default argument. We'll actually parse
   // them when we see the end of the class definition.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8a34467 - [Concepts] Fix ConceptSpecializationExpr profiling crash

2020-01-16 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-16T13:39:30+02:00
New Revision: 8a3446746098ba29348bb8f85357dd0b466a6d6e

URL: 
https://github.com/llvm/llvm-project/commit/8a3446746098ba29348bb8f85357dd0b466a6d6e
DIFF: 
https://github.com/llvm/llvm-project/commit/8a3446746098ba29348bb8f85357dd0b466a6d6e.diff

LOG: [Concepts] Fix ConceptSpecializationExpr profiling crash

ConceptSpecializationExprs (CSEs) were being created with nullptr
TemplateArgsAsWritten during TemplateTemplateParmDecl canonicalization, and
we were relying on them during profiling which caused sporadic crashes
in test/CXX/.../temp.arg.template/p3-2a.cpp introduced in D44352.

Change profiling of CSEs to instead rely on the actual converted template
arguments and concept named.

Added: 


Modified: 
clang/lib/AST/StmtProfile.cpp

Removed: 




diff  --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index 2aa5106e90fa..c0b0f3b0b064 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -1335,9 +1335,9 @@ void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
 void StmtProfiler::VisitConceptSpecializationExpr(
const ConceptSpecializationExpr *S) 
{
   VisitExpr(S);
-  VisitDecl(S->getFoundDecl());
-  VisitTemplateArguments(S->getTemplateArgsAsWritten()->getTemplateArgs(),
- S->getTemplateArgsAsWritten()->NumTemplateArgs);
+  VisitDecl(S->getNamedConcept());
+  for (const TemplateArgument  : S->getTemplateArguments())
+VisitTemplateArgument(Arg);
 }
 
 static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 9b23407 - [Concepts] Fix MarkUsedTemplateParameters for exprs

2020-01-10 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-11T03:16:57+02:00
New Revision: 9b23407063ca41901e9e272bacf8b33eee8251c4

URL: 
https://github.com/llvm/llvm-project/commit/9b23407063ca41901e9e272bacf8b33eee8251c4
DIFF: 
https://github.com/llvm/llvm-project/commit/9b23407063ca41901e9e272bacf8b33eee8251c4.diff

LOG: [Concepts] Fix MarkUsedTemplateParameters for exprs

D41910 introduced a recursive visitor to MarkUsedTemplateParameters, but
disregarded the 'Depth' parameter, and had incorrect assertions. This fixes
the visitor and removes the assertions.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index d267ae8572e4..e626948cb5d4 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5384,46 +5384,40 @@ bool 
Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs(
   return isAtLeastAsSpecializedAs(*this, PType, AType, AArg, Info);
 }
 
-struct OccurringTemplateParameterFinder :
-RecursiveASTVisitor {
-  llvm::SmallBitVector 
+namespace {
+struct MarkUsedTemplateParameterVisitor :
+RecursiveASTVisitor {
+  llvm::SmallBitVector 
+  unsigned Depth;
 
-  OccurringTemplateParameterFinder(llvm::SmallBitVector )
-  : OccurringIndices(OccurringIndices) { }
+  MarkUsedTemplateParameterVisitor(llvm::SmallBitVector ,
+   unsigned Depth)
+  : Used(Used), Depth(Depth) { }
 
   bool VisitTemplateTypeParmType(TemplateTypeParmType *T) {
-assert(T->getDepth() == 0 && "This assumes that we allow concepts at "
- "namespace scope only");
-noteParameter(T->getIndex());
+if (T->getDepth() == Depth)
+  Used[T->getIndex()] = true;
 return true;
   }
 
   bool TraverseTemplateName(TemplateName Template) {
 if (auto *TTP =
-dyn_cast(Template.getAsTemplateDecl())) {
-  assert(TTP->getDepth() == 0 && "This assumes that we allow concepts at "
- "namespace scope only");
-  noteParameter(TTP->getIndex());
-}
-RecursiveASTVisitor::
+dyn_cast(Template.getAsTemplateDecl()))
+  if (TTP->getDepth() == Depth)
+Used[TTP->getIndex()] = true;
+RecursiveASTVisitor::
 TraverseTemplateName(Template);
 return true;
   }
 
   bool VisitDeclRefExpr(DeclRefExpr *E) {
-if (auto *NTTP = dyn_cast(E->getDecl())) {
-  assert(NTTP->getDepth() == 0 && "This assumes that we allow concepts at "
-  "namespace scope only");
-  noteParameter(NTTP->getIndex());
-}
+if (auto *NTTP = dyn_cast(E->getDecl()))
+  if (NTTP->getDepth() == Depth)
+Used[NTTP->getIndex()] = true;
 return true;
   }
-
-protected:
-  void noteParameter(unsigned Index) {
-OccurringIndices.set(Index);
-  }
 };
+}
 
 /// Mark the template parameters that are used by the given
 /// expression.
@@ -5434,7 +5428,8 @@ MarkUsedTemplateParameters(ASTContext ,
unsigned Depth,
llvm::SmallBitVector ) {
   if (!OnlyDeduced) {
-OccurringTemplateParameterFinder(Used).TraverseStmt(const_cast(E));
+MarkUsedTemplateParameterVisitor(Used, Depth)
+.TraverseStmt(const_cast(E));
 return;
   }
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 84ce462 - [Concepts] Fix failing test on Windows

2020-01-09 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-09T16:13:46+02:00
New Revision: 84ce46269cfda8800346706251ac3587b2d1c9f5

URL: 
https://github.com/llvm/llvm-project/commit/84ce46269cfda8800346706251ac3587b2d1c9f5
DIFF: 
https://github.com/llvm/llvm-project/commit/84ce46269cfda8800346706251ac3587b2d1c9f5.diff

LOG: [Concepts] Fix failing test on Windows

Fix test failed by D43357 on Windows.

Added: 


Modified: 
clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp

Removed: 




diff  --git a/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp 
b/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
index dba2ef204e1d..36c68071448c 100644
--- a/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
+++ b/clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
@@ -79,11 +79,11 @@ namespace non_template
 return 0.0;
   }
 
-  void bar() requires (sizeof(long) >= 8) { }
+  void bar() requires (sizeof(char[8]) >= 8) { }
   // expected-note@-1 {{candidate function}}
   // expected-note@-2 {{similar constraint expressions not considered 
equivalent}}
 
-  void bar() requires (sizeof(long) >= 8 && sizeof(int) <= 30) { }
+  void bar() requires (sizeof(char[8]) >= 8 && sizeof(int) <= 30) { }
   // expected-note@-1 {{candidate function}}
   // expected-note@-2 {{similar constraint expression here}}
 
@@ -111,4 +111,3 @@ namespace non_template
   static_assert(goo(1) == 1);
   static_assert(doo(2) == 1); // expected-error {{call to 'doo' is ambiguous}}
 }
-



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 11d5fa6 - [Concepts] Fix incorrect move out of temporary in D41910

2019-12-18 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2019-12-18T21:43:53+02:00
New Revision: 11d5fa6e87e3584f72056ecc2b17f88c58323dde

URL: 
https://github.com/llvm/llvm-project/commit/11d5fa6e87e3584f72056ecc2b17f88c58323dde
DIFF: 
https://github.com/llvm/llvm-project/commit/11d5fa6e87e3584f72056ecc2b17f88c58323dde.diff

LOG: [Concepts] Fix incorrect move out of temporary in D41910

Moves out of temporaries caused warnings that failed builds.

Added: 


Modified: 
clang/lib/Sema/SemaConcept.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index f9d54a811469..63b8e06a7aef 100755
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -653,7 +653,7 @@ static NormalForm makeCNF(const NormalizedConstraint 
) {
   if (Normalized.getCompoundKind() == NormalizedConstraint::CCK_Conjunction) {
 LCNF.reserve(LCNF.size() + RCNF.size());
 while (!RCNF.empty())
-  LCNF.push_back(std::move(RCNF.pop_back_val()));
+  LCNF.push_back(RCNF.pop_back_val());
 return LCNF;
   }
 
@@ -682,7 +682,7 @@ static NormalForm makeDNF(const NormalizedConstraint 
) {
   if (Normalized.getCompoundKind() == NormalizedConstraint::CCK_Disjunction) {
 LDNF.reserve(LDNF.size() + RDNF.size());
 while (!RDNF.empty())
-  LDNF.push_back(std::move(RDNF.pop_back_val()));
+  LDNF.push_back(RDNF.pop_back_val());
 return LDNF;
   }
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 12038be - [Concepts] Fix crash in D41910

2019-12-18 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2019-12-18T21:31:33+02:00
New Revision: 12038be20ee6a903cdbd3fddce65535ef683e31d

URL: 
https://github.com/llvm/llvm-project/commit/12038be20ee6a903cdbd3fddce65535ef683e31d
DIFF: 
https://github.com/llvm/llvm-project/commit/12038be20ee6a903cdbd3fddce65535ef683e31d.diff

LOG: [Concepts] Fix crash in D41910

Differential Revision: https://reviews.llvm.org/D41910

Added: 


Modified: 
clang/lib/Sema/SemaConcept.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index cd41000fa023..f9d54a811469 100755
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -558,7 +558,7 @@ static bool substituteParameterMappings(Sema , 
NormalizedConstraint ,
 Atomic.ParameterMapping.emplace();
 Atomic.ParameterMapping->reserve(OccurringIndices.size());
 for (unsigned I = 0, C = TemplateParams->size(); I != C; ++I)
-  if (OccurringIndices[I])
+  if (I < OccurringIndices.size() && OccurringIndices[I])
 Atomic.ParameterMapping->push_back(
 S.getIdentityTemplateArgumentLoc(TemplateParams->begin()[I],
 // Here we assume we do not support things like



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e7c2466 - [Concepts] Fix build failures in D41569

2019-12-05 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2019-12-06T01:53:18+02:00
New Revision: e7c24667816edc1a3754b46a49f9eac011dc1fee

URL: 
https://github.com/llvm/llvm-project/commit/e7c24667816edc1a3754b46a49f9eac011dc1fee
DIFF: 
https://github.com/llvm/llvm-project/commit/e7c24667816edc1a3754b46a49f9eac011dc1fee.diff

LOG: [Concepts] Fix build failures in D41569

Fix build failures in previous commit.

Added: 


Modified: 
clang/lib/AST/ASTConcept.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTConcept.cpp b/clang/lib/AST/ASTConcept.cpp
index b38b0952145f..fc32e768d92f 100644
--- a/clang/lib/AST/ASTConcept.cpp
+++ b/clang/lib/AST/ASTConcept.cpp
@@ -29,10 +29,10 @@ ASTConstraintSatisfaction::ASTConstraintSatisfaction(const 
ASTContext ,
  Detail.second.get())};
 else {
   auto  =
-  *Detail.second.get *>();
+  *Detail.second.get *>();
   unsigned MessageSize = SubstitutionDiagnostic.second.size();
   char *Mem = new (C) char[MessageSize];
-  memcpy(Mem, SubstitutionDiagnostic.second.c_str(), MessageSize);
+  memcpy(Mem, SubstitutionDiagnostic.second.data(), MessageSize);
   auto *NewSubstDiag = new (C) std::pair(
   SubstitutionDiagnostic.first, StringRef(Mem, MessageSize));
   new (getTrailingObjects() + I)



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fdf80e8 - [Concepts] Constraint Enforcement & Diagnostics

2019-12-05 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2019-12-06T01:34:20+02:00
New Revision: fdf80e86a52849813d05da4b6c25884c06ba9e98

URL: 
https://github.com/llvm/llvm-project/commit/fdf80e86a52849813d05da4b6c25884c06ba9e98
DIFF: 
https://github.com/llvm/llvm-project/commit/fdf80e86a52849813d05da4b6c25884c06ba9e98.diff

LOG: [Concepts] Constraint Enforcement & Diagnostics

Part of the C++20 concepts implementation effort.
- Associated constraints (requires clauses, currently) are now enforced when 
instantiating/specializing templates and when considering partial 
specializations and function overloads.
- Elaborated diagnostics give helpful insight as to why the constraints were 
not satisfied.
Phabricator: D41569

Re-commit, after fixing some memory bugs.

Added: 
clang/include/clang/AST/ASTConcept.h
clang/lib/AST/ASTConcept.cpp
clang/test/CXX/temp/temp.constr/temp.constr.constr/function-templates.cpp

clang/test/CXX/temp/temp.constr/temp.constr.constr/non-function-templates.cpp

clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp

Modified: 
clang/include/clang/AST/ExprCXX.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/include/clang/Sema/TemplateDeduction.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/CMakeLists.txt
clang/lib/AST/Decl.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTConcept.h 
b/clang/include/clang/AST/ASTConcept.h
new file mode 100644
index ..937a8a9b345e
--- /dev/null
+++ b/clang/include/clang/AST/ASTConcept.h
@@ -0,0 +1,80 @@
+//===--- ASTConcept.h - Concepts Related AST Data Structures *- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+///
+/// \file
+/// \brief This file provides AST data structures related to concepts.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_AST_ASTCONCEPT_H
+#define LLVM_CLANG_AST_ASTCONCEPT_H
+#include "clang/AST/Expr.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/SmallVector.h"
+#include 
+#include 
+namespace clang {
+
+/// \brief The result of a constraint satisfaction check, containing the
+/// necessary information to diagnose an unsatisfied constraint.
+struct ConstraintSatisfaction {
+  using SubstitutionDiagnostic = std::pair;
+  using Detail = llvm::PointerUnion;
+
+  bool IsSatisfied = false;
+
+  /// \brief Pairs of unsatisfied atomic constraint expressions along with the
+  /// substituted constraint expr, if the template arguments could be
+  /// substituted into them, or a diagnostic if substitution resulted in an
+  /// invalid expression.
+  llvm::SmallVector, 4> Details;
+
+  // This can leak if used in an AST node, use ASTConstraintSatisfaction
+  // instead.
+  void *operator new(size_t bytes, ASTContext ) = delete;
+};
+
+/// Pairs of unsatisfied atomic constraint expressions along with the
+/// substituted constraint expr, if the template arguments could be
+/// substituted into them, or a diagnostic if substitution resulted in
+/// an invalid expression.
+using UnsatisfiedConstraintRecord =
+std::pair *>>;
+
+/// \brief The result of a constraint satisfaction check, containing the
+/// necessary information to diagnose an unsatisfied constraint.
+///
+/// This is safe to store in an AST node, as opposed to ConstraintSatisfaction.
+struct ASTConstraintSatisfaction final :
+llvm::TrailingObjects {
+  std::size_t NumRecords;
+  bool IsSatisfied : 1;
+
+  const UnsatisfiedConstraintRecord *begin() const {
+return getTrailingObjects();
+  }
+
+  const UnsatisfiedConstraintRecord *end() const {
+return getTrailingObjects() + NumRecords;
+  }
+
+  ASTConstraintSatisfaction(const ASTContext ,
+const ConstraintSatisfaction );
+
+  static ASTConstraintSatisfaction *
+  Create(const ASTContext , const ConstraintSatisfaction );
+};
+
+} // clang
+
+#endif // LLVM_CLANG_AST_ASTCONCEPT_H
\ No newline at end of file

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 1eac1ce842d8..1a16aa7aacec 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ 

[clang] ffa214e - [Concepts] Constraint Enforcement & Diagnostics

2019-10-24 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2019-10-25T00:19:51+03:00
New Revision: ffa214ef22892d75340dc6720271863901dc2c90

URL: 
https://github.com/llvm/llvm-project/commit/ffa214ef22892d75340dc6720271863901dc2c90
DIFF: 
https://github.com/llvm/llvm-project/commit/ffa214ef22892d75340dc6720271863901dc2c90.diff

LOG: [Concepts] Constraint Enforcement & Diagnostics

Part of the C++20 concepts implementation effort.
- Associated constraints (requires clauses, currently) are now enforced when 
instantiating/specializing templates and when considering partial 
specializations and function overloads.
- Elaborated diagnostics give helpful insight as to why the constraints were 
not satisfied.
Phabricator: D41569

Added: 
clang/include/clang/AST/ASTConcept.h
clang/lib/AST/ASTConcept.cpp
clang/test/CXX/temp/temp.constr/temp.constr.constr/function-templates.cpp

clang/test/CXX/temp/temp.constr/temp.constr.constr/non-function-templates.cpp

clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp

Modified: 
clang/include/clang/AST/ExprCXX.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/include/clang/Sema/TemplateDeduction.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/CMakeLists.txt
clang/lib/AST/Decl.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTConcept.h 
b/clang/include/clang/AST/ASTConcept.h
new file mode 100644
index ..f5e99a8bfa1e
--- /dev/null
+++ b/clang/include/clang/AST/ASTConcept.h
@@ -0,0 +1,80 @@
+//===--- ASTConcept.h - Concepts Related AST Data Structures *- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+///
+/// \file
+/// \brief This file provides AST data structures related to concepts.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_AST_ASTCONCEPT_H
+#define LLVM_CLANG_AST_ASTCONCEPT_H
+#include "clang/AST/Expr.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/SmallVector.h"
+#include 
+#include 
+namespace clang {
+
+/// \brief The result of a constraint satisfaction check, containing the
+/// necessary information to diagnose an unsatisfied constraint.
+struct ConstraintSatisfaction {
+  using SubstitutionDiagnostic = std::pair;
+  using Detail = llvm::PointerUnion;
+
+  bool IsSatisfied = false;
+
+  /// \brief Pairs of unsatisfied atomic constraint expressions along with the
+  /// substituted constraint expr, if the template arguments could be
+  /// substituted into them, or a diagnostic if substitution resulted in an
+  /// invalid expression.
+  llvm::SmallVector, 4> Details;
+
+  // This can leak if used in an AST node, use ASTConstraintSatisfaction
+  // instead.
+  void *operator new(size_t bytes, ASTContext ) = delete;
+};
+
+/// Pairs of unsatisfied atomic constraint expressions along with the
+/// substituted constraint expr, if the template arguments could be
+/// substituted into them, or a diagnostic if substitution resulted in
+/// an invalid expression.
+using UnsatisfiedConstraintRecord =
+std::pair *>>;
+
+/// \brief The result of a constraint satisfaction check, containing the
+/// necessary information to diagnose an unsatisfied constraint.
+///
+/// This is safe to store in an AST node, as opposed to ConstraintSatisfaction.
+struct ASTConstraintSatisfaction final :
+llvm::TrailingObjects {
+  std::size_t NumRecords;
+  bool IsSatisfied : 1;
+
+  const UnsatisfiedConstraintRecord *begin() const {
+return getTrailingObjects();
+  }
+
+  const UnsatisfiedConstraintRecord *end() const {
+return getTrailingObjects() + NumRecords;
+  }
+
+  ASTConstraintSatisfaction(const ASTContext ,
+const ConstraintSatisfaction );
+
+  static ASTConstraintSatisfaction *
+  Create(const ASTContext , const ConstraintSatisfaction );
+};
+
+} // clang
+
+#endif // LLVM_CLANG_AST_ASTCONCEPT_H
\ No newline at end of file

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 2152e108c7cb..3719f8229a36 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -14,6 +14,7 @@
 #ifndef 

r375063 - [Concepts] ConceptSpecializationExprs mangling

2019-10-16 Thread Saar Raz via cfe-commits
Author: saar.raz
Date: Wed Oct 16 17:16:01 2019
New Revision: 375063

URL: http://llvm.org/viewvc/llvm-project?rev=375063=rev
Log:
[Concepts] ConceptSpecializationExprs mangling

Implement mangling for CSEs to match regular template-ids.
Reviewed as part of D41569 .

Re-commit fixing failing test.


Added:
cfe/trunk/test/CodeGenCXX/mangle-concept.cpp
Modified:
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=375063=375062=375063=diff
==
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Wed Oct 16 17:16:01 2019
@@ -969,7 +969,7 @@ void CXXNameMangler::mangleUnscopedTempl
 assert(!AdditionalAbiTags &&
"template template param cannot have abi tags");
 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
-  } else if (isa(ND)) {
+  } else if (isa(ND) || isa(ND)) {
 mangleUnscopedName(ND, AdditionalAbiTags);
   } else {
 mangleUnscopedName(ND->getTemplatedDecl(), AdditionalAbiTags);
@@ -1890,7 +1890,7 @@ void CXXNameMangler::mangleTemplatePrefi
 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
   } else {
 manglePrefix(getEffectiveDeclContext(ND), NoFunction);
-if (isa(ND))
+if (isa(ND) || isa(ND))
   mangleUnqualifiedName(ND, nullptr);
 else
   mangleUnqualifiedName(ND->getTemplatedDecl(), nullptr);
@@ -3658,7 +3658,6 @@ recurse:
   case Expr::ConvertVectorExprClass:
   case Expr::StmtExprClass:
   case Expr::TypeTraitExprClass:
-  case Expr::ConceptSpecializationExprClass:
   case Expr::ArrayTypeTraitExprClass:
   case Expr::ExpressionTraitExprClass:
   case Expr::VAArgExprClass:
@@ -4168,6 +4167,18 @@ recurse:
 mangleExpression(cast(E)->getSubExpr(), Arity);
 break;
 
+
+  case Expr::ConceptSpecializationExprClass: {
+//   ::= L  E # external name
+Out << "L_Z";
+auto *CSE = cast(E);
+mangleTemplateName(CSE->getNamedConcept(),
+   CSE->getTemplateArguments().data(),
+   CSE->getTemplateArguments().size());
+Out << 'E';
+break;
+  }
+
   case Expr::DeclRefExprClass:
 mangleDeclRefExpr(cast(E)->getDecl());
 break;

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=375063=375062=375063=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Oct 16 17:16:01 2019
@@ -4302,7 +4302,7 @@ ExprResult Sema::BuildTemplateIdExpr(con
   TemplateKWLoc, TemplateArgs);
   }
 
-  if (R.getAsSingle() && !AnyDependentArguments()) {
+  if (R.getAsSingle()) {
 return CheckConceptTemplateId(SS, TemplateKWLoc,
   R.getLookupNameInfo().getBeginLoc(),
   R.getFoundDecl(),

Added: cfe/trunk/test/CodeGenCXX/mangle-concept.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-concept.cpp?rev=375063=auto
==
--- cfe/trunk/test/CodeGenCXX/mangle-concept.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/mangle-concept.cpp Wed Oct 16 17:16:01 2019
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -verify -Wno-return-type -Wno-main -std=c++2a -fconcepts-ts 
-emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s
+// expected-no-diagnostics
+
+namespace test1 {
+template  struct S {};
+template  concept C = true;
+template  S> f0() { return S>{}; }
+template S> f0<>();
+// CHECK: @_ZN5test12f0IiEENS_1SIXL_ZNS_1CIT_EEv(
+}
+
+template  struct S {};
+template  concept C = true;
+template  S> f0() { return S>{}; }
+template S> f0<>();
+// CHECK: @_Z2f0IiE1SIXL_Z1CIT_v(


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r374971 - Fix failing mangle-concept.cpp test.

2019-10-15 Thread Saar Raz via cfe-commits
Author: saar.raz
Date: Tue Oct 15 19:56:40 2019
New Revision: 374971

URL: http://llvm.org/viewvc/llvm-project?rev=374971=rev
Log:
Fix failing mangle-concept.cpp test.


Modified:
cfe/trunk/test/CodeGenCXX/mangle-concept.cpp

Modified: cfe/trunk/test/CodeGenCXX/mangle-concept.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-concept.cpp?rev=374971=374970=374971=diff
==
--- cfe/trunk/test/CodeGenCXX/mangle-concept.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-concept.cpp Tue Oct 15 19:56:40 2019
@@ -6,11 +6,11 @@ template  struct S {};
 template  concept C = true;
 template  S> f0() { return S>{}; }
 template S> f0<>();
-// CHECK: void @_ZN5test12f0IiEENS_1SIXL_ZNS_1CIT_EEv()
+// CHECK: void @_ZN5test12f0IiEENS_1SIXL_ZNS_1CIT_EEv(
 }
 
 template  struct S {};
 template  concept C = true;
 template  S> f0() { return S>{}; }
 template S> f0<>();
-// CHECK: void @_Z2f0IiE1SIXL_Z1CIT_v()
\ No newline at end of file
+// CHECK: void @_Z2f0IiE1SIXL_Z1CIT_v(


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r374967 - [Concepts] ConceptSpecializationExprs mangling

2019-10-15 Thread Saar Raz via cfe-commits
Author: saar.raz
Date: Tue Oct 15 19:33:41 2019
New Revision: 374967

URL: http://llvm.org/viewvc/llvm-project?rev=374967=rev
Log:
[Concepts] ConceptSpecializationExprs mangling

Implement mangling for CSEs to match regular template-ids.
Reviewed as part of D41569.

Added:
cfe/trunk/test/CodeGenCXX/mangle-concept.cpp
Modified:
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=374967=374966=374967=diff
==
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Tue Oct 15 19:33:41 2019
@@ -969,7 +969,7 @@ void CXXNameMangler::mangleUnscopedTempl
 assert(!AdditionalAbiTags &&
"template template param cannot have abi tags");
 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
-  } else if (isa(ND)) {
+  } else if (isa(ND) || isa(ND)) {
 mangleUnscopedName(ND, AdditionalAbiTags);
   } else {
 mangleUnscopedName(ND->getTemplatedDecl(), AdditionalAbiTags);
@@ -1890,7 +1890,7 @@ void CXXNameMangler::mangleTemplatePrefi
 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
   } else {
 manglePrefix(getEffectiveDeclContext(ND), NoFunction);
-if (isa(ND))
+if (isa(ND) || isa(ND))
   mangleUnqualifiedName(ND, nullptr);
 else
   mangleUnqualifiedName(ND->getTemplatedDecl(), nullptr);
@@ -3658,7 +3658,6 @@ recurse:
   case Expr::ConvertVectorExprClass:
   case Expr::StmtExprClass:
   case Expr::TypeTraitExprClass:
-  case Expr::ConceptSpecializationExprClass:
   case Expr::ArrayTypeTraitExprClass:
   case Expr::ExpressionTraitExprClass:
   case Expr::VAArgExprClass:
@@ -4168,6 +4167,18 @@ recurse:
 mangleExpression(cast(E)->getSubExpr(), Arity);
 break;
 
+
+  case Expr::ConceptSpecializationExprClass: {
+//   ::= L  E # external name
+Out << "L_Z";
+auto *CSE = cast(E);
+mangleTemplateName(CSE->getNamedConcept(),
+   CSE->getTemplateArguments().data(),
+   CSE->getTemplateArguments().size());
+Out << 'E';
+break;
+  }
+
   case Expr::DeclRefExprClass:
 mangleDeclRefExpr(cast(E)->getDecl());
 break;

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=374967=374966=374967=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Tue Oct 15 19:33:41 2019
@@ -4302,7 +4302,7 @@ ExprResult Sema::BuildTemplateIdExpr(con
   TemplateKWLoc, TemplateArgs);
   }
 
-  if (R.getAsSingle() && !AnyDependentArguments()) {
+  if (R.getAsSingle()) {
 return CheckConceptTemplateId(SS, TemplateKWLoc,
   R.getLookupNameInfo().getBeginLoc(),
   R.getFoundDecl(),

Added: cfe/trunk/test/CodeGenCXX/mangle-concept.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-concept.cpp?rev=374967=auto
==
--- cfe/trunk/test/CodeGenCXX/mangle-concept.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/mangle-concept.cpp Tue Oct 15 19:33:41 2019
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -verify -Wno-return-type -Wno-main -std=c++2a -fconcepts-ts 
-emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s
+// expected-no-diagnostics
+
+namespace test1 {
+template  struct S {};
+template  concept C = true;
+template  S> f0() { return S>{}; }
+template S> f0<>();
+// CHECK: void @_ZN5test12f0IiEENS_1SIXL_ZNS_1CIT_EEv()
+}
+
+template  struct S {};
+template  concept C = true;
+template  S> f0() { return S>{}; }
+template S> f0<>();
+// CHECK: void @_Z2f0IiE1SIXL_Z1CIT_v()
\ No newline at end of file


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r374938 - [Concept] Associated Constraints Infrastructure

2019-10-15 Thread Saar Raz via cfe-commits
Author: saar.raz
Date: Tue Oct 15 11:44:06 2019
New Revision: 374938

URL: http://llvm.org/viewvc/llvm-project?rev=374938=rev
Log:
[Concept] Associated Constraints Infrastructure

Add code to correctly calculate the associated constraints of a template (no 
enforcement yet).
D41284 on Phabricator.


Added:
cfe/trunk/test/CXX/temp/concept/p4.cpp
cfe/trunk/test/CXX/temp/temp.constr/temp.constr.decl/func-template-decl.cpp
cfe/trunk/test/CXX/temp/temp.constr/temp.constr.decl/var-template-decl.cpp
Modified:
cfe/trunk/include/clang/AST/ASTNodeTraverser.h
cfe/trunk/include/clang/AST/DeclTemplate.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/DeclTemplate.cpp
cfe/trunk/lib/Sema/SemaConcept.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CXX/temp/temp.constr/temp.constr.decl/class-template-decl.cpp

Modified: cfe/trunk/include/clang/AST/ASTNodeTraverser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTNodeTraverser.h?rev=374938=374937=374938=diff
==
--- cfe/trunk/include/clang/AST/ASTNodeTraverser.h (original)
+++ cfe/trunk/include/clang/AST/ASTNodeTraverser.h Tue Oct 15 11:44:06 2019
@@ -237,6 +237,9 @@ public:
 
 for (const auto  : *TPL)
   Visit(TP);
+
+if (const Expr *RC = TPL->getRequiresClause())
+  Visit(RC);
   }
 
   void

Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=374938=374937=374938=diff
==
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Tue Oct 15 11:44:06 2019
@@ -168,6 +168,16 @@ public:
 return HasRequiresClause ? *getTrailingObjects() : nullptr;
   }
 
+  /// \brief All associated constraints derived from this template parameter
+  /// list, including the requires clause and any constraints derived from
+  /// constrained-parameters.
+  ///
+  /// The constraints in the resulting list are to be treated as if in a
+  /// conjunction ("and").
+  void getAssociatedConstraints(llvm::SmallVectorImpl ) const;
+
+  bool hasAssociatedConstraints() const;
+
   SourceLocation getTemplateLoc() const { return TemplateLoc; }
   SourceLocation getLAngleLoc() const { return LAngleLoc; }
   SourceLocation getRAngleLoc() const { return RAngleLoc; }
@@ -369,33 +379,7 @@ public:
 // Kinds of Templates
 
//===--===//
 
-/// Stores the template parameter list and associated constraints for
-/// \c TemplateDecl objects that track associated constraints.
-class ConstrainedTemplateDeclInfo {
-  friend TemplateDecl;
-
-public:
-  ConstrainedTemplateDeclInfo() = default;
-
-  TemplateParameterList *getTemplateParameters() const {
-return TemplateParams;
-  }
-
-  Expr *getAssociatedConstraints() const { return AssociatedConstraints; }
-
-protected:
-  void setTemplateParameters(TemplateParameterList *TParams) {
-TemplateParams = TParams;
-  }
-
-  void setAssociatedConstraints(Expr *AC) { AssociatedConstraints = AC; }
-
-  TemplateParameterList *TemplateParams = nullptr;
-  Expr *AssociatedConstraints = nullptr;
-};
-
-
-/// The base class of all kinds of template declarations (e.g.,
+/// \brief The base class of all kinds of template declarations (e.g.,
 /// class, function, etc.).
 ///
 /// The TemplateDecl class stores the list of template parameters and a
@@ -404,55 +388,33 @@ class TemplateDecl : public NamedDecl {
   void anchor() override;
 
 protected:
+  // Construct a template decl with name, parameters, and templated element.
+  TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName 
Name,
+   TemplateParameterList *Params, NamedDecl *Decl);
+
   // Construct a template decl with the given name and parameters.
   // Used when there is no templated element (e.g., for tt-params).
-  TemplateDecl(ConstrainedTemplateDeclInfo *CTDI, Kind DK, DeclContext *DC,
-   SourceLocation L, DeclarationName Name,
-   TemplateParameterList *Params)
-  : NamedDecl(DK, DC, L, Name), TemplatedDecl(nullptr),
-TemplateParams(CTDI) {
-this->setTemplateParameters(Params);
-  }
-
   TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName 
Name,
TemplateParameterList *Params)
-  : TemplateDecl(nullptr, DK, DC, L, Name, Params) {}
-
-  // Construct a template decl with 

r374907 - [Concepts] Remove unused and illegal Sema includes from ExprCXX.cpp

2019-10-15 Thread Saar Raz via cfe-commits
Author: saar.raz
Date: Tue Oct 15 08:49:29 2019
New Revision: 374907

URL: http://llvm.org/viewvc/llvm-project?rev=374907=rev
Log:
[Concepts] Remove unused and illegal Sema includes from ExprCXX.cpp

Fixing accidental includes introduced in 374903

Modified:
cfe/trunk/lib/AST/ExprCXX.cpp

Modified: cfe/trunk/lib/AST/ExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=374907=374906=374907=diff
==
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Tue Oct 15 08:49:29 2019
@@ -28,9 +28,6 @@
 #include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
-#include "clang/Sema/Template.h"
-#include "clang/Sema/SemaDiagnostic.h"
-#include "clang/Sema/Sema.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -1761,4 +1758,4 @@ ConceptSpecializationExpr::Create(ASTCon
   void *Buffer = C.Allocate(totalSizeToAlloc(
 NumTemplateArgs));
   return new (Buffer) ConceptSpecializationExpr(Empty, NumTemplateArgs);
-}
\ No newline at end of file
+}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r374903 - [Concepts] Concept Specialization Expressions

2019-10-15 Thread Saar Raz via cfe-commits
Author: saar.raz
Date: Tue Oct 15 08:24:26 2019
New Revision: 374903

URL: http://llvm.org/viewvc/llvm-project?rev=374903=rev
Log:
[Concepts] Concept Specialization Expressions

Part of C++20 Concepts implementation effort. Added Concept Specialization 
Expressions that are created when a concept is refe$

D41217 on Phabricator.

(recommit after fixing failing Parser test on windows)


Added:
cfe/trunk/lib/Sema/SemaConcept.cpp
cfe/trunk/test/CXX/expr/expr.prim/expr.prim.id/
cfe/trunk/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp
cfe/trunk/test/CXX/temp/temp.constr/
cfe/trunk/test/CXX/temp/temp.constr/temp.constr.decl/
cfe/trunk/test/CXX/temp/temp.constr/temp.constr.decl/class-template-decl.cpp
cfe/trunk/test/PCH/cxx2a-concept-specialization-expr.cpp
Removed:
cfe/trunk/test/CXX/concepts-ts/
Modified:
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/StmtNodes.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/ExprCXX.cpp
cfe/trunk/lib/AST/ExprClassification.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/AST/StmtProfile.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Sema/CMakeLists.txt
cfe/trunk/lib/Sema/SemaExceptionSpec.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/test/Parser/cxx2a-concept-declaration.cpp
cfe/trunk/tools/libclang/CXCursor.cpp

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=374903=374902=374903=diff
==
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Tue Oct 15 08:24:26 2019
@@ -17,6 +17,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/NestedNameSpecifier.h"
@@ -56,6 +57,7 @@ class IdentifierInfo;
 class LambdaCapture;
 class NonTypeTemplateParmDecl;
 class TemplateParameterList;
+class Sema;
 
 //======//
 // C++ Expressions.
@@ -4750,6 +4752,125 @@ public:
   }
 };
 
+/// \brief Represents the specialization of a concept - evaluates to a prvalue
+/// of type bool.
+///
+/// According to C++2a [expr.prim.id]p3 an id-expression that denotes the
+/// specialization of a concept results in a prvalue of type bool.
+class ConceptSpecializationExpr final : public Expr,
+  private llvm::TrailingObjects {
+  friend class ASTStmtReader;
+  friend TrailingObjects;
+
+  // \brief The optional nested name specifier used when naming the concept.
+  NestedNameSpecifierLoc NestedNameSpec;
+
+  /// \brief The location of the template keyword, if specified when naming the
+  /// concept.
+  SourceLocation TemplateKWLoc;
+
+  /// \brief The location of the concept name in the expression.
+  SourceLocation ConceptNameLoc;
+
+  /// \brief The declaration found by name lookup when the expression was
+  /// created.
+  /// Can differ from NamedConcept when, for example, the concept was found
+  /// through a UsingShadowDecl.
+  NamedDecl *FoundDecl;
+
+  /// \brief The concept named, and whether or not the concept with the given
+  /// arguments was satisfied when the expression was created.
+  /// If any of the template arguments are dependent (this expr would then be
+  /// isValueDependent()), this bit is to be ignored.
+  llvm::PointerIntPair NamedConcept;
+
+  /// \brief The template argument list source info used to specialize the
+  /// concept.
+  const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr;
+
+  /// \brief The number of template arguments in the tail-allocated list of
+  /// converted template arguments.
+  unsigned NumTemplateArgs;
+
+  ConceptSpecializationExpr(ASTContext , NestedNameSpecifierLoc NNS,
+SourceLocation TemplateKWLoc,
+SourceLocation ConceptNameLoc, NamedDecl 
*FoundDecl,
+ConceptDecl *NamedConcept,
+const ASTTemplateArgumentListInfo *ArgsAsWritten,
+ArrayRef ConvertedArgs,
+Optional IsSatisfied);
+
+  ConceptSpecializationExpr(EmptyShell 

r374882 - [Concepts] Concept Specialization Expressions

2019-10-15 Thread Saar Raz via cfe-commits
Author: saar.raz
Date: Tue Oct 15 04:48:58 2019
New Revision: 374882

URL: http://llvm.org/viewvc/llvm-project?rev=374882=rev
Log:
[Concepts] Concept Specialization Expressions

Part of C++20 Concepts implementation effort. Added Concept Specialization 
Expressions that are created when a concept is referenced with arguments, and 
tests thereof.



Added:
cfe/trunk/lib/Sema/SemaConcept.cpp
cfe/trunk/test/CXX/expr/expr.prim/expr.prim.id/
cfe/trunk/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp
cfe/trunk/test/CXX/temp/temp.constr/
cfe/trunk/test/CXX/temp/temp.constr/temp.constr.decl/
cfe/trunk/test/CXX/temp/temp.constr/temp.constr.decl/class-template-decl.cpp
cfe/trunk/test/PCH/cxx2a-concept-specialization-expr.cpp
Removed:
cfe/trunk/test/CXX/concepts-ts/
Modified:
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/StmtNodes.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/ExprCXX.cpp
cfe/trunk/lib/AST/ExprClassification.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/AST/StmtProfile.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Sema/CMakeLists.txt
cfe/trunk/lib/Sema/SemaExceptionSpec.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/test/Parser/cxx2a-concept-declaration.cpp
cfe/trunk/tools/libclang/CXCursor.cpp

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=374882=374881=374882=diff
==
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Tue Oct 15 04:48:58 2019
@@ -17,6 +17,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/NestedNameSpecifier.h"
@@ -56,6 +57,7 @@ class IdentifierInfo;
 class LambdaCapture;
 class NonTypeTemplateParmDecl;
 class TemplateParameterList;
+class Sema;
 
 //======//
 // C++ Expressions.
@@ -4750,6 +4752,125 @@ public:
   }
 };
 
+/// \brief Represents the specialization of a concept - evaluates to a prvalue
+/// of type bool.
+///
+/// According to C++2a [expr.prim.id]p3 an id-expression that denotes the
+/// specialization of a concept results in a prvalue of type bool.
+class ConceptSpecializationExpr final : public Expr,
+  private llvm::TrailingObjects {
+  friend class ASTStmtReader;
+  friend TrailingObjects;
+
+  // \brief The optional nested name specifier used when naming the concept.
+  NestedNameSpecifierLoc NestedNameSpec;
+
+  /// \brief The location of the template keyword, if specified when naming the
+  /// concept.
+  SourceLocation TemplateKWLoc;
+
+  /// \brief The location of the concept name in the expression.
+  SourceLocation ConceptNameLoc;
+
+  /// \brief The declaration found by name lookup when the expression was
+  /// created.
+  /// Can differ from NamedConcept when, for example, the concept was found
+  /// through a UsingShadowDecl.
+  NamedDecl *FoundDecl;
+
+  /// \brief The concept named, and whether or not the concept with the given
+  /// arguments was satisfied when the expression was created.
+  /// If any of the template arguments are dependent (this expr would then be
+  /// isValueDependent()), this bit is to be ignored.
+  llvm::PointerIntPair NamedConcept;
+
+  /// \brief The template argument list source info used to specialize the
+  /// concept.
+  const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr;
+
+  /// \brief The number of template arguments in the tail-allocated list of
+  /// converted template arguments.
+  unsigned NumTemplateArgs;
+
+  ConceptSpecializationExpr(ASTContext , NestedNameSpecifierLoc NNS,
+SourceLocation TemplateKWLoc,
+SourceLocation ConceptNameLoc, NamedDecl 
*FoundDecl,
+ConceptDecl *NamedConcept,
+const ASTTemplateArgumentListInfo *ArgsAsWritten,
+ArrayRef ConvertedArgs,
+Optional IsSatisfied);
+
+  ConceptSpecializationExpr(EmptyShell Empty, unsigned NumTemplateArgs);
+

r365699 - [Concepts] Concept definitions (D40381)

2019-07-10 Thread Saar Raz via cfe-commits
Author: saar.raz
Date: Wed Jul 10 14:25:49 2019
New Revision: 365699

URL: http://llvm.org/viewvc/llvm-project?rev=365699=rev
Log:
[Concepts] Concept definitions (D40381)

First in a series of patches to land C++2a Concepts support.
This patch adds AST and parsing support for concept-declarations.

Added:
cfe/trunk/test/CXX/concepts-ts/expr/
cfe/trunk/test/CXX/concepts-ts/expr/expr.prim/
cfe/trunk/test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/
cfe/trunk/test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/p3.cpp
cfe/trunk/test/Parser/cxx2a-concept-declaration.cpp
Modified:
cfe/trunk/include/clang/AST/ASTNodeTraverser.h
cfe/trunk/include/clang/AST/DeclTemplate.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/AST/TextNodeDumper.h
cfe/trunk/include/clang/Basic/DeclNodes.td
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/TemplateKinds.h
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/lib/AST/DeclTemplate.cpp
cfe/trunk/lib/AST/TextNodeDumper.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Index/IndexDecl.cpp
cfe/trunk/lib/Parse/ParseTemplate.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Serialization/ASTCommon.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/include/clang/AST/ASTNodeTraverser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTNodeTraverser.h?rev=365699=365698=365699=diff
==
--- cfe/trunk/include/clang/AST/ASTNodeTraverser.h (original)
+++ cfe/trunk/include/clang/AST/ASTNodeTraverser.h Wed Jul 10 14:25:49 2019
@@ -529,6 +529,11 @@ public:
   D->defaultArgumentWasInherited() ? "inherited from" : "previous");
   }
 
+  void VisitConceptDecl(const ConceptDecl *D) {
+dumpTemplateParameters(D->getTemplateParameters());
+Visit(D->getConstraintExpr());
+  }
+
   void VisitUsingShadowDecl(const UsingShadowDecl *D) {
 if (auto *TD = dyn_cast(D->getUnderlyingDecl()))
   Visit(TD->getTypeForDecl());

Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=365699=365698=365699=diff
==
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Wed Jul 10 14:25:49 2019
@@ -3090,6 +3090,42 @@ public:
   static bool classofKind(Kind K) { return K == VarTemplate; }
 };
 
+// \brief Declaration of a C++2a concept.
+class ConceptDecl : public TemplateDecl, public Mergeable {
+protected:
+  Expr *ConstraintExpr;
+
+  ConceptDecl(DeclContext *DC,
+  SourceLocation L, DeclarationName Name,
+  TemplateParameterList *Params,
+  Expr *ConstraintExpr)
+  : TemplateDecl(nullptr, Concept, DC, L, Name, Params),
+ConstraintExpr(ConstraintExpr) {};
+public:
+  static ConceptDecl *Create(ASTContext , DeclContext *DC,
+ SourceLocation L, DeclarationName Name,
+ TemplateParameterList *Params,
+ Expr *ConstraintExpr);
+  static ConceptDecl *CreateDeserialized(ASTContext , unsigned ID);
+
+  Expr *getConstraintExpr() const {
+return ConstraintExpr;
+  }
+
+  SourceRange getSourceRange() const override LLVM_READONLY {
+return SourceRange(getTemplateParameters()->getTemplateLoc(),
+   ConstraintExpr->getEndLoc());
+  }
+
+  // Implement isa/cast/dyncast/etc.
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
+  static bool classofKind(Kind K) { return K == Concept; }
+
+  friend class ASTReader;
+  friend class ASTDeclReader;
+  friend class ASTDeclWriter;
+};
+
 inline NamedDecl *getAsNamedDecl(TemplateParameter P) {
   if (auto *PD = P.dyn_cast())
 return PD;

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=365699=365698=365699=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ 

r365695 - My first test commit.

2019-07-10 Thread Saar Raz via cfe-commits
Author: saar.raz
Date: Wed Jul 10 13:01:44 2019
New Revision: 365695

URL: http://llvm.org/viewvc/llvm-project?rev=365695=rev
Log:
My first test commit.

Modified:
cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p1.cpp

Modified: 
cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p1.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p1.cpp?rev=365695=365694=365695=diff
==
--- cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p1.cpp 
(original)
+++ cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p1.cpp Wed 
Jul 10 13:01:44 2019
@@ -30,6 +30,7 @@ template
 concept bool D7() throw(int) { return true; } // expected-error {{function 
concept cannot have exception specification}}
 
 // Tag
+
 concept class CC1 {}; // expected-error {{'concept' can only appear on the 
definition of a function template or variable template}}
 concept struct CS1 {}; // expected-error {{'concept' can only appear on the 
definition of a function template or variable template}}
 concept union CU1 {}; // expected-error {{'concept' can only appear on the 
definition of a function template or variable template}}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[concepts] Step 1: Remove unneeded partial support for concepts.

2017-11-22 Thread Saar Raz via cfe-commits
As part of the roadmap for concepts,
https://github.com/saarraz/clang-concepts-roadmap, as discussed on
[cfe-dev] -
http://lists.llvm.org/pipermail/cfe-dev/2017-November/056009.html, we're
doing incremental commits with the end goal of supporting concepts as they
are in the current C++2a working draft.
This is the first step - removing old support for function and variable
concepts in preparation for the addition of concepts as they are defined in
the current working draft.
Tests were removed because they are no longer relevant/true to the current
standard. A very small amount of them can be adapted, and will be salvaged
later when we have some compilation code to support them.
diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h
index 2879452f24..d764e485dd 100644
--- a/include/clang/AST/DeclTemplate.h
+++ b/include/clang/AST/DeclTemplate.h
@@ -383,7 +383,7 @@ protected:
   TemplateDecl(ConstrainedTemplateDeclInfo *CTDI, Kind DK, DeclContext *DC,
SourceLocation L, DeclarationName Name,
TemplateParameterList *Params)
-  : NamedDecl(DK, DC, L, Name), TemplatedDecl(nullptr, false),
+  : NamedDecl(DK, DC, L, Name), TemplatedDecl(nullptr),
 TemplateParams(CTDI) {
 this->setTemplateParameters(Params);
   }
@@ -396,7 +396,7 @@ protected:
   TemplateDecl(ConstrainedTemplateDeclInfo *CTDI, Kind DK, DeclContext *DC,
SourceLocation L, DeclarationName Name,
TemplateParameterList *Params, NamedDecl *Decl)
-  : NamedDecl(DK, DC, L, Name), TemplatedDecl(Decl, false),
+  : NamedDecl(DK, DC, L, Name), TemplatedDecl(Decl),
 TemplateParams(CTDI) {
 this->setTemplateParameters(Params);
   }
@@ -428,7 +428,7 @@ public:
   }
 
   /// Get the underlying, templated declaration.
-  NamedDecl *getTemplatedDecl() const { return TemplatedDecl.getPointer(); }
+  NamedDecl *getTemplatedDecl() const { return TemplatedDecl; }
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
@@ -438,20 +438,13 @@ public:
 
   SourceRange getSourceRange() const override LLVM_READONLY {
 return SourceRange(getTemplateParameters()->getTemplateLoc(),
-   TemplatedDecl.getPointer()->getSourceRange().getEnd());
+   TemplatedDecl->getSourceRange().getEnd());
   }
 
-  /// Whether this is a (C++ Concepts TS) function or variable concept.
-  bool isConcept() const { return TemplatedDecl.getInt(); }
-  void setConcept() { TemplatedDecl.setInt(true); }
-
 protected:
   /// \brief The named declaration from which this template was instantiated.
   /// (or null).
-  ///
-  /// The boolean value will be true to indicate that this template
-  /// (function or variable) is a concept.
-  llvm::PointerIntPair TemplatedDecl;
+  NamedDecl *TemplatedDecl;
 
   /// \brief The template parameter list and optional requires-clause
   /// associated with this declaration; alternatively, a
@@ -481,9 +474,9 @@ public:
   /// \brief Initialize the underlying templated declaration and
   /// template parameters.
   void init(NamedDecl *templatedDecl, TemplateParameterList* templateParams) {
-assert(!TemplatedDecl.getPointer() && "TemplatedDecl already set!");
+assert(!TemplatedDecl && "TemplatedDecl already set!");
 assert(!TemplateParams && "TemplateParams already set!");
-TemplatedDecl.setPointer(templatedDecl);
+TemplatedDecl = templatedDecl;
 TemplateParams = templateParams;
   }
 };
@@ -996,7 +989,7 @@ public:
 
   /// Get the underlying function declaration of the template.
   FunctionDecl *getTemplatedDecl() const {
-return static_cast(TemplatedDecl.getPointer());
+return static_cast(TemplatedDecl);
   }
 
   /// Returns whether this template declaration defines the primary
@@ -2092,7 +2085,7 @@ public:
 
   /// \brief Get the underlying class declarations of the template.
   CXXRecordDecl *getTemplatedDecl() const {
-return static_cast(TemplatedDecl.getPointer());
+return static_cast(TemplatedDecl);
   }
 
   /// \brief Returns whether this template declaration defines the primary
@@ -2345,7 +2338,7 @@ protected:
 public:
   /// Get the underlying function declaration of the template.
   TypeAliasDecl *getTemplatedDecl() const {
-return static_cast(TemplatedDecl.getPointer());
+return static_cast(TemplatedDecl);
   }
 
 
@@ -2900,7 +2893,7 @@ public:
 
   /// \brief Get the underlying variable declarations of the template.
   VarDecl *getTemplatedDecl() const {
-return static_cast(TemplatedDecl.getPointer());
+return static_cast(TemplatedDecl);
   }
 
   /// \brief Returns whether this template declaration defines the primary
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 8725415af9..a4719c2260 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2366,30 +2366,15 @@