[clang] [clang] AST Visitor: skip empty qualifiers in QualifiedTemplateName (PR #93926)

2024-05-31 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov closed 
https://github.com/llvm/llvm-project/pull/93926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] AST Visitor: skip empty qualifiers in QualifiedTemplateName (PR #93926)

2024-05-31 Thread Matheus Izvekov via cfe-commits


@@ -855,10 +855,14 @@ bool 
RecursiveASTVisitor::TraverseDeclarationNameInfo(
 
 template 
 bool RecursiveASTVisitor::TraverseTemplateName(TemplateName Template) 
{
-  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
+  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
 TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
-  else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
-TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
+  } else if (QualifiedTemplateName *QTN =
+ Template.getAsQualifiedTemplateName()) {
+if (QTN->getQualifier()) {
+  TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
+}
+  }

mizvekov wrote:

I am going to merge since this fixes broken build bot.

Let's continue in post.

https://github.com/llvm/llvm-project/pull/93926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] AST Visitor: skip empty qualifiers in QualifiedTemplateName (PR #93926)

2024-05-31 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/93926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] AST Visitor: skip empty qualifiers in QualifiedTemplateName (PR #93926)

2024-05-31 Thread Matheus Izvekov via cfe-commits


@@ -855,10 +855,14 @@ bool 
RecursiveASTVisitor::TraverseDeclarationNameInfo(
 
 template 
 bool RecursiveASTVisitor::TraverseTemplateName(TemplateName Template) 
{
-  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
+  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
 TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
-  else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
-TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
+  } else if (QualifiedTemplateName *QTN =
+ Template.getAsQualifiedTemplateName()) {
+if (QTN->getQualifier()) {
+  TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
+}
+  }

mizvekov wrote:

I understand that looks cleaner at first glance, but the intention in the 
original code was to match each kind of `TemplateName`.

For example, this doesn't traverse `OverloadTemplateName` right now, but if we 
wanted to add it after this change, this would necessitate to refactor the if 
branches once again.

https://github.com/llvm/llvm-project/pull/93926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] AST Visitor: skip empty qualifiers in QualifiedTemplateName (PR #93926)

2024-05-31 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/93926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] AST Visitor: skip empty qualifiers in QualifiedTemplateName (PR #93926)

2024-05-31 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/93926

>From 55d946648a44e7a0b2fc45d20866f29ef4528c15 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Fri, 31 May 2024 02:53:18 -0300
Subject: [PATCH] [clang] AST Visitor: skip empty qualifiers in
 QualifiedTemplateName

This change was missed in #93433.
---
 clang/include/clang/AST/RecursiveASTVisitor.h | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 4bbb4380cdd7f..99093aa17972c 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -855,10 +855,14 @@ bool 
RecursiveASTVisitor::TraverseDeclarationNameInfo(
 
 template 
 bool RecursiveASTVisitor::TraverseTemplateName(TemplateName Template) 
{
-  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
+  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
 TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
-  else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
-TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
+  } else if (QualifiedTemplateName *QTN =
+ Template.getAsQualifiedTemplateName()) {
+if (QTN->getQualifier()) {
+  TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
+}
+  }
 
   return true;
 }

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


[clang] [clang] AST Visitor: skip empty qualifiers in QualifiedTemplateName (PR #93926)

2024-05-31 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/93926

>From db56ac3130164f570942d54686ffb39cf7d2ae33 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Fri, 31 May 2024 02:53:18 -0300
Subject: [PATCH] [clang] AST Visitor: skip empty qualifiers in
 QualifiedTemplateName

This change was missed in #93433.
---
 clang/include/clang/AST/RecursiveASTVisitor.h | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 4bbb4380cdd7f..d16074443b2dc 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -855,10 +855,14 @@ bool 
RecursiveASTVisitor::TraverseDeclarationNameInfo(
 
 template 
 bool RecursiveASTVisitor::TraverseTemplateName(TemplateName Template) 
{
-  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
+  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
 TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
-  else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
-TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
+  } else if (QualifiedTemplateName *QTN =
+ Template.getAsQualifiedTemplateName()) {
+if (T->getQualifier()) {
+  TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
+}
+  }
 
   return true;
 }

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


[clang] [libcxx] [clang] Preserve Qualifiers and type sugar in TemplateNames (PR #93433)

2024-05-31 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

@pcc https://github.com/llvm/llvm-project/pull/93926 should fix it, can you 
double check that it gets all issues?

https://github.com/llvm/llvm-project/pull/93433
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] AST Visitor: skip empty qualifiers in QualifiedTemplateName (PR #93926)

2024-05-30 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/93926

This change was missed in #93433.

>From dd8839b4f3294241b2a6df8bc10e869176baff72 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Fri, 31 May 2024 02:53:18 -0300
Subject: [PATCH] [clang] AST Visitor: skip empty qualifiers in
 QualifiedTemplateName

This change was missed in #93433.
---
 clang/include/clang/AST/RecursiveASTVisitor.h | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 4bbb4380cdd7f..28a90dffcb8dc 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -855,10 +855,13 @@ bool 
RecursiveASTVisitor::TraverseDeclarationNameInfo(
 
 template 
 bool RecursiveASTVisitor::TraverseTemplateName(TemplateName Template) 
{
-  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
+  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
 TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
-  else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
-TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
+  } else if (QualifiedTemplateName *QTN = 
Template.getAsQualifiedTemplateName()) {
+if (T->getQualifier()) {
+  TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
+}
+  }
 
   return true;
 }

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


[clang] [Clang][Sema] Diagnose variable template explicit specializations with storage-class-specifiers (PR #93873)

2024-05-30 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov commented:

Interestingly, only GCC errors on a case like this:

```
namespace {
  template int A = 0;
}
template<> int A = 0;
```

https://godbolt.org/z/TTjssKxz5

https://github.com/llvm/llvm-project/pull/93873
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Diagnose variable template explicit specializations with storage-class-specifiers (PR #93873)

2024-05-30 Thread Matheus Izvekov via cfe-commits


@@ -3561,6 +3562,7 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier 
AS, Declarator ,
   }
   return nullptr;
 }
+#endif

mizvekov wrote:

Leftover

https://github.com/llvm/llvm-project/pull/93873
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Diagnose variable template explicit specializations with storage-class-specifiers (PR #93873)

2024-05-30 Thread Matheus Izvekov via cfe-commits


@@ -3541,6 +3541,7 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier 
AS, Declarator ,
 
 IdentifierInfo *II = Name.getAsIdentifierInfo();
 
+#if 0

mizvekov wrote:

Leftover

https://github.com/llvm/llvm-project/pull/93873
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix a crash when a variable is captured by a block nested inside a lambda (PR #93749)

2024-05-30 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov commented:

I see it stops crashing, but is it actually working now?

Why `hasInit` returns true, but the variable doesn't actually have an 
initializer?
Shouldn't the fix go there?

https://github.com/llvm/llvm-project/pull/93749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Use correct TemplateName when transforming TemplateSpecializationType (PR #93411)

2024-05-30 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov commented:

So After we have formed a TemplateSpecializationType, we are done with the NNS. 
We keep it around in an ElaboratedType for type sugar only, it should not be 
needed to compile the program correctly anymore.

So I think this solution violates one important aspect of our AST design.

If we still need the NNS, we have to hold-off on building the TST until we 
don't.

https://github.com/llvm/llvm-project/pull/93411
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [clang] Preserve Qualifiers and type sugar in TemplateNames (PR #93433)

2024-05-30 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> Could you please take another look?

Sure, but let's take the discussion to the other PR.

https://github.com/llvm/llvm-project/pull/93433
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] text ast-dumper: dump TemplateName for TST and DTST (PR #93766)

2024-05-30 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov closed 
https://github.com/llvm/llvm-project/pull/93766
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] text ast-dumper: dump TemplateName for TST and DTST (PR #93766)

2024-05-30 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/93766

>From 774fa391d3ba427adf81919c361dd4f01e72d6a1 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 30 May 2024 01:24:53 -0300
Subject: [PATCH] [clang] text ast-dumper: dump TemplateName for TST and DTST

Implement AST text dumping of the TemplateName for
TemplateSpecializationType and VisitDeducedTemplateSpecializationType.
---
 clang/include/clang/AST/TemplateName.h|  4 ++
 clang/include/clang/AST/TextNodeDumper.h  |  3 +-
 clang/lib/AST/TextNodeDumper.cpp  | 43 
 clang/test/AST/ast-dump-ctad-alias.cpp|  6 ++-
 clang/test/AST/ast-dump-template-decls.cpp| 14 --
 clang/test/AST/ast-dump-template-name.cpp |  6 +++
 clang/test/AST/ast-dump-using-template.cpp| 18 +--
 clang/test/Import/builtin-template/test.cpp   | 11 +---
 .../aggregate-deduction-candidate.cpp |  4 +-
 clang/test/SemaTemplate/deduction-guide.cpp   | 22 
 clang/test/SemaTemplate/make_integer_seq.cpp  | 50 +--
 clang/test/SemaTemplate/type_pack_element.cpp | 34 +
 12 files changed, 149 insertions(+), 66 deletions(-)

diff --git a/clang/include/clang/AST/TemplateName.h 
b/clang/include/clang/AST/TemplateName.h
index 876be463c71d0..7aedc086ab7d0 100644
--- a/clang/include/clang/AST/TemplateName.h
+++ b/clang/include/clang/AST/TemplateName.h
@@ -360,6 +360,10 @@ class TemplateName {
   static TemplateName getFromVoidPointer(void *Ptr) {
 return TemplateName(Ptr);
   }
+
+  /// Structural equality.
+  bool operator==(TemplateName Other) const { return Storage == Other.Storage; 
}
+  bool operator!=(TemplateName Other) const { return !operator==(Other); }
 };
 
 /// Insertion operator for diagnostics.  This allows sending TemplateName's
diff --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 63fa16c9ec47c..caa33abd99e47 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -214,7 +214,8 @@ class TextNodeDumper
   void dumpNestedNameSpecifier(const NestedNameSpecifier *NNS);
   void dumpConceptReference(const ConceptReference *R);
   void dumpTemplateArgument(const TemplateArgument );
-  void dumpTemplateName(TemplateName TN);
+  void dumpBareTemplateName(TemplateName TN);
+  void dumpTemplateName(TemplateName TN, StringRef Label = {});
 
   void dumpDeclRef(const Decl *D, StringRef Label = {});
 
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index a0eedc71ea220..0e0e0a86f5cfc 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1126,7 +1126,32 @@ void TextNodeDumper::VisitIntegralTemplateArgument(const 
TemplateArgument ) {
   dumpTemplateArgument(TA);
 }
 
-void TextNodeDumper::dumpTemplateName(TemplateName TN) {
+void TextNodeDumper::dumpTemplateName(TemplateName TN, StringRef Label) {
+  AddChild(Label, [=] {
+{
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TN.print(SS, PrintPolicy);
+  }
+  OS << " '" << Str << "'";
+
+  if (TemplateName CanonTN = Context->getCanonicalTemplateName(TN);
+  CanonTN != TN) {
+llvm::SmallString<128> CanonStr;
+{
+  llvm::raw_svector_ostream SS(CanonStr);
+  CanonTN.print(SS, PrintPolicy);
+}
+if (CanonStr != Str)
+  OS << ":'" << CanonStr << "'";
+  }
+}
+dumpBareTemplateName(TN);
+  });
+}
+
+void TextNodeDumper::dumpBareTemplateName(TemplateName TN) {
   switch (TN.getKind()) {
   case TemplateName::Template:
 AddChild([=] { Visit(TN.getAsTemplateDecl()); });
@@ -1143,7 +1168,7 @@ void TextNodeDumper::dumpTemplateName(TemplateName TN) {
 if (QTN->hasTemplateKeyword())
   OS << " keyword";
 dumpNestedNameSpecifier(QTN->getQualifier());
-dumpTemplateName(QTN->getUnderlyingTemplate());
+dumpBareTemplateName(QTN->getUnderlyingTemplate());
 return;
   }
   case TemplateName::DependentTemplate: {
@@ -1162,7 +1187,7 @@ void TextNodeDumper::dumpTemplateName(TemplateName TN) {
 if (const TemplateTemplateParmDecl *P = STS->getParameter())
   AddChild("parameter", [=] { Visit(P); });
 dumpDeclRef(STS->getAssociatedDecl(), "associated");
-AddChild("replacement", [=] { dumpTemplateName(STS->getReplacement()); });
+dumpTemplateName(STS->getReplacement(), "replacement");
 return;
   }
   // FIXME: Implement these.
@@ -1182,14 +1207,14 @@ void TextNodeDumper::dumpTemplateName(TemplateName TN) {
 void TextNodeDumper::VisitTemplateTemplateArgument(const TemplateArgument ) 
{
   OS << " template";
   dumpTemplateArgument(TA);
-  dumpTemplateName(TA.getAsTemplate());
+  dumpBareTemplateName(TA.getAsTemplate());
 }
 
 void TextNodeDumper::VisitTemplateExpansionTemplateArgument(
 const TemplateArgument ) {
   OS << " template expansion";
   dumpTemplateArgument(TA);
- 

[clang] [clang] text ast-dumper: dump TemplateName for TST and DTST (PR #93766)

2024-05-30 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/93766
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] CWG150: add tests and change to unreleased (PR #93758)

2024-05-30 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov closed 
https://github.com/llvm/llvm-project/pull/93758
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [clang] Preserve Qualifiers and type sugar in TemplateNames (PR #93433)

2024-05-30 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

@nikic Thanks for the heads-up. I expected some impact. There are some ideas to 
regain that loss in follow up work.

https://github.com/llvm/llvm-project/pull/93433
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] CWG150: add tests and change to unreleased (PR #93758)

2024-05-30 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/93758

>From 5ecb3c36d40bb4a361b9af8776e9c4e45fa15b8d Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 29 May 2024 22:23:01 -0300
Subject: [PATCH] [clang] CWG150: add tests and change to unreleased

---
 clang/test/CXX/drs/cwg1xx.cpp | 40 +++
 clang/www/cxx_dr_status.html  |  2 +-
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/clang/test/CXX/drs/cwg1xx.cpp b/clang/test/CXX/drs/cwg1xx.cpp
index 6bc63760f8333..b39cc21fa4917 100644
--- a/clang/test/CXX/drs/cwg1xx.cpp
+++ b/clang/test/CXX/drs/cwg1xx.cpp
@@ -753,6 +753,46 @@ namespace cwg148 { // cwg148: yes
 
 // cwg149: na
 
+namespace cwg150 { // cwg150: 19
+  namespace p1 {
+template 
+class ARG { };
+
+template  class PARM>
+void f(PARM) { }
+
+void g() {
+  ARG x;
+  f(x);
+}
+  } // namespace p1
+
+  namespace p2 {
+template  class PARM>
+class C {
+  PARM pi;
+};
+  } // namespace p2
+
+  namespace n1 {
+struct Dense { static const unsigned int dim = 1; };
+
+template  class View,
+  typename Block>
+void operator+(float, View const&);
+
+template 
+class Lvalue_proxy { operator float() const; };
+
+void test_1d (void) {
+  Lvalue_proxy p;
+  float b;
+  b + p;
+}
+  } // namespace n1
+}
+
 namespace cwg151 { // cwg151: 3.1
   struct X {};
   typedef int X::*p;
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 4cce88fe0490f..628ee12992e6b 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -938,7 +938,7 @@ C++ defect report implementation status
 https://cplusplus.github.io/CWG/issues/150.html;>150
 C++17
 Template template parameters and default arguments
-Unknown
+Clang 19
   
   
 https://cplusplus.github.io/CWG/issues/151.html;>151

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


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-05-30 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov closed 
https://github.com/llvm/llvm-project/pull/80245
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-05-30 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

I have revived this PR after a long time.

The original ODR violation bad diagnostic from the GH issue is gone from main, 
so I have removed the test for it.
My best guess is that the ODR checking must have gotten weakened somehow.
I really don't have time to dig into it though.

The original bug is still there in main, is self evident from looking at the 
source code, and can be confirmed bad and that it gets fixed by just looking at 
the AST dump.

https://github.com/llvm/llvm-project/pull/80245
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-05-30 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/80245

>From 9763cc9e6f081bc28b74164c77a2b80ac42aec1c Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 1 Feb 2024 02:26:10 -0300
Subject: [PATCH] [clang] fix merging of UsingShadowDecl

Previously, when deciding if two UsingShadowDecls where mergeable,
we would incorrectly only look for both pointing to the exact redecla
ration, whereas the correct thing is to look for declarations to the
same entity.

This problem has existed as far back as 2013, introduced in commit
fd8634a09de71.

This problem could manifest itself as ODR check false positives
when importing modules.

Fixes: #80252
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/lib/AST/ASTContext.cpp| 2 +-
 clang/test/Modules/cxx20-decls.cppm | 4 ++--
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 44035f48cb3f9..9dc93f53fe716 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -813,6 +813,9 @@ Bug Fixes to C++ Support
 - Clang now allows ``@$``` in raw string literals. Fixes (#GH93130).
 - Fix an assertion failure when checking invalid ``this`` usage in the wrong 
context. (Fixes #GH91536).
 - Clang no longer models dependent NTTP arguments as 
``TemplateParamObjectDecl`` s. Fixes (#GH84052).
+- Fix incorrect merging of modules which contain using declarations which 
shadow
+  other declarations. This could manifest as ODR checker false positives.
+  Fixes (`#80252 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 06780ceba4074..73d3b152c49f1 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -6794,7 +6794,7 @@ bool ASTContext::isSameEntity(const NamedDecl *X, const 
NamedDecl *Y) const {
   // Using shadow declarations with the same target match.
   if (const auto *USX = dyn_cast(X)) {
 const auto *USY = cast(Y);
-return USX->getTargetDecl() == USY->getTargetDecl();
+return declaresSameEntity(USX->getTargetDecl(), USY->getTargetDecl());
   }
 
   // Using declarations with the same qualifier match. (We already know that
diff --git a/clang/test/Modules/cxx20-decls.cppm 
b/clang/test/Modules/cxx20-decls.cppm
index 9f0c40685b68f..0e8b59708ab4c 100644
--- a/clang/test/Modules/cxx20-decls.cppm
+++ b/clang/test/Modules/cxx20-decls.cppm
@@ -28,8 +28,8 @@ using xxx = baz::foo;
 // CHECK-NEXT: NamespaceDecl 0x[[BAZ_REDECL_ADDR:[^ ]*]] prev 0x[[BAZ_ADDR:[^ 
]*]]
 // CHECK:  TypeAliasDecl 0x[[ALIAS_REDECL_ADDR:[^ ]*]] prev 
0x[[ALIAS_ADDR:[^ ]*]]
 // FIXME: UsingShadowDecl should have been merged
-// CHECK:  UsingShadowDecl 0x{{[^ ]*}} <{{.*}}> col:{{.*}} imported in 
A. hidden implicit TypeAlias 0x[[ALIAS_REDECL_ADDR]] 'foo'
+// CHECK:  UsingShadowDecl 0x{{[^ ]*}} prev 0x[[SHADOW_ADDR:[^ ]*]] {{.*}} 
imported in A. {{.*}} 'foo'
 
 // CHECK-LABEL: Dumping baz:
 // CHECK-NEXT: NamespaceDecl 0x[[BAZ_ADDR]] <{{.*}}> line:{{.*}} baz
-// CHECK:  UsingShadowDecl 0x[[SHADOW_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} 
implicit TypeAlias 0x[[ALIAS_ADDR]] 'foo'
+// CHECK:  UsingShadowDecl 0x[[SHADOW_ADDR]] {{.*}} 'foo'

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


[clang] 498da62 - [NFC] [clang] add tests for merging of UsingShadowDecl

2024-05-29 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2024-05-30T02:56:57-03:00
New Revision: 498da62088b22ef1d4e90d6021a80ae7bab6abae

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

LOG: [NFC] [clang] add tests for merging of UsingShadowDecl

Added: 
clang/test/Modules/cxx20-decls.cppm

Modified: 


Removed: 




diff  --git a/clang/test/Modules/cxx20-decls.cppm 
b/clang/test/Modules/cxx20-decls.cppm
new file mode 100644
index 0..9f0c40685b68f
--- /dev/null
+++ b/clang/test/Modules/cxx20-decls.cppm
@@ -0,0 +1,35 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o 
%t/A.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cpp -fmodule-file=A=%t/A.pcm 
-fsyntax-only -verify -ast-dump-all -ast-dump-filter baz | FileCheck %s
+
+//--- foo.h
+namespace baz {
+  using foo = char;
+  using baz::foo;
+}
+
+//--- A.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module A;
+
+//--- B.cpp
+// expected-no-diagnostics
+#include "foo.h"
+import A;
+// Since modules are loaded lazily, force loading by performing a lookup.
+using xxx = baz::foo;
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl 0x[[BAZ_REDECL_ADDR:[^ ]*]] prev 0x[[BAZ_ADDR:[^ 
]*]]
+// CHECK:  TypeAliasDecl 0x[[ALIAS_REDECL_ADDR:[^ ]*]] prev 
0x[[ALIAS_ADDR:[^ ]*]]
+// FIXME: UsingShadowDecl should have been merged
+// CHECK:  UsingShadowDecl 0x{{[^ ]*}} <{{.*}}> col:{{.*}} imported in 
A. hidden implicit TypeAlias 0x[[ALIAS_REDECL_ADDR]] 'foo'
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl 0x[[BAZ_ADDR]] <{{.*}}> line:{{.*}} baz
+// CHECK:  UsingShadowDecl 0x[[SHADOW_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} 
implicit TypeAlias 0x[[ALIAS_ADDR]] 'foo'



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


[clang] [llvm] Add option to generate additional debug info for expression dereferencing pointer to pointers. (PR #81545)

2024-05-29 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

I think the fix for the breakage is to just pin the new test to a fixed triple 
like so `-triple x86_64-linux-gnu`.

https://github.com/llvm/llvm-project/pull/81545
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] CWG150: add tests and change to unreleased (PR #93758)

2024-05-29 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/93758

None

>From 834696f9b0a74c5a4c0d261480be6cff71fc91f5 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 29 May 2024 22:23:01 -0300
Subject: [PATCH] [clang] CWG150: add tests and change to unreleased

---
 clang/test/CXX/drs/cwg1xx.cpp | 40 +++
 clang/www/cxx_dr_status.html  |  2 +-
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/clang/test/CXX/drs/cwg1xx.cpp b/clang/test/CXX/drs/cwg1xx.cpp
index 6bc63760f8333..6016af67aae1a 100644
--- a/clang/test/CXX/drs/cwg1xx.cpp
+++ b/clang/test/CXX/drs/cwg1xx.cpp
@@ -753,6 +753,46 @@ namespace cwg148 { // cwg148: yes
 
 // cwg149: na
 
+namespace cwg150 { // cwg150: yes
+  namespace p1 {
+template 
+class ARG { };
+
+template  class PARM>
+void f(PARM) { }
+
+void g() {
+  ARG x;
+  f(x);
+}
+  } // namespace p1
+
+  namespace p2 {
+template  class PARM>
+class C {
+  PARM pi;
+};
+  } // namespace p2
+
+  namespace n1 {
+struct Dense { static const unsigned int dim = 1; };
+
+template  class View,
+  typename Block>
+void operator+(float, View const&);
+
+template 
+class Lvalue_proxy { operator float() const; };
+
+void test_1d (void) {
+  Lvalue_proxy p;
+  float b;
+  b + p;
+}
+  } // namespace n1
+}
+
 namespace cwg151 { // cwg151: 3.1
   struct X {};
   typedef int X::*p;
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 4cce88fe0490f..628ee12992e6b 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -938,7 +938,7 @@ C++ defect report implementation status
 https://cplusplus.github.io/CWG/issues/150.html;>150
 C++17
 Template template parameters and default arguments
-Unknown
+Clang 19
   
   
 https://cplusplus.github.io/CWG/issues/151.html;>151

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


[clang] [clang] fix printing of canonical template template parameters take 2 (PR #93448)

2024-05-29 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov closed 
https://github.com/llvm/llvm-project/pull/93448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix printing of canonical template template parameters take 2 (PR #93448)

2024-05-29 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/93448

>From 4ed34c959afa51328102ec037b418dbfc84ab063 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Mon, 27 May 2024 05:51:18 -0300
Subject: [PATCH] [clang] fix printing of canonical template template
 parameters take 2

Since they can also occur as the template name of
template specializations, handle them from TemplateName
printing instead of TemplateArgument.
---
 clang/lib/AST/TemplateBase.cpp  | 11 +--
 clang/lib/AST/TemplateName.cpp  | 14 ++
 clang/test/SemaTemplate/deduction-guide.cpp | 10 +-
 3 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index 6d3c843cfd29e..46f7b79b272ef 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -544,16 +544,7 @@ void TemplateArgument::print(const PrintingPolicy , 
raw_ostream ,
 break;
 
   case Template: {
-TemplateName TN = getAsTemplate();
-if (const auto *TD = TN.getAsTemplateDecl();
-TD && TD->getDeclName().isEmpty()) {
-  assert(isa(TD) &&
- "Unexpected anonymous template");
-  const auto *TTP = cast(TD);
-  Out << "template-parameter-" << TTP->getDepth() << "-" << 
TTP->getIndex();
-} else {
-  TN.print(Out, Policy);
-}
+getAsTemplate().print(Out, Policy);
 break;
   }
 
diff --git a/clang/lib/AST/TemplateName.cpp b/clang/lib/AST/TemplateName.cpp
index 3aae998eceeb0..3dbdad92813f6 100644
--- a/clang/lib/AST/TemplateName.cpp
+++ b/clang/lib/AST/TemplateName.cpp
@@ -292,6 +292,14 @@ void TemplateName::Profile(llvm::FoldingSetNodeID ) {
 
 void TemplateName::print(raw_ostream , const PrintingPolicy ,
  Qualified Qual) const {
+  auto handleAnonymousTTP = [](TemplateDecl *TD, raw_ostream ) {
+if (TemplateTemplateParmDecl *TTP = dyn_cast(TD);
+TTP && TTP->getIdentifier() == nullptr) {
+  OS << "template-parameter-" << TTP->getDepth() << "-" << TTP->getIndex();
+  return true;
+}
+return false;
+  };
   if (NameKind Kind = getKind();
   Kind == TemplateName::Template || Kind == TemplateName::UsingTemplate) {
 // After `namespace ns { using std::vector }`, what is the fully-qualified
@@ -304,6 +312,8 @@ void TemplateName::print(raw_ostream , const 
PrintingPolicy ,
 // names more often than to export them, thus using the original name is
 // most useful in this case.
 TemplateDecl *Template = getAsTemplateDecl();
+if (handleAnonymousTTP(Template, OS))
+  return;
 if (Qual == Qualified::None)
   OS << *Template;
 else
@@ -320,6 +330,10 @@ void TemplateName::print(raw_ostream , const 
PrintingPolicy ,
Underlying.getKind() == TemplateName::UsingTemplate);
 
 TemplateDecl *UTD = Underlying.getAsTemplateDecl();
+
+if (handleAnonymousTTP(UTD, OS))
+  return;
+
 if (IdentifierInfo *II = UTD->getIdentifier();
 Policy.CleanUglifiedParameters && II &&
 isa(UTD))
diff --git a/clang/test/SemaTemplate/deduction-guide.cpp 
b/clang/test/SemaTemplate/deduction-guide.cpp
index 96b4cd9622a24..100b580fe9f02 100644
--- a/clang/test/SemaTemplate/deduction-guide.cpp
+++ b/clang/test/SemaTemplate/deduction-guide.cpp
@@ -315,19 +315,19 @@ namespace TTP {
 // CHECK-NEXT:  |-TemplateTypeParmDecl {{.+}} class depth 0 index 0 T{{$}}
 // CHECK-NEXT:  |-TemplateTemplateParmDecl {{.+}} depth 0 index 1 TT{{$}}
 // CHECK-NEXT:  | `-TemplateTypeParmDecl {{.+}} class depth 1 index 0{{$}}
-// CHECK-NEXT:  |-CXXDeductionGuideDecl {{.+}} 'auto () -> B'{{$}}
-// CHECK-NEXT:  | `-ParmVarDecl {{.+}} ''{{$}}
+// CHECK-NEXT:  |-CXXDeductionGuideDecl {{.+}} 'auto 
(template-parameter-0-1) -> B'{{$}}
+// CHECK-NEXT:  | `-ParmVarDecl {{.+}} 'template-parameter-0-1'{{$}}
 // CHECK-NEXT:  `-CXXDeductionGuideDecl {{.+}} 'auto (A) -> TTP::B'
 // CHECK-NEXT:|-TemplateArgument type 'int'
 // CHECK-NEXT:| `-BuiltinType {{.+}} 'int'{{$}}
 // CHECK-NEXT:|-TemplateArgument template 'TTP::A'{{$}}
 // CHECK-NEXT:| `-ClassTemplateDecl {{.+}} A{{$}}
 // CHECK-NEXT:`-ParmVarDecl {{.+}} 'A':'TTP::A'{{$}}
-// CHECK-NEXT:  FunctionProtoType {{.+}} 'auto () -> B' dependent 
trailing_return cdecl{{$}}
+// CHECK-NEXT:  FunctionProtoType {{.+}} 'auto (template-parameter-0-1) -> 
B' dependent trailing_return cdecl{{$}}
 // CHECK-NEXT:  |-InjectedClassNameType {{.+}} 'B' dependent{{$}}
 // CHECK-NEXT:  | `-CXXRecord {{.+}} 'B'{{$}}
-// CHECK-NEXT:  `-ElaboratedType {{.+}} '' sugar dependent{{$}}
-// CHECK-NEXT:`-TemplateSpecializationType {{.+}} '' dependent {{$}}
+// CHECK-NEXT:  `-ElaboratedType {{.+}} 'template-parameter-0-1' sugar 
dependent{{$}}
+// CHECK-NEXT:`-TemplateSpecializationType {{.+}} 
'template-parameter-0-1' dependent template-parameter-0-1{{$}}
 // CHECK-NEXT:  `-TemplateArgument type 'T':'type-parameter-0-0'{{$}}
 // CHECK-NEXT:

[clang] [libcxx] [clang] fix printing of canonical template template parameters take 2 (PR #93448)

2024-05-29 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/93448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [clang] Preserve Qualifiers and type sugar in TemplateNames (PR #93433)

2024-05-29 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov closed 
https://github.com/llvm/llvm-project/pull/93433
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [clang] Preserve Qualifiers and type sugar in TemplateNames (PR #93433)

2024-05-29 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/93433
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-29 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov closed 
https://github.com/llvm/llvm-project/pull/93431
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Diagnose musttail instead of crash inside backend (PR #93267)

2024-05-29 Thread Matheus Izvekov via cfe-commits


@@ -3833,6 +3833,14 @@ def note_cannot_use_trivial_abi_reason : Note<
   "it is polymorphic|"
   "it has a base of a non-trivial class type|it has a virtual base|"
   "it has a __weak field|it has a field of a non-trivial class type}1">;
+def err_ppc_impossible_musttail: Error<
+  "'musttail' attribute for this call is impossible because %select{"
+  "long calls can not be tail called|"
+  "indirect calls can not be tail called|"
+  "external calls can not be tail called}0"

mizvekov wrote:

Should this perhaps mention this is a target specific restriction?

https://github.com/llvm/llvm-project/pull/93267
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Diagnose musttail instead of crash inside backend (PR #93267)

2024-05-29 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov approved this pull request.

Small nit, otherwise after you address @efriedma-quic 's concerns, this LGTM.

https://github.com/llvm/llvm-project/pull/93267
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Diagnose musttail instead of crash inside backend (PR #93267)

2024-05-29 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/93267
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-29 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/93431

>From fabcce0d7a4a1633b4d5ed49cb78fdf441e3c11e Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Fri, 24 May 2024 12:22:55 -0300
Subject: [PATCH] [clang] Improve ast-dumper text printing of TemplateArgument

This improves and unifies our approach to printing all template
arguments.

The same approach to printing types is extended to all
TemplateArguments: A sugared version is printed in quotes,
followed by printing the canonical form, unless they would print
the same.

Special improvements are done to add more detail to template template
arguments.

It's planned in a future patch to use this improved TemplateName
printer for other places besides TemplateArguments.

Note: The sugared/desugared printing does not show up for
TemplateNames in tests yet, because we do a poor job of preserving
their type sugar. This will be improved in a future patch.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/AST/TextNodeDumper.h  |   2 +
 clang/lib/AST/TextNodeDumper.cpp  | 104 +++---
 clang/test/AST/ast-dump-decl.cpp  |  25 +++--
 ...penmp-begin-declare-variant_template_2.cpp |   6 +-
 clang/test/AST/ast-dump-template-name.cpp |  54 +
 clang/test/AST/ast-dump-using-template.cpp|   8 +-
 .../constraints-explicit-instantiation.cpp|   6 +-
 clang/test/OpenMP/align_clause_ast_print.cpp  |   2 +-
 clang/test/OpenMP/generic_loop_ast_print.cpp  |   2 +-
 clang/test/OpenMP/interop_ast_print.cpp   |   2 +-
 clang/test/SemaOpenACC/sub-array-ast.cpp  |   2 +-
 .../aggregate-deduction-candidate.cpp |  18 +--
 clang/test/SemaTemplate/attributes.cpp|  64 +--
 clang/test/SemaTemplate/deduction-guide.cpp   |  19 ++--
 clang/test/SemaTemplate/make_integer_seq.cpp  |  68 +++-
 clang/test/SemaTemplate/type_pack_element.cpp |  20 ++--
 17 files changed, 276 insertions(+), 128 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-template-name.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bd92818f0c09d..e1c6d55eeeacd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -98,6 +98,8 @@ ABI Changes in This Version
 AST Dumping Potentially Breaking Changes
 
 
+- The text ast-dumper has improved printing of TemplateArguments.
+
 Clang Frontend Potentially Breaking Changes
 ---
 - Removed support for constructing on-stack ``TemplateArgumentList``\ s; 
interfaces should instead
diff --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 1fede6e462e92..63fa16c9ec47c 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -213,6 +213,8 @@ class TextNodeDumper
   void dumpTemplateSpecializationKind(TemplateSpecializationKind TSK);
   void dumpNestedNameSpecifier(const NestedNameSpecifier *NNS);
   void dumpConceptReference(const ConceptReference *R);
+  void dumpTemplateArgument(const TemplateArgument );
+  void dumpTemplateName(TemplateName TN);
 
   void dumpDeclRef(const Decl *D, StringRef Label = {});
 
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 4a1e94ffe283b..627f8d3477d4e 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -947,6 +947,26 @@ void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef 
Label) {
   });
 }
 
+void TextNodeDumper::dumpTemplateArgument(const TemplateArgument ) {
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TA.print(PrintPolicy, SS, /*IncludeType=*/true);
+  }
+  OS << " '" << Str << "'";
+
+  if (TemplateArgument CanonTA = Context->getCanonicalTemplateArgument(TA);
+  !CanonTA.structurallyEquals(TA)) {
+llvm::SmallString<128> CanonStr;
+{
+  llvm::raw_svector_ostream SS(CanonStr);
+  CanonTA.print(PrintPolicy, SS, /*IncludeType=*/true);
+}
+if (CanonStr != Str)
+  OS << ":'" << CanonStr << "'";
+  }
+}
+
 const char *TextNodeDumper::getCommandName(unsigned CommandID) {
   if (Traits)
 return Traits->getCommandInfo(CommandID)->Name;
@@ -1086,45 +1106,101 @@ void TextNodeDumper::VisitNullTemplateArgument(const 
TemplateArgument &) {
 
 void TextNodeDumper::VisitTypeTemplateArgument(const TemplateArgument ) {
   OS << " type";
-  dumpType(TA.getAsType());
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitDeclarationTemplateArgument(
 const TemplateArgument ) {
   OS << " decl";
+  dumpTemplateArgument(TA);
   dumpDeclRef(TA.getAsDecl());
 }
 
-void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &) {
+void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument ) {
   OS << " nullptr";
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitIntegralTemplateArgument(const 

[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)

2024-05-29 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> :( My goal now is to fix xtensor implementation/original tests, so this is 
> not a question of reduction. I need to understand where the compiler picked a 
> different specialization with relaxed argument matching.

So from the reduction you can see you have a problem where `svector` is 
matching a partial specialization of `xtype_for_shape`, which it shouldn't.

I see that you have a very similar problem to your first one, which is not 
fixed in main yet, where one of the partial specializations is ifdef'd out in a 
similar manner, that also very suspiciously looks like it should have been 
using the feature test macro instead:
https://github.com/xtensor-stack/xtensor/blob/d9c3782ed51027b2d00be3c26288b2f74e4dbe94/include/xtensor/xexpression_traits.hpp#L106

Does changing that to the feature test macro help?

https://github.com/llvm/llvm-project/pull/89807
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-28 Thread Matheus Izvekov via cfe-commits


@@ -947,6 +947,26 @@ void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef 
Label) {
   });
 }
 
+void TextNodeDumper::dumpTemplateArgument(const TemplateArgument ) {
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TA.print(PrintPolicy, SS, /*IncludeType=*/true);
+  }
+  OS << " '" << Str << "'";

mizvekov wrote:

I think the problem is that it makes little sense to show the char as a char 
literal for this integral dumper.

This is a resolved argument, it's not supposed to print as-written anyway.

This dumper is a debugging aid and the most important things are showing the 
value and the type it had.
The suffixed literals are going to obscure any typedefs. The char literal is 
going to obscure the signed-ness of the char besides that.

The most helpful representation is the cast followed by the plain literal. Ie 
(uintptr_t)28999
I think we should have a mode in that literal printer for that.

This would remove the plain ugly case of the char literal, but still the single 
quotes can appear within the printed type of the literal, which can already 
happen anyway.

Shafik would that also alleviate your concern?



https://github.com/llvm/llvm-project/pull/93431
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)

2024-05-28 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

No, I never used templight for this. I don't know of any easy to use tools that 
would work for a complex sample without modification.

Otherwise, the reduction wasn't difficult, it was mostly that creduce / cvise 
are lacking steps to reduce template type aliases, and the typedef within a 
class template equivalent.

There is also a seemingly complex pack expansion of a boolean expression, that 
you can just replace with false; cvise missed this as well.

https://github.com/llvm/llvm-project/pull/89807
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)

2024-05-28 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

@eaeltsin You example boils down to https://godbolt.org/z/axnanxP1z:
```C++
template  struct xtype_for_shape;
template  class S, class X, long N>
struct xtype_for_shape> {};

template  struct svector;
template struct xtype_for_shape>;
```
There is wide divergence between implementations on what happens during 
deduction, at least when NTTPs are involved.

clang picks the partial specialization, all other implementations pick the 
primary template.
This is not something new from this PR either.

The other implementations reject the matching in deduction, but all 
implementations agree that it would work if directly specified: 
https://godbolt.org/z/Gfs3dbYEe

(discounting EDG which doesn't seem to implement P0522R0 at all).

I think what clang does makes the most sense; I see no point in having 
deduction be more strict than the matching itself.

Also, you can create a similar situation with NTTPs where this adds new 
ambiguity: https://godbolt.org/z/cWPM7jWvd

https://github.com/llvm/llvm-project/pull/89807
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)

2024-05-28 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> @mizvekov - can you please take a look at https://godbolt.org/z/ahro3vnPd ?
> The reduced example fails somewhat differently, but it complains on `implicit 
> instantiation of undefined template` _with_ relaxed argument matching enabled 
> and compiles OK without...

Thank you, this example does look interesting. I will try to reduce further.

https://github.com/llvm/llvm-project/pull/89807
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-28 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> Should we also be updating JSONNodeDumper.cpp at the same time?

We would ideally update it as well.

Not necessarily in the same PR, as it's a separate change that doesn't need to 
be synchronized.

It's just not important to me, because I don't personally use the JSON dumper 
for debugging.

https://github.com/llvm/llvm-project/pull/93431
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Use correct TemplateName when transforming TemplateSpecializationType (PR #93411)

2024-05-28 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> > The problem here is the loss of the qualification on the TemplateNames
> > This patch fixes the problem, without taking any workarounds: #93433
> > It also doesn't cause any change in diagnostics in 
> > `clang/test/SemaTemplate/typename-specifier-3.cpp`.
> 
> I think we should report this message since `B::arg` in `A` is a NTTP.

Yeah, I am not saying that is wrong, but this needs more investigation.

I am not looking at this bug specifically: I just noticed my patch would have 
an effect here, and after testing it sure did, but I haven't looked closely.

Maybe I used the term 'fixes' incorrectly, as in my patch makes it not crash, 
but it's strange that type sugar would have a semantic effect here, that is not 
supposed to happen.

Again, thinking in first principles, without looking at this example too 
specifically, my intuition says that what might be happening here is that we 
transformed a `DependentTemplateSpecializationType` into a 
`TemplateSpecializationType` too early, before resolving everything that needs 
to be resolved related to it's TemplateName and NestedNameSpecifier.

https://github.com/llvm/llvm-project/pull/93411
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-28 Thread Matheus Izvekov via cfe-commits


@@ -947,6 +947,26 @@ void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef 
Label) {
   });
 }
 
+void TextNodeDumper::dumpTemplateArgument(const TemplateArgument ) {
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TA.print(PrintPolicy, SS, /*IncludeType=*/true);
+  }
+  OS << " '" << Str << "'";
+
+  if (TemplateArgument CanonTA = Context->getCanonicalTemplateArgument(TA);

mizvekov wrote:

`getCanonicalTemplateArgument` returns a TemplateArgument by value. These are 
small objects we don't manually allocate, and don't unique tem (but may unique 
things it references internally). This is similar to how we don't take const 
references to QualType.

https://github.com/llvm/llvm-project/pull/93431
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-28 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/93431
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-28 Thread Matheus Izvekov via cfe-commits


@@ -1086,45 +1106,100 @@ void TextNodeDumper::VisitNullTemplateArgument(const 
TemplateArgument &) {
 
 void TextNodeDumper::VisitTypeTemplateArgument(const TemplateArgument ) {
   OS << " type";
-  dumpType(TA.getAsType());
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitDeclarationTemplateArgument(
 const TemplateArgument ) {
   OS << " decl";
+  dumpTemplateArgument(TA);
   dumpDeclRef(TA.getAsDecl());
 }
 
-void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &) {
+void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument ) {
   OS << " nullptr";
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument ) 
{
-  OS << " integral " << TA.getAsIntegral();
+  OS << " integral";
+  dumpTemplateArgument(TA);
+}
+
+void TextNodeDumper::dumpTemplateName(TemplateName TN) {
+  switch (TN.getKind()) {
+  case TemplateName::Template:
+AddChild([=] { Visit(TN.getAsTemplateDecl()); });
+return;
+  case TemplateName::UsingTemplate: {
+const UsingShadowDecl *USD = TN.getAsUsingShadowDecl();
+AddChild([=] { Visit(USD); });
+AddChild("target", [=] { Visit(USD->getTargetDecl()); });
+return;
+  }
+  case TemplateName::QualifiedTemplate: {
+OS << " qualified";
+const QualifiedTemplateName *QTN = TN.getAsQualifiedTemplateName();
+if (QTN->hasTemplateKeyword())
+  OS << " keyword";
+dumpNestedNameSpecifier(QTN->getQualifier());
+dumpTemplateName(QTN->getUnderlyingTemplate());
+return;
+  }
+  case TemplateName::DependentTemplate: {
+OS << " dependent";
+const DependentTemplateName *DTN = TN.getAsDependentTemplateName();
+dumpNestedNameSpecifier(DTN->getQualifier());
+return;
+  }
+  case TemplateName::SubstTemplateTemplateParm: {
+const SubstTemplateTemplateParmStorage *STS =
+TN.getAsSubstTemplateTemplateParm();
+OS << " subst index " << STS->getIndex();
+if (std::optional PackIndex = STS->getPackIndex())
+  OS << " pack_index " << *PackIndex;

mizvekov wrote:

Oh, okay, I see the confusion.

`subst index` in this case is not one thing, they are two separate things. It 
only looks that way because we are avoiding writing to the stream two separate 
times. Ie see the other TemplateArgument kinds above.

`subst` refers to the kind of TemplateArgument, ie: type, expr, template, 
subst, subst_pack, etc.
`index 0` refers to the position in the parameter list this substitution 
represents.
`pack_index 0` refers to the position in the pack, in case `index` above points 
to a pack parameter. This 'pack_index` is the term we already use in the dumper 
for other Subst nodes.

I agree this is not great, but the way we format this text ast-dumper leads to 
this sort of confusion.

Any other suggestions?

https://github.com/llvm/llvm-project/pull/93431
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Be const-correct with all uses of `Module *`. (PR #93493)

2024-05-28 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> `const_cast` here is a relatively recent addition, and I checked out with 
> @erichkeane that the use case (pack expansion) is legit. According to the 
> approach you're suggesting, the one who wrote this `const_cast` should 
> instead refactor the MLTAL to use `llvm::MutableArrayRef`.

Take a guess who that person was :grin:

> I tried, pretty hard, but ultimately failed. The change turned out to be 
> touching every corner of our template engine, with no end in sight.

Oh well, sorry I wasn't around to advise against it.


https://github.com/llvm/llvm-project/pull/93493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Be const-correct with all uses of `Module *`. (PR #93493)

2024-05-28 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

One suggestion, if you are going to go about this problem systematically, try 
to tackle the hardest problems first.

For example: Try to make `MultiLevelTemplateArgumentList` const correct. I 
would like other suggestions as well.

https://github.com/llvm/llvm-project/pull/93493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Be const-correct with all uses of `Module *`. (PR #93493)

2024-05-28 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> That's the opposite of my view. Mutation needs to be justified. "What if we 
> need it later" can be used to justify anything, and if we do need it later 
> then we change the code then. Until that point, readers can see `const` and 
> know that things aren't being changed out from under them while reasoning 
> about what the code does.

I agree that works well for small code bases, but in LLVM some of these changes 
lead to so much churn, I start to question their benefit. Speaking from a been 
there, done that POV.


https://github.com/llvm/llvm-project/pull/93493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Use StructuralValues to model dependent NTTP arguments (PR #93556)

2024-05-28 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

LGTM as well, thanks!

https://github.com/llvm/llvm-project/pull/93556
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Be const-correct with all uses of `Module *`. (PR #93493)

2024-05-28 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> Errr, not certain I agree with this -- that basically is "admit defeat and 
> stop aiming for const correctness."

Well, I am saying, add const to places we are pretty sure we will never change, 
and leave const out when in doubt.
Don't add const just because we don't need mutation today.

https://github.com/llvm/llvm-project/pull/93493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Be const-correct with all uses of `Module *`. (PR #93493)

2024-05-28 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

I could agree on being const correct here, but mostly by removing const, not 
adding more, in the general case.

The problem here is that this is such a big code base, and where some times 
parameters can be passed down from function to function for a very long depth, 
that this can make some seemingly small local changes propagate into a lot of 
code churn.

https://github.com/llvm/llvm-project/pull/93493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] CTAD alias: fix transformation for require-clause expr Part2. (PR #93533)

2024-05-28 Thread Matheus Izvekov via cfe-commits


@@ -3100,6 +3118,7 @@ BuildDeductionGuideForTypeAlias(Sema ,
 Context.getInjectedTemplateArg(NewParam));
 TransformedDeducedAliasArgs[AliasTemplateParamIdx] = NewTemplateArgument;
   }
+  unsigned UndeducedTemplateParameterStartIndex = FPrimeTemplateParams.size();

mizvekov wrote:

Nit, this is a bit of a mouth full:
```suggestion
  unsigned FirstUndeducedParamIdx = FPrimeTemplateParams.size();
```

https://github.com/llvm/llvm-project/pull/93533
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] CTAD alias: fix transformation for require-clause expr Part2. (PR #93533)

2024-05-28 Thread Matheus Izvekov via cfe-commits


@@ -2882,7 +2899,8 @@ buildAssociatedConstraints(Sema , 
FunctionTemplateDecl *F,
   // We add the outer template arguments which is [int] to the multi-level arg
   // list to ensure that the occurrence U in `C` will be replaced with int
   // during the substitution.
-  if (F->getInstantiatedFromMemberTemplate()) {
+  if (F->getLexicalDeclContext()->getDeclKind() ==
+  clang::Decl::ClassTemplateSpecialization) {

mizvekov wrote:

Should this apply to a ClassTemplatePartialSpecialization as well?

https://github.com/llvm/llvm-project/pull/93533
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] CTAD alias: fix transformation for require-clause expr Part2. (PR #93533)

2024-05-28 Thread Matheus Izvekov via cfe-commits


@@ -2840,8 +2841,22 @@ buildAssociatedConstraints(Sema , 
FunctionTemplateDecl *F,
 
   for (unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
 const auto  = DeduceResults[Index];
-if (D.isNull())
+if (D.isNull()) { // non-deduced template parameters of f
+  auto TP = F->getTemplateParameters()->getParam(Index);
+  MultiLevelTemplateArgumentList Args;
+  Args.setKind(TemplateSubstitutionKind::Rewrite);
+  Args.addOuterTemplateArguments(TemplateArgsForBuildingRC);
+  // Rebuild the template parameter with updated depth and index.
+  NamedDecl *NewParam = transformTemplateParameter(
+  SemaRef, F->getDeclContext(), TP, Args,
+  /*NewIndex=*/UndeducedTemplateParameterStartIndex++,
+  getTemplateParameterDepth(TP) + AdjustDepth);

mizvekov wrote:

Took me a while to spot that one:
```suggestion
  NamedDecl *NewParam = transformTemplateParameter(
  SemaRef, F->getDeclContext(), TP, Args,
  /*NewIndex=*/UndeducedTemplateParameterStartIndex,
  getTemplateParameterDepth(TP) + AdjustDepth);
  UndeducedTemplateParameterStartIndex += 1;
```

https://github.com/llvm/llvm-project/pull/93533
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] CTAD alias: fix transformation for require-clause expr Part2. (PR #93533)

2024-05-28 Thread Matheus Izvekov via cfe-commits


@@ -2840,8 +2841,22 @@ buildAssociatedConstraints(Sema , 
FunctionTemplateDecl *F,
 
   for (unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
 const auto  = DeduceResults[Index];
-if (D.isNull())
+if (D.isNull()) { // non-deduced template parameters of f
+  auto TP = F->getTemplateParameters()->getParam(Index);

mizvekov wrote:

Small nit:
```suggestion
  NamedDecl *TP = F->getTemplateParameters()->getParam(Index);
```

https://github.com/llvm/llvm-project/pull/93533
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-27 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/93431

>From 86e3852d0501bd24738c094359799c72781ad808 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Fri, 24 May 2024 12:22:55 -0300
Subject: [PATCH] [clang] Improve ast-dumper text printing of TemplateArgument

This improves and unifies our approach to printing all template
arguments.

The same approach to printing types is extended to all
TemplateArguments: A sugared version is printed in quotes,
followed by printing the canonical form, unless they would print
the same.

Special improvements are done to add more detail to template template
arguments.

It's planned in a future patch to use this improved TemplateName
printer for other places besides TemplateArguments.

Note: The sugared/desugared printing does not show up for
TemplateNames in tests yet, because we do a poor job of preserving
their type sugar. This will be improved in a future patch.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/AST/TextNodeDumper.h  |   2 +
 clang/lib/AST/TextNodeDumper.cpp  | 103 +++---
 clang/test/AST/ast-dump-decl.cpp  |  25 +++--
 ...penmp-begin-declare-variant_template_2.cpp |   6 +-
 clang/test/AST/ast-dump-template-name.cpp |  54 +
 clang/test/AST/ast-dump-using-template.cpp|   8 +-
 .../constraints-explicit-instantiation.cpp|   6 +-
 clang/test/OpenMP/align_clause_ast_print.cpp  |   2 +-
 clang/test/OpenMP/generic_loop_ast_print.cpp  |   2 +-
 clang/test/OpenMP/interop_ast_print.cpp   |   2 +-
 clang/test/SemaOpenACC/sub-array-ast.cpp  |   2 +-
 .../aggregate-deduction-candidate.cpp |  18 +--
 clang/test/SemaTemplate/attributes.cpp|  64 +--
 clang/test/SemaTemplate/deduction-guide.cpp   |  19 ++--
 clang/test/SemaTemplate/make_integer_seq.cpp  |  68 +++-
 clang/test/SemaTemplate/type_pack_element.cpp |  20 ++--
 17 files changed, 275 insertions(+), 128 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-template-name.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 825e91876ffce..f7562ce74f4ed 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -98,6 +98,8 @@ ABI Changes in This Version
 AST Dumping Potentially Breaking Changes
 
 
+- The text ast-dumper has improved printing of TemplateArguments.
+
 Clang Frontend Potentially Breaking Changes
 ---
 - Removed support for constructing on-stack ``TemplateArgumentList``\ s; 
interfaces should instead
diff --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 1fede6e462e92..63fa16c9ec47c 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -213,6 +213,8 @@ class TextNodeDumper
   void dumpTemplateSpecializationKind(TemplateSpecializationKind TSK);
   void dumpNestedNameSpecifier(const NestedNameSpecifier *NNS);
   void dumpConceptReference(const ConceptReference *R);
+  void dumpTemplateArgument(const TemplateArgument );
+  void dumpTemplateName(TemplateName TN);
 
   void dumpDeclRef(const Decl *D, StringRef Label = {});
 
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 4a1e94ffe283b..ed343ffb74124 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -947,6 +947,26 @@ void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef 
Label) {
   });
 }
 
+void TextNodeDumper::dumpTemplateArgument(const TemplateArgument ) {
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TA.print(PrintPolicy, SS, /*IncludeType=*/true);
+  }
+  OS << " '" << Str << "'";
+
+  if (TemplateArgument CanonTA = Context->getCanonicalTemplateArgument(TA);
+  !CanonTA.structurallyEquals(TA)) {
+llvm::SmallString<128> CanonStr;
+{
+  llvm::raw_svector_ostream SS(CanonStr);
+  CanonTA.print(PrintPolicy, SS, /*IncludeType=*/true);
+}
+if (CanonStr != Str)
+  OS << ":'" << CanonStr << "'";
+  }
+}
+
 const char *TextNodeDumper::getCommandName(unsigned CommandID) {
   if (Traits)
 return Traits->getCommandInfo(CommandID)->Name;
@@ -1086,45 +1106,100 @@ void TextNodeDumper::VisitNullTemplateArgument(const 
TemplateArgument &) {
 
 void TextNodeDumper::VisitTypeTemplateArgument(const TemplateArgument ) {
   OS << " type";
-  dumpType(TA.getAsType());
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitDeclarationTemplateArgument(
 const TemplateArgument ) {
   OS << " decl";
+  dumpTemplateArgument(TA);
   dumpDeclRef(TA.getAsDecl());
 }
 
-void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &) {
+void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument ) {
   OS << " nullptr";
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitIntegralTemplateArgument(const 

[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-27 Thread Matheus Izvekov via cfe-commits


@@ -1086,45 +1106,100 @@ void TextNodeDumper::VisitNullTemplateArgument(const 
TemplateArgument &) {
 
 void TextNodeDumper::VisitTypeTemplateArgument(const TemplateArgument ) {
   OS << " type";
-  dumpType(TA.getAsType());
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitDeclarationTemplateArgument(
 const TemplateArgument ) {
   OS << " decl";
+  dumpTemplateArgument(TA);
   dumpDeclRef(TA.getAsDecl());
 }
 
-void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &) {
+void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument ) {
   OS << " nullptr";
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument ) 
{
-  OS << " integral " << TA.getAsIntegral();
+  OS << " integral";
+  dumpTemplateArgument(TA);
+}
+
+void TextNodeDumper::dumpTemplateName(TemplateName TN) {
+  switch (TN.getKind()) {
+  case TemplateName::Template:
+AddChild([=] { Visit(TN.getAsTemplateDecl()); });
+return;
+  case TemplateName::UsingTemplate: {
+const UsingShadowDecl *USD = TN.getAsUsingShadowDecl();
+AddChild([=] { Visit(USD); });
+AddChild("target", [=] { Visit(USD->getTargetDecl()); });
+return;
+  }
+  case TemplateName::QualifiedTemplate: {
+OS << " qualified";
+const QualifiedTemplateName *QTN = TN.getAsQualifiedTemplateName();
+if (QTN->hasTemplateKeyword())
+  OS << " keyword";
+dumpNestedNameSpecifier(QTN->getQualifier());
+dumpTemplateName(QTN->getUnderlyingTemplate());
+return;
+  }
+  case TemplateName::DependentTemplate: {
+OS << " dependent";
+const DependentTemplateName *DTN = TN.getAsDependentTemplateName();
+dumpNestedNameSpecifier(DTN->getQualifier());
+return;
+  }
+  case TemplateName::SubstTemplateTemplateParm: {
+const SubstTemplateTemplateParmStorage *STS =
+TN.getAsSubstTemplateTemplateParm();
+OS << " subst index " << STS->getIndex();
+if (std::optional PackIndex = STS->getPackIndex())
+  OS << " pack_index " << *PackIndex;

mizvekov wrote:

The spelling `pack_index` is already used for the same purpose in the Subst* 
node printers.

The flags in the AST text dumper are separated by spaces, I think this spelling 
could mislead someone to think these are two separate things.

Any other ideas? If we make a change here, we better change the other printer 
as well.

https://github.com/llvm/llvm-project/pull/93431
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-27 Thread Matheus Izvekov via cfe-commits


@@ -947,6 +947,26 @@ void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef 
Label) {
   });
 }
 
+void TextNodeDumper::dumpTemplateArgument(const TemplateArgument ) {
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TA.print(PrintPolicy, SS, /*IncludeType=*/true);
+  }
+  OS << " '" << Str << "'";

mizvekov wrote:

Yeah, the quotes are what we already do for types, and I think the problem 
shows up there, though of course not as self-evident as here.

I don't think there is a formal solution besides to start escaping the string.

https://github.com/llvm/llvm-project/pull/93431
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-27 Thread Matheus Izvekov via cfe-commits


@@ -947,6 +947,26 @@ void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef 
Label) {
   });
 }
 
+void TextNodeDumper::dumpTemplateArgument(const TemplateArgument ) {
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TA.print(PrintPolicy, SS, /*IncludeType=*/true);
+  }
+  OS << " '" << Str << "'";
+
+  if (TemplateArgument CanonTA = Context->getCanonicalTemplateArgument(TA);
+  !CanonTA.structurallyEquals(TA)) {
+llvm::SmallString<128> CanonStr;
+{
+  llvm::raw_svector_ostream SS(CanonStr);
+  CanonTA.print(PrintPolicy, SS, /*IncludeType=*/true);
+}
+if (CanonStr != Str)
+  OS << ":'" << CanonStr << "'";
+  }

mizvekov wrote:

This starts showing up in tests after the improvements in 
https://github.com/llvm/llvm-project/pull/93433,
which is stacked on top of this PR.

Take a look at some of the modified AST tests there.

https://github.com/llvm/llvm-project/pull/93431
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0f85b25 - [clang] NFC: add a test case for TemplateName canonical type print issue

2024-05-27 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2024-05-27T04:45:20-03:00
New Revision: 0f85b25f51a3e06c48b3fe8042a3de1cf0e635d7

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

LOG: [clang] NFC: add a test case for TemplateName canonical type print issue

Added: 


Modified: 
clang/test/SemaTemplate/deduction-guide.cpp

Removed: 




diff  --git a/clang/test/SemaTemplate/deduction-guide.cpp 
b/clang/test/SemaTemplate/deduction-guide.cpp
index c38b647e42f4c..91c35d98fbf57 100644
--- a/clang/test/SemaTemplate/deduction-guide.cpp
+++ b/clang/test/SemaTemplate/deduction-guide.cpp
@@ -299,3 +299,34 @@ using AFoo = Foo>;
 // CHECK-NEXT:   `-ParmVarDecl {{.*}} 'G'
 
 AFoo aa(G{});
+
+namespace TTP {
+  template struct A {};
+
+  template struct B {
+template typename TT> B(TT);
+  };
+
+  B b(A{});
+} // namespace TTP
+
+// CHECK-LABEL: Dumping TTP:::
+// CHECK-NEXT:  FunctionTemplateDecl 0x{{.+}} <{{.+}}:[[# @LINE - 7]]:5, 
col:51>
+// CHECK-NEXT:  |-TemplateTypeParmDecl {{.+}} class depth 0 index 0 T{{$}}
+// CHECK-NEXT:  |-TemplateTemplateParmDecl {{.+}} depth 0 index 1 TT{{$}}
+// CHECK-NEXT:  | `-TemplateTypeParmDecl {{.+}} class depth 1 index 0{{$}}
+// CHECK-NEXT:  |-CXXDeductionGuideDecl {{.+}} 'auto () -> B'{{$}}
+// CHECK-NEXT:  | `-ParmVarDecl {{.+}} ''{{$}}
+// CHECK-NEXT:  `-CXXDeductionGuideDecl {{.+}} 'auto (A) -> TTP::B'
+// CHECK-NEXT:|-TemplateArgument type 'int'
+// CHECK-NEXT:| `-BuiltinType {{.+}} 'int'{{$}}
+// CHECK-NEXT:|-TemplateArgument template A
+// CHECK-NEXT:`-ParmVarDecl {{.+}} 'A':'TTP::A'{{$}}
+// CHECK-NEXT:  FunctionProtoType {{.+}} 'auto () -> B' dependent 
trailing_return cdecl{{$}}
+// CHECK-NEXT:  |-InjectedClassNameType {{.+}} 'B' dependent{{$}}
+// CHECK-NEXT:  | `-CXXRecord {{.+}} 'B'{{$}}
+// CHECK-NEXT:  `-ElaboratedType {{.+}} '' sugar dependent{{$}}
+// CHECK-NEXT:`-TemplateSpecializationType {{.+}} '' dependent {{$}}
+// CHECK-NEXT:  `-TemplateArgument type 'T'{{$}}
+// CHECK-NEXT:`-TemplateTypeParmType {{.+}} 'T' dependent depth 0 
index 0{{$}}
+// CHECK-NEXT:  `-TemplateTypeParm {{.+}} 'T'{{$}}



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


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-26 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/93431

>From f9892ebed002d73c74f44629e926386006f7bec1 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Fri, 24 May 2024 12:22:55 -0300
Subject: [PATCH] [clang] Improve ast-dumper text printing of TemplateArgument

This improves and unifies our approach to printing all template
arguments.

The same approach to printing types is extended to all
TemplateArguments: A sugared version is printed in quotes,
followed by printing the canonical form, unless they would print
the same.

Special improvements are done to add more detail to template template
arguments.

It's planned in a future patch to use this improved TemplateName
printer for other places besides TemplateArguments.

Note: The sugared/desugared printing does not show up for
TemplateNames in tests yet, because we do a poor job of preserving
their type sugar. This will be improved in a future patch.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/AST/TextNodeDumper.h  |   2 +
 clang/lib/AST/TextNodeDumper.cpp  | 103 +++---
 clang/test/AST/ast-dump-decl.cpp  |  25 +++--
 ...penmp-begin-declare-variant_template_2.cpp |   6 +-
 clang/test/AST/ast-dump-template-name.cpp |  54 +
 clang/test/AST/ast-dump-using-template.cpp|   8 +-
 .../constraints-explicit-instantiation.cpp|   6 +-
 clang/test/OpenMP/align_clause_ast_print.cpp  |   2 +-
 clang/test/OpenMP/generic_loop_ast_print.cpp  |   2 +-
 clang/test/OpenMP/interop_ast_print.cpp   |   2 +-
 clang/test/SemaOpenACC/sub-array-ast.cpp  |   2 +-
 .../aggregate-deduction-candidate.cpp |  18 +--
 clang/test/SemaTemplate/attributes.cpp|  64 +--
 clang/test/SemaTemplate/deduction-guide.cpp   |  14 +--
 clang/test/SemaTemplate/make_integer_seq.cpp  |  68 +++-
 clang/test/SemaTemplate/type_pack_element.cpp |  20 ++--
 17 files changed, 272 insertions(+), 126 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-template-name.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 825e91876ffce..f7562ce74f4ed 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -98,6 +98,8 @@ ABI Changes in This Version
 AST Dumping Potentially Breaking Changes
 
 
+- The text ast-dumper has improved printing of TemplateArguments.
+
 Clang Frontend Potentially Breaking Changes
 ---
 - Removed support for constructing on-stack ``TemplateArgumentList``\ s; 
interfaces should instead
diff --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 1fede6e462e92..63fa16c9ec47c 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -213,6 +213,8 @@ class TextNodeDumper
   void dumpTemplateSpecializationKind(TemplateSpecializationKind TSK);
   void dumpNestedNameSpecifier(const NestedNameSpecifier *NNS);
   void dumpConceptReference(const ConceptReference *R);
+  void dumpTemplateArgument(const TemplateArgument );
+  void dumpTemplateName(TemplateName TN);
 
   void dumpDeclRef(const Decl *D, StringRef Label = {});
 
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 4a1e94ffe283b..ed343ffb74124 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -947,6 +947,26 @@ void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef 
Label) {
   });
 }
 
+void TextNodeDumper::dumpTemplateArgument(const TemplateArgument ) {
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TA.print(PrintPolicy, SS, /*IncludeType=*/true);
+  }
+  OS << " '" << Str << "'";
+
+  if (TemplateArgument CanonTA = Context->getCanonicalTemplateArgument(TA);
+  !CanonTA.structurallyEquals(TA)) {
+llvm::SmallString<128> CanonStr;
+{
+  llvm::raw_svector_ostream SS(CanonStr);
+  CanonTA.print(PrintPolicy, SS, /*IncludeType=*/true);
+}
+if (CanonStr != Str)
+  OS << ":'" << CanonStr << "'";
+  }
+}
+
 const char *TextNodeDumper::getCommandName(unsigned CommandID) {
   if (Traits)
 return Traits->getCommandInfo(CommandID)->Name;
@@ -1086,45 +1106,100 @@ void TextNodeDumper::VisitNullTemplateArgument(const 
TemplateArgument &) {
 
 void TextNodeDumper::VisitTypeTemplateArgument(const TemplateArgument ) {
   OS << " type";
-  dumpType(TA.getAsType());
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitDeclarationTemplateArgument(
 const TemplateArgument ) {
   OS << " decl";
+  dumpTemplateArgument(TA);
   dumpDeclRef(TA.getAsDecl());
 }
 
-void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &) {
+void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument ) {
   OS << " nullptr";
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitIntegralTemplateArgument(const 

[clang] [Clang][Sema] Use correct TemplateName when transforming TemplateSpecializationType (PR #93411)

2024-05-26 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov commented:

The problem here is the loss of the qualification on the TemplateNames

This patch fixes the problem, without taking any workarounds: 
https://github.com/llvm/llvm-project/pull/93433

It also doesn't cause any change in diagnostics in 
`clang/test/SemaTemplate/typename-specifier-3.cpp`.

https://github.com/llvm/llvm-project/pull/93411
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-26 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/93431

>From 031e7c235ce5cbae31504c21eeecc7655fbd1566 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Fri, 24 May 2024 12:22:55 -0300
Subject: [PATCH] [clang] Improve ast-dumper text printing of TemplateArgument

This improves and unifies our approach to printing all template
arguments.

The same approach to printing types is extended to all
TemplateArguments: A sugared version is printed in quotes,
followed by printing the canonical form, unless they would print
the same.

Special improvements are done to add more detail to template template
arguments.

It's planned in a future patch to use this improved TemplateName
printer for other places besides TemplateArguments.

Note: The sugared/desugared printing does not show up for
TemplateNames in tests yet, because we do a poor job of preserving
their type sugar. This will be improved in a future patch.
---
 clang/docs/ReleaseNotes.rst   |   5 +
 clang/include/clang/AST/TextNodeDumper.h  |   2 +
 clang/lib/AST/TextNodeDumper.cpp  | 103 +++---
 clang/test/AST/ast-dump-decl.cpp  |  25 +++--
 ...penmp-begin-declare-variant_template_2.cpp |   6 +-
 clang/test/AST/ast-dump-template-name.cpp |  54 +
 clang/test/AST/ast-dump-using-template.cpp|   8 +-
 .../constraints-explicit-instantiation.cpp|   6 +-
 clang/test/OpenMP/align_clause_ast_print.cpp  |   2 +-
 clang/test/OpenMP/generic_loop_ast_print.cpp  |   2 +-
 clang/test/OpenMP/interop_ast_print.cpp   |   2 +-
 clang/test/SemaOpenACC/sub-array-ast.cpp  |   2 +-
 .../aggregate-deduction-candidate.cpp |  16 +--
 clang/test/SemaTemplate/attributes.cpp|  64 +--
 clang/test/SemaTemplate/deduction-guide.cpp   |  14 +--
 clang/test/SemaTemplate/make_integer_seq.cpp  |  68 +++-
 clang/test/SemaTemplate/type_pack_element.cpp |  20 ++--
 17 files changed, 274 insertions(+), 125 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-template-name.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 825e91876ffce..403a107edef17 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -818,6 +818,11 @@ Miscellaneous Clang Crashes Fixed
   when ``-fdump-record-layouts-complete`` is passed. Fixes #GH83684.
 - Unhandled StructuralValues in the template differ (#GH93068).
 
+Miscellaneous Clang Improvements
+^
+
+- The text ast-dumper has improved printing of TemplateArguments.
+
 OpenACC Specific Changes
 
 
diff --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 1fede6e462e92..63fa16c9ec47c 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -213,6 +213,8 @@ class TextNodeDumper
   void dumpTemplateSpecializationKind(TemplateSpecializationKind TSK);
   void dumpNestedNameSpecifier(const NestedNameSpecifier *NNS);
   void dumpConceptReference(const ConceptReference *R);
+  void dumpTemplateArgument(const TemplateArgument );
+  void dumpTemplateName(TemplateName TN);
 
   void dumpDeclRef(const Decl *D, StringRef Label = {});
 
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 4a1e94ffe283b..ed343ffb74124 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -947,6 +947,26 @@ void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef 
Label) {
   });
 }
 
+void TextNodeDumper::dumpTemplateArgument(const TemplateArgument ) {
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TA.print(PrintPolicy, SS, /*IncludeType=*/true);
+  }
+  OS << " '" << Str << "'";
+
+  if (TemplateArgument CanonTA = Context->getCanonicalTemplateArgument(TA);
+  !CanonTA.structurallyEquals(TA)) {
+llvm::SmallString<128> CanonStr;
+{
+  llvm::raw_svector_ostream SS(CanonStr);
+  CanonTA.print(PrintPolicy, SS, /*IncludeType=*/true);
+}
+if (CanonStr != Str)
+  OS << ":'" << CanonStr << "'";
+  }
+}
+
 const char *TextNodeDumper::getCommandName(unsigned CommandID) {
   if (Traits)
 return Traits->getCommandInfo(CommandID)->Name;
@@ -1086,45 +1106,100 @@ void TextNodeDumper::VisitNullTemplateArgument(const 
TemplateArgument &) {
 
 void TextNodeDumper::VisitTypeTemplateArgument(const TemplateArgument ) {
   OS << " type";
-  dumpType(TA.getAsType());
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitDeclarationTemplateArgument(
 const TemplateArgument ) {
   OS << " decl";
+  dumpTemplateArgument(TA);
   dumpDeclRef(TA.getAsDecl());
 }
 
-void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &) {
+void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument ) {
   OS << " nullptr";
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitIntegralTemplateArgument(const 

[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-26 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/93431

>From c23a96038a8233b44b49bc0a1d2a2475e4d2a8ae Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Fri, 24 May 2024 12:22:55 -0300
Subject: [PATCH] [clang] Improve ast-dumper text printing of TemplateArgument

This improves and unifies our approach to printing all template
arguments.

The same approach to printing types is extended to all
TemplateArguments: A sugared version is printed in quotes,
followed by printing the canonical form, unless they would print
the same.

Special improvements are done to add more detail to template template
arguments.

It's planned in a future patch to use this improved TemplateName
printer for other places besides TemplateArguments.

Note: The sugared/desugared printing does not show up for
TemplateNames in tests yet, because we do a poor job of preserving
their type sugar. This will be improved in a future patch.
---
 clang/docs/ReleaseNotes.rst   |  5 +
 clang/include/clang/AST/TextNodeDumper.h  |  2 +
 clang/lib/AST/TextNodeDumper.cpp  | 94 ---
 clang/test/AST/ast-dump-decl.cpp  | 25 ++---
 ...penmp-begin-declare-variant_template_2.cpp |  6 +-
 clang/test/AST/ast-dump-template-name.cpp | 54 +++
 clang/test/AST/ast-dump-using-template.cpp|  8 +-
 .../constraints-explicit-instantiation.cpp|  6 +-
 clang/test/OpenMP/align_clause_ast_print.cpp  |  2 +-
 clang/test/OpenMP/generic_loop_ast_print.cpp  |  2 +-
 clang/test/OpenMP/interop_ast_print.cpp   |  2 +-
 clang/test/SemaOpenACC/sub-array-ast.cpp  |  2 +-
 .../aggregate-deduction-candidate.cpp | 16 ++--
 clang/test/SemaTemplate/attributes.cpp| 64 ++---
 clang/test/SemaTemplate/deduction-guide.cpp   | 14 +--
 clang/test/SemaTemplate/make_integer_seq.cpp  | 68 --
 clang/test/SemaTemplate/type_pack_element.cpp | 20 ++--
 17 files changed, 265 insertions(+), 125 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-template-name.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 825e91876ffce..403a107edef17 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -818,6 +818,11 @@ Miscellaneous Clang Crashes Fixed
   when ``-fdump-record-layouts-complete`` is passed. Fixes #GH83684.
 - Unhandled StructuralValues in the template differ (#GH93068).
 
+Miscellaneous Clang Improvements
+^
+
+- The text ast-dumper has improved printing of TemplateArguments.
+
 OpenACC Specific Changes
 
 
diff --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 1fede6e462e92..63fa16c9ec47c 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -213,6 +213,8 @@ class TextNodeDumper
   void dumpTemplateSpecializationKind(TemplateSpecializationKind TSK);
   void dumpNestedNameSpecifier(const NestedNameSpecifier *NNS);
   void dumpConceptReference(const ConceptReference *R);
+  void dumpTemplateArgument(const TemplateArgument );
+  void dumpTemplateName(TemplateName TN);
 
   void dumpDeclRef(const Decl *D, StringRef Label = {});
 
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 4a1e94ffe283b..742203e3b946d 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -947,6 +947,26 @@ void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef 
Label) {
   });
 }
 
+void TextNodeDumper::dumpTemplateArgument(const TemplateArgument ) {
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TA.print(PrintPolicy, SS, /*IncludeType=*/true);
+  }
+  OS << " '" << Str << "'";
+
+  if (TemplateArgument CanonTA = Context->getCanonicalTemplateArgument(TA);
+  !CanonTA.structurallyEquals(TA)) {
+llvm::SmallString<128> CanonStr;
+{
+  llvm::raw_svector_ostream SS(CanonStr);
+  CanonTA.print(PrintPolicy, SS, /*IncludeType=*/true);
+}
+if (CanonStr != Str)
+  OS << ":'" << CanonStr << "'";
+  }
+}
+
 const char *TextNodeDumper::getCommandName(unsigned CommandID) {
   if (Traits)
 return Traits->getCommandInfo(CommandID)->Name;
@@ -1086,45 +1106,91 @@ void TextNodeDumper::VisitNullTemplateArgument(const 
TemplateArgument &) {
 
 void TextNodeDumper::VisitTypeTemplateArgument(const TemplateArgument ) {
   OS << " type";
-  dumpType(TA.getAsType());
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitDeclarationTemplateArgument(
 const TemplateArgument ) {
   OS << " decl";
+  dumpTemplateArgument(TA);
   dumpDeclRef(TA.getAsDecl());
 }
 
-void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &) {
+void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument ) {
   OS << " nullptr";
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument 

[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-26 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/93431

This improves and unifies our approach to printing all template arguments.

The same approach to printing types is extended to all TemplateArguments: A 
sugared version is printed in quotes, followed by printing the canonical form, 
unless they would print the same.

Special improvements are done to add more detail to template template arguments.

It's planned in a future patch to use this improved TemplateName printer for 
other places besides TemplateArguments.

Note: The sugared/desugared printing does not show up for TemplateNames in 
tests yet, because we do a poor job of preserving their type sugar. This will 
be improved in a future patch.

>From 51ca62950c19648895f1947bbf981408193d9002 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Fri, 24 May 2024 12:22:55 -0300
Subject: [PATCH] [clang] Improve ast-dumper text printing of TemplateArgument

This improves and unifies our approach to printing all template
arguments.

The same approach to printing types is extended to all
TemplateArguments: A sugared version is printed in quotes,
followed by printing the canonical form, unless they would print
the same.

Special improvements are done to add more detail to template template
arguments.

It's planned in a future patch to use this improved TemplateName
printer for other places besides TemplateArguments.

Note: The sugared/desugared printing does not show up for
TemplateNames in tests yet, because we do a poor job of preserving
their type sugar. This will be improved in a future patch.
---
 clang/docs/ReleaseNotes.rst   |  5 +
 clang/include/clang/AST/TextNodeDumper.h  |  3 +
 clang/lib/AST/TextNodeDumper.cpp  | 94 ---
 clang/test/AST/ast-dump-decl.cpp  | 25 ++---
 ...penmp-begin-declare-variant_template_2.cpp |  6 +-
 clang/test/AST/ast-dump-template-name.cpp | 54 +++
 clang/test/AST/ast-dump-using-template.cpp|  8 +-
 .../constraints-explicit-instantiation.cpp|  6 +-
 clang/test/OpenMP/align_clause_ast_print.cpp  |  2 +-
 clang/test/OpenMP/generic_loop_ast_print.cpp  |  2 +-
 clang/test/OpenMP/interop_ast_print.cpp   |  2 +-
 clang/test/SemaOpenACC/sub-array-ast.cpp  |  2 +-
 .../aggregate-deduction-candidate.cpp | 16 ++--
 clang/test/SemaTemplate/attributes.cpp| 64 ++---
 clang/test/SemaTemplate/deduction-guide.cpp   | 14 +--
 clang/test/SemaTemplate/make_integer_seq.cpp  | 68 --
 clang/test/SemaTemplate/type_pack_element.cpp | 20 ++--
 17 files changed, 266 insertions(+), 125 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-template-name.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 825e91876ffce..403a107edef17 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -818,6 +818,11 @@ Miscellaneous Clang Crashes Fixed
   when ``-fdump-record-layouts-complete`` is passed. Fixes #GH83684.
 - Unhandled StructuralValues in the template differ (#GH93068).
 
+Miscellaneous Clang Improvements
+^
+
+- The text ast-dumper has improved printing of TemplateArguments.
+
 OpenACC Specific Changes
 
 
diff --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 1fede6e462e92..0d057b8011164 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -211,8 +211,11 @@ class TextNodeDumper
   void dumpAccessSpecifier(AccessSpecifier AS);
   void dumpCleanupObject(const ExprWithCleanups::CleanupObject );
   void dumpTemplateSpecializationKind(TemplateSpecializationKind TSK);
+  void dumpBareNestedNameSpecifier(NestedNameSpecifier *NNS);
   void dumpNestedNameSpecifier(const NestedNameSpecifier *NNS);
   void dumpConceptReference(const ConceptReference *R);
+  void dumpTemplateArgument(const TemplateArgument );
+  void dumpTemplateName(TemplateName TN);
 
   void dumpDeclRef(const Decl *D, StringRef Label = {});
 
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 4a1e94ffe283b..742203e3b946d 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -947,6 +947,26 @@ void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef 
Label) {
   });
 }
 
+void TextNodeDumper::dumpTemplateArgument(const TemplateArgument ) {
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TA.print(PrintPolicy, SS, /*IncludeType=*/true);
+  }
+  OS << " '" << Str << "'";
+
+  if (TemplateArgument CanonTA = Context->getCanonicalTemplateArgument(TA);
+  !CanonTA.structurallyEquals(TA)) {
+llvm::SmallString<128> CanonStr;
+{
+  llvm::raw_svector_ostream SS(CanonStr);
+  CanonTA.print(PrintPolicy, SS, /*IncludeType=*/true);
+}
+if (CanonStr != Str)
+  OS << ":'" << CanonStr << "'";
+  }
+}
+
 const char 

[clang] [Clang] Implement resolution for CWG1835 (PR #92957)

2024-05-24 Thread Matheus Izvekov via cfe-commits


@@ -55,15 +55,21 @@ namespace PR11856 {
 
   template T *end(T*);
 
-  class X { };
+  struct X { };
+  struct Y {
+int end;
+  };
   template 
   void Foo2() {
 T it1;
-if (it1->end < it1->end) {
-}
+if (it1->end < it1->end) { }
 
 X *x;
-if (x->end < 7) {  // expected-error{{no member named 'end' in 
'PR11856::X'}}
-}
+if (x->end < 7) { } // expected-error{{expected '>'}}
+// expected-note@-1{{to match this '<'}}
+// expected-error@-2{{expected unqualified-id}}

mizvekov wrote:

I see.

Still, error recovery is not great here.

I think this looks sufficiently different from a template argument list that we 
should just error out and commit to the interpretation that this is a 
comparison.

We already have this capability to look ahead and tell if something looks like 
a template argument list, see: 
https://github.com/llvm/llvm-project/blob/d07362f7a9fc06e2445f5c4bc62c10a339bf68a5/clang/include/clang/Parse/Parser.h#L2734

https://github.com/llvm/llvm-project/pull/92957
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] add fallback to expr in the template differ when comparing ValueDecl (PR #93266)

2024-05-24 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov closed 
https://github.com/llvm/llvm-project/pull/93266
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] add fallback to expr in the template differ when comparing ValueDecl (PR #93266)

2024-05-24 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/93266

>From 5b592204ddef177d612f8455f4e14ab9cf9c06bd Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 23 May 2024 23:57:01 -0300
Subject: [PATCH] [clang] add fallback to expr in the template differ when
 comparing ValueDecl

---
 clang/docs/ReleaseNotes.rst | 1 +
 clang/lib/AST/ASTDiagnostic.cpp | 5 +
 clang/test/Misc/diag-template-diffing-cxx26.cpp | 4 ++--
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f612a1fd36859..fd7f3ee13d9ac 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -803,6 +803,7 @@ Miscellaneous Bug Fixes
 - Fixed an infinite recursion in ASTImporter, on return type declared inside
   body of C++11 lambda without trailing return (#GH68775).
 - Fixed declaration name source location of instantiated function definitions 
(GH71161).
+- Improve diagnostic output to print an expression instead of 'no argument` 
when comparing Values as template arguments.
 
 Miscellaneous Clang Crashes Fixed
 ^
diff --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp
index 5c7afaaf2ca8f..0680ff5e3a385 100644
--- a/clang/lib/AST/ASTDiagnostic.cpp
+++ b/clang/lib/AST/ASTDiagnostic.cpp
@@ -1936,6 +1936,11 @@ class TemplateDiff {
   return;
 }
 
+if (E) {
+  PrintExpr(E);
+  return;
+}
+
 OS << "(no argument)";
   }
 
diff --git a/clang/test/Misc/diag-template-diffing-cxx26.cpp 
b/clang/test/Misc/diag-template-diffing-cxx26.cpp
index cc174d6c334fb..2b6dd86a9885d 100644
--- a/clang/test/Misc/diag-template-diffing-cxx26.cpp
+++ b/clang/test/Misc/diag-template-diffing-cxx26.cpp
@@ -19,10 +19,10 @@ namespace GH93068 {
 // expected-note@#A {{no known conversion from 'A<0>' to 'const A<[1]> 
&' for 1st argument}}
 // expected-note@#A {{no known conversion from 'A<0>' to 'A<[1]> &&' for 
1st argument}}
 
-// notree-error@#2 {{no viable conversion from 'A' to 'A<(no 
argument)>'}}
+// notree-error@#2 {{no viable conversion from 'A' to 'A'}}
 /* tree-error@#2 {{no viable conversion
   A<
-[n != (no argument)]>}}*/
+[n != n + 1]>}}*/
 
 A v2 = A(); // #2
 // expected-note@#A {{no known conversion from 'A' to 'const A<[1]> 
&' for 1st argument}}

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


[clang] [clang] add fallback to expr in the template differ when comparing ValueDecl (PR #93266)

2024-05-24 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/93266
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov closed 
https://github.com/llvm/llvm-project/pull/93265
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/93265

>From 2546c2c5d9e1bc6d1d4ddd818b4017073f17cec0 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 23 May 2024 21:23:21 -0300
Subject: [PATCH] [clang] Avoid crash due to unimplemented StructuralValue
 support in the template differ

This was not implemented in https://github.com/llvm/llvm-project/pull/78041

This patch does not implement this fucntionality, it just falls back to the 
expression
when possible.

Otherwise, such as when dealing with canonical types to begin with,
this will just ignore the argument as if it wasn't even there.

Fixes https://github.com/llvm/llvm-project/issues/93068
---
 clang/docs/ReleaseNotes.rst   |   1 +
 clang/lib/AST/ASTDiagnostic.cpp   | 106 +++---
 ...ng.cpp => diag-template-diffing-cxx11.cpp} |   0
 .../test/Misc/diag-template-diffing-cxx26.cpp |  49 
 4 files changed, 114 insertions(+), 42 deletions(-)
 rename clang/test/Misc/{diag-template-diffing.cpp => 
diag-template-diffing-cxx11.cpp} (100%)
 create mode 100644 clang/test/Misc/diag-template-diffing-cxx26.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7bcdee96e213e..6e8687fadc6f7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -790,6 +790,7 @@ Miscellaneous Clang Crashes Fixed
 
 - Do not attempt to dump the layout of dependent types or invalid declarations
   when ``-fdump-record-layouts-complete`` is passed. Fixes #GH83684.
+- Unhandled StructuralValues in the template differ (#GH93068).
 
 OpenACC Specific Changes
 
diff --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp
index 91bc1b22acfc7..5c7afaaf2ca8f 100644
--- a/clang/lib/AST/ASTDiagnostic.cpp
+++ b/clang/lib/AST/ASTDiagnostic.cpp
@@ -1215,46 +1215,19 @@ class TemplateDiff {
  bool ) {
 if (!Iter.isEnd()) {
   switch (Iter->getKind()) {
-default:
-  llvm_unreachable("unknown ArgumentKind");
-case TemplateArgument::Integral:
-  Value = Iter->getAsIntegral();
-  HasInt = true;
-  IntType = Iter->getIntegralType();
-  return;
-case TemplateArgument::Declaration: {
-  VD = Iter->getAsDecl();
-  QualType ArgType = Iter->getParamTypeForDecl();
-  QualType VDType = VD->getType();
-  if (ArgType->isPointerType() &&
-  Context.hasSameType(ArgType->getPointeeType(), VDType))
-NeedAddressOf = true;
-  return;
-}
-case TemplateArgument::NullPtr:
-  IsNullPtr = true;
-  return;
-case TemplateArgument::Expression:
-  E = Iter->getAsExpr();
-  }
-} else if (!Default->isParameterPack()) {
-  E = Default->getDefaultArgument().getArgument().getAsExpr();
-}
-
-if (!Iter.hasDesugaredTA()) return;
-
-const TemplateArgument& TA = Iter.getDesugaredTA();
-switch (TA.getKind()) {
-  default:
-llvm_unreachable("unknown ArgumentKind");
+  case TemplateArgument::StructuralValue:
+// FIXME: Diffing of structural values is not implemented.
+// There is no possible fallback in this case, this will show up
+// as '(no argument)'.
+return;
   case TemplateArgument::Integral:
-Value = TA.getAsIntegral();
+Value = Iter->getAsIntegral();
 HasInt = true;
-IntType = TA.getIntegralType();
+IntType = Iter->getIntegralType();
 return;
   case TemplateArgument::Declaration: {
-VD = TA.getAsDecl();
-QualType ArgType = TA.getParamTypeForDecl();
+VD = Iter->getAsDecl();
+QualType ArgType = Iter->getParamTypeForDecl();
 QualType VDType = VD->getType();
 if (ArgType->isPointerType() &&
 Context.hasSameType(ArgType->getPointeeType(), VDType))
@@ -1265,13 +1238,62 @@ class TemplateDiff {
 IsNullPtr = true;
 return;
   case TemplateArgument::Expression:
-// TODO: Sometimes, the desugared template argument Expr differs from
-// the sugared template argument Expr.  It may be useful in the future
-// but for now, it is just discarded.
-if (!E)
-  E = TA.getAsExpr();
-return;
+E = Iter->getAsExpr();
+break;
+  case TemplateArgument::Null:
+  case TemplateArgument::Type:
+  case TemplateArgument::Template:
+  case TemplateArgument::TemplateExpansion:
+llvm_unreachable("TemplateArgument kind is not expected for NTTP");
+  case TemplateArgument::Pack:
+llvm_unreachable("TemplateArgument kind should be handled elsewhere");
+  }
+} else if (!Default->isParameterPack()) {
+  E = Default->getDefaultArgument().getArgument().getAsExpr();
 }
+
+if (!Iter.hasDesugaredTA())
+  return;
+
+const TemplateArgument  = 

[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-24 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov approved this pull request.

Can you also add a test based on my example?

With also a variant on that in which the bad conversion happens on the last 
element of the pack, instead of the last parameter.

Lastly, please namespace the tests with the name of, or add a comment naming, 
the GitHub issue.

Otherwise, LGTM.



https://github.com/llvm/llvm-project/pull/93079
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-24 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/93079
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-24 Thread Matheus Izvekov via cfe-commits


@@ -11298,8 +11298,9 @@ static void DiagnoseBadConversion(Sema , 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  SourceRange ToParamRange;
+  if (!isObjectArgument && I < Fn->getNumParams())
+ToParamRange = Fn->getParamDecl(I)->getSourceRange();

mizvekov wrote:

Okay. Should'nt be a problem to pipe in the specialization, but as I said, just 
leaving the FIXME is fine.

https://github.com/llvm/llvm-project/pull/93079
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/93265
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Matheus Izvekov via cfe-commits




mizvekov wrote:

We usually create new tests under the latest standard.

https://github.com/llvm/llvm-project/pull/93265
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Diagnose musttail instead of crash inside backend (PR #93267)

2024-05-23 Thread Matheus Izvekov via cfe-commits


@@ -3833,6 +3833,11 @@ def note_cannot_use_trivial_abi_reason : Note<
   "it is polymorphic|"
   "it has a base of a non-trivial class type|it has a virtual base|"
   "it has a __weak field|it has a field of a non-trivial class type}1">;
+def warn_ppc_musttail_maybe_ignored: Warning<
+  "'musttail' attribute may be ignored on ppc targets">,
+  InGroup;

mizvekov wrote:

musttail can't be ignored with just a warning: This is a promise by the 
implementation, and this is not just an optimization, it is often required to 
get correct behavior on code that relies on it.

I expect this will lead to crashes due to stack exhaustion in such programs, or 
other UB with assembly interop.

https://github.com/llvm/llvm-project/pull/93267
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Diagnose musttail instead of crash inside backend (PR #93267)

2024-05-23 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov requested changes to this pull request.


https://github.com/llvm/llvm-project/pull/93267
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Diagnose musttail instead of crash inside backend (PR #93267)

2024-05-23 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/93267
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [lldb] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-05-23 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

This missed adding support to StructuralValue template arguments to the 
template differ.

See https://github.com/llvm/llvm-project/pull/93265

Te support is still missing, we are just avoiding the crash for now.

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-23 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/93265

This was not implemented in https://github.com/llvm/llvm-project/pull/78041 
when StructuralValue TemplateArguments were originally added.

This patch does not implement this functionality, it just falls back to the 
expression when possible.

Otherwise, such as when dealing with canonical types to begin with, this will 
just ignore the argument as if it wasn't even there.

Fixes https://github.com/llvm/llvm-project/issues/93068

>From c7a056d39dd4148cc8872e8ca136a9f9525ff654 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 23 May 2024 21:23:21 -0300
Subject: [PATCH] [clang] Avoid crash due to unimplemented StructuralValue
 support in the template differ

This was not implemented in https://github.com/llvm/llvm-project/pull/78041

This patch does not implement this fucntionality, it just falls back to the 
expression
when possible.

Otherwise, such as when dealing with canonical types to begin with,
this will just ignore the argument as if it wasn't even there.

Fixes https://github.com/llvm/llvm-project/issues/93068
---
 clang/docs/ReleaseNotes.rst   |   1 +
 clang/lib/AST/ASTDiagnostic.cpp   | 106 +++---
 ...ng.cpp => diag-template-diffing-cxx11.cpp} |   0
 .../test/Misc/diag-template-diffing-cxx26.cpp |  49 
 4 files changed, 114 insertions(+), 42 deletions(-)
 rename clang/test/Misc/{diag-template-diffing.cpp => 
diag-template-diffing-cxx11.cpp} (100%)
 create mode 100644 clang/test/Misc/diag-template-diffing-cxx26.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7bcdee96e213e..6e8687fadc6f7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -790,6 +790,7 @@ Miscellaneous Clang Crashes Fixed
 
 - Do not attempt to dump the layout of dependent types or invalid declarations
   when ``-fdump-record-layouts-complete`` is passed. Fixes #GH83684.
+- Unhandled StructuralValues in the template differ (#GH93068).
 
 OpenACC Specific Changes
 
diff --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp
index 91bc1b22acfc7..7e4a5709a44ce 100644
--- a/clang/lib/AST/ASTDiagnostic.cpp
+++ b/clang/lib/AST/ASTDiagnostic.cpp
@@ -1215,46 +1215,19 @@ class TemplateDiff {
  bool ) {
 if (!Iter.isEnd()) {
   switch (Iter->getKind()) {
-default:
-  llvm_unreachable("unknown ArgumentKind");
-case TemplateArgument::Integral:
-  Value = Iter->getAsIntegral();
-  HasInt = true;
-  IntType = Iter->getIntegralType();
-  return;
-case TemplateArgument::Declaration: {
-  VD = Iter->getAsDecl();
-  QualType ArgType = Iter->getParamTypeForDecl();
-  QualType VDType = VD->getType();
-  if (ArgType->isPointerType() &&
-  Context.hasSameType(ArgType->getPointeeType(), VDType))
-NeedAddressOf = true;
-  return;
-}
-case TemplateArgument::NullPtr:
-  IsNullPtr = true;
-  return;
-case TemplateArgument::Expression:
-  E = Iter->getAsExpr();
-  }
-} else if (!Default->isParameterPack()) {
-  E = Default->getDefaultArgument().getArgument().getAsExpr();
-}
-
-if (!Iter.hasDesugaredTA()) return;
-
-const TemplateArgument& TA = Iter.getDesugaredTA();
-switch (TA.getKind()) {
-  default:
-llvm_unreachable("unknown ArgumentKind");
+  case TemplateArgument::StructuralValue:
+// FIXME: Diffing of structural values is not implemented.
+// There is no possible fallback in this case, this will show up
+// as '(no argument)'.
+return;
   case TemplateArgument::Integral:
-Value = TA.getAsIntegral();
+Value = Iter->getAsIntegral();
 HasInt = true;
-IntType = TA.getIntegralType();
+IntType = Iter->getIntegralType();
 return;
   case TemplateArgument::Declaration: {
-VD = TA.getAsDecl();
-QualType ArgType = TA.getParamTypeForDecl();
+VD = Iter->getAsDecl();
+QualType ArgType = Iter->getParamTypeForDecl();
 QualType VDType = VD->getType();
 if (ArgType->isPointerType() &&
 Context.hasSameType(ArgType->getPointeeType(), VDType))
@@ -1265,13 +1238,62 @@ class TemplateDiff {
 IsNullPtr = true;
 return;
   case TemplateArgument::Expression:
-// TODO: Sometimes, the desugared template argument Expr differs from
-// the sugared template argument Expr.  It may be useful in the future
-// but for now, it is just discarded.
-if (!E)
-  E = TA.getAsExpr();
-return;
+E = Iter->getAsExpr();
+break;
+  case TemplateArgument::Null:
+  case TemplateArgument::Type:
+  case TemplateArgument::Template:
+  case 

[clang] [clang-tools-extra] [clang] Implement CWG2398 provisional TTP matching to class templates (PR #92855)

2024-05-23 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

I figured a reproducer based on your hints:

```C++
template struct A {};

template class TT> auto f(TT a) { return a; }

A v1;
A v2;

using X = decltype(f(v1));
using Y = decltype(f(v2));
```

Fails with:
```
t.cc:9:20: error: no matching function for call to 'f'
9 | using Y = decltype(f(v2));
  |^
t.cc:3:41: note: candidate template ignored: deduced type 'A<[...], (default) 
float>' of 1st parameter does not match adjusted type 'A<[...], double>' of 
argument [with TT = A]
3 | template class TT> auto f(TT a) { return a; }
  | ^
```

This shows we are not properly canonicalizing the synthesized template 
declaration.

The problem does not show up with class template partial specializations due to 
a pre-existing issue, but otherwise this was an oversight on my part.

No need to keep reducing on your end, I already have enough to go with.

https://github.com/llvm/llvm-project/pull/92855
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang] Implement CWG2398 provisional TTP matching to class templates (PR #92855)

2024-05-23 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> Heads up: this commit has triggered some weird errors for a compile, but only 
> when clang header modules are enabled. 
> That seems to _probably_ indicate a bug in this commit (presumably related to 
> AST serialization or deserialization?), but I don't have a test-case, and, 
> that's harder to get for issues that only arise with modules enabled...

Thanks for the heads-up, James.

Indeed, and it's not only modules, our tooling for reducing test cases is 
getting less and less effective.

https://github.com/llvm/llvm-project/pull/92855
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[clang] Implement CWG2398 provisional TTP matching to class templates" (PR #93258)

2024-05-23 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov closed 
https://github.com/llvm/llvm-project/pull/93258
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[clang] Implement CWG2398 provisional TTP matching to class templates" (PR #93258)

2024-05-23 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/93258

Reverts llvm/llvm-project#92855

This is causing issues, there are still being reduced, but does look like a 
problem.

>From 8871ef58ece10234b8cd97c5e7199dee7d7a8b08 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 23 May 2024 21:30:43 -0300
Subject: [PATCH] =?UTF-8?q?Revert=20"[clang]=20Implement=20CWG2398=20provi?=
 =?UTF-8?q?sional=20TTP=20matching=20to=20class=20templates=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit ff3f41deb04c03ba57658776e4e0dc26ef01187d.
---
 clang/lib/Sema/SemaTemplate.cpp   |  5 +-
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 76 ---
 .../CXX/temp/temp.decls/temp.alias/p2.cpp |  5 +-
 clang/test/SemaTemplate/cwg2398.cpp   |  3 +
 4 files changed, 36 insertions(+), 53 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 268f079980a6c..39e9dbed0c3e0 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1807,8 +1807,6 @@ static void SetNestedNameSpecifier(Sema , TagDecl *T,
 // Returns the template parameter list with all default template argument
 // information.
 static TemplateParameterList *GetTemplateParameterList(TemplateDecl *TD) {
-  if (TD->isImplicit())
-return TD->getTemplateParameters();
   // Make sure we get the template parameter list from the most
   // recent declaration, since that is the only one that is guaranteed to
   // have all the default template argument information.
@@ -1829,8 +1827,7 @@ static TemplateParameterList 
*GetTemplateParameterList(TemplateDecl *TD) {
   //template  friend struct C;
   //  };
   //  template struct S;
-  while ((D->isImplicit() ||
-  D->getFriendObjectKind() != Decl::FriendObjectKind::FOK_None) &&
+  while (D->getFriendObjectKind() != Decl::FriendObjectKind::FOK_None &&
  D->getPreviousDecl())
 D = D->getPreviousDecl();
   return cast(D)->getTemplateParameters();
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 08a69d3cb2589..f9ec34163e656 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -527,8 +527,8 @@ static NamedDecl *getTemplateParameterWithDefault(Sema , 
NamedDecl *A,
 R->setDefaultArgument(
 S.Context,
 S.getTrivialTemplateArgumentLoc(Default, QualType(), 
SourceLocation()));
-if (T->hasTypeConstraint()) {
-  auto *C = T->getTypeConstraint();
+if (R->hasTypeConstraint()) {
+  auto *C = R->getTypeConstraint();
   R->setTypeConstraint(C->getConceptReference(),
C->getImmediatelyDeclaredConstraint());
 }
@@ -583,53 +583,37 @@ DeduceTemplateArguments(Sema , TemplateParameterList 
*TemplateParams,
   return TemplateDeductionResult::Success;
 
 auto NewDeduced = DeducedTemplateArgument(Arg);
-// Provisional resolution for CWG2398: If Arg names a template
-// specialization, then we deduce a synthesized template template parameter
-// based on A, but using the TS's arguments as defaults.
-if (DefaultArguments.size() != 0) {
+// Provisional resolution for CWG2398: If Arg is also a template template
+// param, and it names a template specialization, then we deduce a
+// synthesized template template parameter based on A, but using the TS's
+// arguments as defaults.
+if (auto *TempArg = dyn_cast_or_null(
+Arg.getAsTemplateDecl())) {
   assert(Arg.getKind() == TemplateName::Template);
-  TemplateDecl *TempArg = Arg.getAsTemplateDecl();
+  assert(!TempArg->isExpandedParameterPack());
+
   TemplateParameterList *As = TempArg->getTemplateParameters();
-  assert(DefaultArguments.size() <= As->size());
-
-  SmallVector Params(As->size());
-  for (unsigned I = 0; I < DefaultArguments.size(); ++I)
-Params[I] = getTemplateParameterWithDefault(S, As->getParam(I),
-DefaultArguments[I]);
-  for (unsigned I = DefaultArguments.size(); I < As->size(); ++I)
-Params[I] = As->getParam(I);
-  // FIXME: We could unique these, and also the parameters, but we don't
-  // expect programs to contain a large enough amount of these deductions
-  // for that to be worthwhile.
-  auto *TPL = TemplateParameterList::Create(
-  S.Context, SourceLocation(), SourceLocation(), Params,
-  SourceLocation(), As->getRequiresClause());
-
-  TemplateDecl *TD;
-  switch (TempArg->getKind()) {
-  case Decl::TemplateTemplateParm: {
-auto *A = cast(TempArg);
-assert(!A->isExpandedParameterPack());
-TD = TemplateTemplateParmDecl::Create(
-S.Context, A->getDeclContext(), SourceLocation(), A->getDepth(),
-A->getPosition(), 

[clang] [clang-tools-extra] [clang] Implement CWG2398 provisional TTP matching to class templates (PR #92855)

2024-05-23 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

Thanks for the heads up, this does look like a problem. I am reverting it for 
now.

https://github.com/llvm/llvm-project/pull/92855
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-23 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/93079
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-23 Thread Matheus Izvekov via cfe-commits


@@ -11298,8 +11298,9 @@ static void DiagnoseBadConversion(Sema , 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  SourceRange ToParamRange;
+  if (!isObjectArgument && I < Fn->getNumParams())
+ToParamRange = Fn->getParamDecl(I)->getSourceRange();

mizvekov wrote:

Sure, fixing the crash is important, but in that case I would leave a FIXME and 
keep the bug open, with updated information. It's your call.

Though I don't think solving this is complicated: Just a linear scan on the 
parameter list:
* A parameter which is a pack consumes 
`cast(Fn->getParamDecl(I)->getType())->getNumExpansions()` 
arguments, which can possibly be zero arguments. It should not be possible to 
find an unexpanded pack in this diagnostic.
* A parameter which is not a pack consumes one argument.

https://github.com/llvm/llvm-project/pull/93079
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-23 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov requested changes to this pull request.


https://github.com/llvm/llvm-project/pull/93079
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix printing of canonical template template parameters (PR #93124)

2024-05-23 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov closed 
https://github.com/llvm/llvm-project/pull/93124
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix printing of canonical template template parameters (PR #93124)

2024-05-22 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/93124

When printing template arguments of the template kind, a canonical template 
template parameter would be printed as an empty string.

This fixes it so they are printed similarly to canonical template type 
parameters.

>From cc85c5f7c04c78ef01bd9c7514d36ad3eaea5605 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 22 May 2024 20:56:20 -0300
Subject: [PATCH] [clang] fix printing of canonical template template
 parameters

When printing template arguments of the template kind, a canonical
template template parameter would be printed as an empty string.

This fixes it so they are printed similarly to canonical template
type parameters.
---
 clang/lib/AST/TemplateBase.cpp   | 14 --
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp |  2 +-
 clang/test/SemaTemplate/deduction-guide.cpp  | 10 +-
 clang/test/SemaTemplate/make_integer_seq.cpp |  4 ++--
 4 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index 3310d7dc24c59..a7ee973b7f7d0 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -538,9 +538,19 @@ void TemplateArgument::print(const PrintingPolicy , 
raw_ostream ,
 Out << "nullptr";
 break;
 
-  case Template:
-getAsTemplate().print(Out, Policy, TemplateName::Qualified::Fully);
+  case Template: {
+TemplateName TN = getAsTemplate();
+if (const auto *TD = TN.getAsTemplateDecl();
+TD && TD->getDeclName().isEmpty()) {
+  assert(isa(TD) &&
+ "Unexpected anonymous template");
+  const auto *TTP = cast(TD);
+  Out << "template-parameter-" << TTP->getDepth() << "-" << 
TTP->getIndex();
+} else {
+  TN.print(Out, Policy, TemplateName::Qualified::Fully);
+}
 break;
+  }
 
   case TemplateExpansion:
 getAsTemplateOrTemplatePattern().print(Out, Policy);
diff --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp 
b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
index 4c6ef5adae7d2..b71dfc6ccaf4f 100644
--- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
+++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
@@ -284,7 +284,7 @@ class Foo {};
 // Verify that template template type parameter TTP is referenced/used in the
 // template arguments of the RHS.
 template  typename TTP>
-using Bar = Foo>; // expected-note {{candidate template ignored: could 
not match 'Foo>' against 'int'}}
+using Bar = Foo>; // expected-note {{candidate template ignored: could 
not match 'Foo>' against 'int'}}
 
 template 
 class Container {};
diff --git a/clang/test/SemaTemplate/deduction-guide.cpp 
b/clang/test/SemaTemplate/deduction-guide.cpp
index 0eaeb49e6b32d..c38b647e42f4c 100644
--- a/clang/test/SemaTemplate/deduction-guide.cpp
+++ b/clang/test/SemaTemplate/deduction-guide.cpp
@@ -102,9 +102,9 @@ using CT = C;
 // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'type-parameter-0-2' depth 0 index 
3 V
 // CHECK: | `-TemplateArgument {{.*}} expr
 // CHECK: |   `-IntegerLiteral {{.*}} 'int' 0
-// CHECK: |-CXXDeductionGuideDecl {{.*}} 'auto (A, Y<>, type-parameter-0-2) -> 
C'
+// CHECK: |-CXXDeductionGuideDecl {{.*}} 'auto (A, Y, 
type-parameter-0-2) -> C'
 // CHECK: | |-ParmVarDecl {{.*}} 'A'
-// CHECK: | |-ParmVarDecl {{.*}} 'Y<>'
+// CHECK: | |-ParmVarDecl {{.*}} 'Y'
 // CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-2'
 // CHECK: `-CXXDeductionGuideDecl {{.*}} 'auto (int, Y, int) -> C'
 // CHECK:  |-TemplateArgument type 'int'
@@ -114,12 +114,12 @@ using CT = C;
 // CHECK:  |-ParmVarDecl {{.*}} 'int'
 // CHECK:  |-ParmVarDecl {{.*}} 'Y'
 // CHECK:  `-ParmVarDecl {{.*}} 'int'
-// CHECK: FunctionProtoType {{.*}} 'auto (A, Y<>, type-parameter-0-2) -> C' 
dependent trailing_return cdecl
+// CHECK: FunctionProtoType {{.*}} 'auto (A, Y, 
type-parameter-0-2) -> C' dependent trailing_return cdecl
 // CHECK: |-InjectedClassNameType {{.*}} 'C' dependent
 // CHECK: |-TemplateTypeParmType {{.*}} 'A' dependent depth 0 index 0
 // CHECK: | `-TemplateTypeParm {{.*}} 'A'
-// CHECK: |-ElaboratedType {{.*}} 'Y<>' sugar dependent
-// CHECK: | `-TemplateSpecializationType {{.*}} 'Y<>' dependent Y
+// CHECK: |-ElaboratedType {{.*}} 'Y' sugar dependent
+// CHECK: | `-TemplateSpecializationType {{.*}} 'Y' 
dependent Y
 // CHECK: |   `-TemplateArgument template
 // CHECK: `-TemplateTypeParmType {{.*}} 'type-parameter-0-2' dependent depth 0 
index 2
 
diff --git a/clang/test/SemaTemplate/make_integer_seq.cpp 
b/clang/test/SemaTemplate/make_integer_seq.cpp
index 3a692f5ae2bfb..c5a1e27053689 100644
--- a/clang/test/SemaTemplate/make_integer_seq.cpp
+++ b/clang/test/SemaTemplate/make_integer_seq.cpp
@@ -61,7 +61,7 @@ using test2 = B;
 
 template  class S, class T, int N> struct C {
   using test3 = __make_integer_seq;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 
test3 '__make_integer_seq':'__make_integer_seq'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  

[clang] [clang-tools-extra] [clang] Implement CWG2398 provisional TTP matching to class templates (PR #92855)

2024-05-22 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov closed 
https://github.com/llvm/llvm-project/pull/92855
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-22 Thread Matheus Izvekov via cfe-commits


@@ -11298,8 +11298,9 @@ static void DiagnoseBadConversion(Sema , 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  SourceRange ToParamRange;
+  if (!isObjectArgument && I < Fn->getNumParams())
+ToParamRange = Fn->getParamDecl(I)->getSourceRange();

mizvekov wrote:

I mean, I would expect the patch would make it so it doesn't crash, but does 
the diagnostic point to the correct parameter?

https://github.com/llvm/llvm-project/pull/93079
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-22 Thread Matheus Izvekov via cfe-commits


@@ -11298,8 +11298,9 @@ static void DiagnoseBadConversion(Sema , 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  SourceRange ToParamRange;
+  if (!isObjectArgument && I < Fn->getNumParams())
+ToParamRange = Fn->getParamDecl(I)->getSourceRange();

mizvekov wrote:

It seems like the problem here may be that `I` is an index into an 
argument-as-written list, which doesn't take into account that mapping into the 
parameter list needs to consider packs.

I think this could do the wrong thing if there are other parameters after the 
pack.

How does your patch handle the following example?
```C++
template  int b(a..., int);
 int d() { return b(0, 0, d); }
```

https://github.com/llvm/llvm-project/pull/93079
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang] NFCI: use TemplateArgumentLoc for NTTP DefaultArgument (PR #92852)

2024-05-22 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov closed 
https://github.com/llvm/llvm-project/pull/92852
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang] Implement CWG2398 provisional TTP matching to class templates (PR #92855)

2024-05-22 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/92855
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Implement resolution for CWG1835 (PR #92957)

2024-05-21 Thread Matheus Izvekov via cfe-commits


@@ -618,7 +618,6 @@ namespace cwg141 { // cwg141: 3.1
 // FIXME: we issue a useful diagnostic first, then some bogus ones.

mizvekov wrote:

It looks like this FIXME is fixed as per change below.

https://github.com/llvm/llvm-project/pull/92957
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Implement resolution for CWG1835 (PR #92957)

2024-05-21 Thread Matheus Izvekov via cfe-commits


@@ -2893,6 +2893,8 @@ class TreeTransform {
 
 CXXScopeSpec SS;
 SS.Adopt(QualifierLoc);
+if (FirstQualifierInScope)
+  SS.setFoundFirstQualifierInScope(FirstQualifierInScope);

mizvekov wrote:

It looks like adding 'FirstQualifierInScope' as a property to SS makes it so 
keeping and passing both around is redundant.

https://github.com/llvm/llvm-project/pull/92957
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   5   >