[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)
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)
@@ -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)
@@ -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)
@@ -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
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)
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)
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)
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)
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)
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)
@@ -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)
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)
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)
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)
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)
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)
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)
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)
@@ -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)
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)
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)
@@ -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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
@@ -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)
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)
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)
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)
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)
@@ -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)
@@ -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)
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)
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)
@@ -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)
@@ -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
[clang] [Clang] Implement resolution for CWG1835 (PR #92957)
@@ -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: This doesn't look expected to me, what is going on? 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)
@@ -397,22 +397,32 @@ NamedDecl *Sema::FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS) { while (NNS->getPrefix()) NNS = NNS->getPrefix(); - if (NNS->getKind() != NestedNameSpecifier::Identifier) -return nullptr; - - LookupResult Found(*this, NNS->getAsIdentifier(), SourceLocation(), - LookupNestedNameSpecifierName); + // FIXME: This is a rather nasty hack! Ideally we should get the results + // from LookupTemplateName/BuildCXXNestedNameSpecifier. + const IdentifierInfo *II = NNS->getAsIdentifier(); + if (!II) { +if (const auto *DTST = +dyn_cast_if_present( +NNS->getAsType())) + II = DTST->getIdentifier(); +else + return nullptr; + } mizvekov wrote: I am not sure why you think this is a nasty hack, this looks legitimate to me. I think this looks ugly because of the lack of a NNS kind for an Identifier with template arguments, so we abuse a type kind storing a DependentTemplateSpecializationType with no qualifier. 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)
https://github.com/mizvekov edited 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)
@@ -720,7 +720,7 @@ Parser::DeclGroupPtrTy Parser::ParseUsingDeclaration( return nullptr; } CXXScopeSpec SS; -if (ParseOptionalCXXScopeSpecifier(SS, /*ParsedType=*/nullptr, +if (ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/nullptr, mizvekov wrote: Land this cleanup separately as well. 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)
@@ -6891,7 +6891,7 @@ class Sema final : public SemaBase { const TemplateArgumentListInfo *TemplateArgs); ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, SourceLocation OpLoc, - tok::TokenKind OpKind, CXXScopeSpec , + bool IsArrow, CXXScopeSpec , mizvekov wrote: You could land this refactoring straight away on an NFC commit, to clean up for the review a bit. 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)
@@ -47,8 +47,8 @@ template void DerivedT::Inner() { Derived1T::Foo(); Derived2T::Member = 42; - this->Derived1T::Foo(); - this->Derived2T::Member = 42; + this->Derived1T::Foo(); // expected-error{{use 'template' keyword to treat 'Derived1T' as a dependent template name}} + this->Derived2T::Member = 42; // expected-error{{use 'template' keyword to treat 'Derived2T' as a dependent template name}} mizvekov wrote: This is an access control test: ```suggestion this->template Derived1T::Foo(); this->template Derived2T::Member = 42; ``` 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)
https://github.com/mizvekov commented: I think overall this looks like the right direction to me. 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-tools-extra] [clang] NFCI: use TemplateArgumentLoc for NTTP DefaultArgument (PR #92852)
https://github.com/mizvekov edited 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] NFCI: use TemplateArgumentLoc for NTTP DefaultArgument (PR #92852)
https://github.com/mizvekov updated https://github.com/llvm/llvm-project/pull/92852 >From 229cb63b95bb3b0db8d73947a40dede945b8b378 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Mon, 20 May 2024 00:39:55 -0300 Subject: [PATCH] [clang] NFCI: use TemplateArgumentLoc for NTTP DefaultArgument This is an enabler for a future patch. --- clang-tools-extra/clangd/Hover.cpp| 3 +- clang/include/clang/AST/ASTNodeTraverser.h| 6 +-- clang/include/clang/AST/DeclTemplate.h| 11 +++-- clang/include/clang/AST/RecursiveASTVisitor.h | 2 +- clang/lib/AST/ASTContext.cpp | 6 ++- clang/lib/AST/ASTDiagnostic.cpp | 2 +- clang/lib/AST/ASTImporter.cpp | 5 +- clang/lib/AST/DeclPrinter.cpp | 4 +- clang/lib/AST/DeclTemplate.cpp| 15 -- clang/lib/AST/JSONNodeDumper.cpp | 2 +- clang/lib/AST/ODRDiagsEmitter.cpp | 7 ++- clang/lib/AST/ODRHash.cpp | 2 +- clang/lib/AST/TypePrinter.cpp | 5 +- clang/lib/ExtractAPI/DeclarationFragments.cpp | 5 +- clang/lib/Index/IndexDecl.cpp | 3 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 10 ++-- clang/lib/Sema/SemaTemplate.cpp | 46 +-- clang/lib/Sema/SemaTemplateDeduction.cpp | 10 ++-- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 7 +-- clang/lib/Serialization/ASTReaderDecl.cpp | 3 +- clang/lib/Serialization/ASTWriterDecl.cpp | 2 +- clang/test/AST/ast-dump-decl.cpp | 4 +- clang/test/SemaTemplate/deduction-guide.cpp | 6 +-- clang/tools/libclang/CIndex.cpp | 5 +- clang/unittests/AST/ASTImporterTest.cpp | 2 +- 25 files changed, 99 insertions(+), 74 deletions(-) diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp index 2ec0994e846e9..de103e011c708 100644 --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -262,7 +262,8 @@ fetchTemplateParameters(const TemplateParameterList *Params, if (NTTP->hasDefaultArgument()) { P.Default.emplace(); llvm::raw_string_ostream Out(*P.Default); -NTTP->getDefaultArgument()->printPretty(Out, nullptr, PP); +NTTP->getDefaultArgument().getArgument().print(PP, Out, + /*IncludeType=*/false); } } else if (const auto *TTPD = dyn_cast(Param)) { P.Type = printType(TTPD, PP); diff --git a/clang/include/clang/AST/ASTNodeTraverser.h b/clang/include/clang/AST/ASTNodeTraverser.h index 98db1cb578990..616f92691ec32 100644 --- a/clang/include/clang/AST/ASTNodeTraverser.h +++ b/clang/include/clang/AST/ASTNodeTraverser.h @@ -704,9 +704,9 @@ class ASTNodeTraverser if (const auto *E = D->getPlaceholderTypeConstraint()) Visit(E); if (D->hasDefaultArgument()) - Visit(D->getDefaultArgument(), SourceRange(), -D->getDefaultArgStorage().getInheritedFrom(), -D->defaultArgumentWasInherited() ? "inherited from" : "previous"); + dumpTemplateArgumentLoc( + D->getDefaultArgument(), D->getDefaultArgStorage().getInheritedFrom(), + D->defaultArgumentWasInherited() ? "inherited from" : "previous"); } void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D) { diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 07b08b5ed43ca..5b6a6b40b28ef 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -1360,7 +1360,8 @@ class NonTypeTemplateParmDecl final /// The default template argument, if any, and whether or not /// it was inherited. - using DefArgStorage = DefaultArgStorage; + using DefArgStorage = + DefaultArgStorage; DefArgStorage DefaultArgument; // FIXME: Collapse this into TemplateParamPosition; or, just move depth/index @@ -1430,7 +1431,10 @@ class NonTypeTemplateParmDecl final bool hasDefaultArgument() const { return DefaultArgument.isSet(); } /// Retrieve the default argument, if any. - Expr *getDefaultArgument() const { return DefaultArgument.get(); } + const TemplateArgumentLoc () const { +static const TemplateArgumentLoc NoneLoc; +return DefaultArgument.isSet() ? *DefaultArgument.get() : NoneLoc; + } /// Retrieve the location of the default argument, if any. SourceLocation getDefaultArgumentLoc() const; @@ -1444,7 +1448,8 @@ class NonTypeTemplateParmDecl final /// Set the default argument for this template parameter, and /// whether that default argument was inherited from another /// declaration. - void setDefaultArgument(Expr *DefArg) { DefaultArgument.set(DefArg); } + void setDefaultArgument(const ASTContext , + const TemplateArgumentLoc ); void setInheritedDefaultArgument(const ASTContext ,
[clang] [clang-tools-extra] [clang] NFCI: use TemplateArgumentLoc for NTTP DefaultArgument (PR #92852)
https://github.com/mizvekov updated https://github.com/llvm/llvm-project/pull/92852 >From 984ac614f6d6e3196961690fa957df6a03f37782 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Mon, 20 May 2024 00:39:55 -0300 Subject: [PATCH] [clang] NFCI: use TemplateArgumentLoc for NTTP DefaultArgument This is an enabler for a future patch. --- clang-tools-extra/clangd/Hover.cpp| 3 +- clang/include/clang/AST/ASTNodeTraverser.h| 6 +-- clang/include/clang/AST/DeclTemplate.h| 11 +++-- clang/include/clang/AST/RecursiveASTVisitor.h | 2 +- clang/lib/AST/ASTContext.cpp | 6 ++- clang/lib/AST/ASTDiagnostic.cpp | 2 +- clang/lib/AST/ASTImporter.cpp | 5 +- clang/lib/AST/DeclPrinter.cpp | 4 +- clang/lib/AST/DeclTemplate.cpp| 15 -- clang/lib/AST/JSONNodeDumper.cpp | 2 +- clang/lib/AST/ODRDiagsEmitter.cpp | 7 ++- clang/lib/AST/ODRHash.cpp | 2 +- clang/lib/AST/TypePrinter.cpp | 5 +- clang/lib/ExtractAPI/DeclarationFragments.cpp | 5 +- clang/lib/Index/IndexDecl.cpp | 3 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 10 ++-- clang/lib/Sema/SemaTemplate.cpp | 46 +-- clang/lib/Sema/SemaTemplateDeduction.cpp | 10 ++-- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 7 +-- clang/lib/Serialization/ASTReaderDecl.cpp | 3 +- clang/lib/Serialization/ASTWriterDecl.cpp | 2 +- clang/test/AST/ast-dump-decl.cpp | 4 +- clang/test/SemaTemplate/deduction-guide.cpp | 6 +-- clang/tools/libclang/CIndex.cpp | 5 +- clang/unittests/AST/ASTImporterTest.cpp | 2 +- 25 files changed, 99 insertions(+), 74 deletions(-) diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp index 2ec0994e846e9..de103e011c708 100644 --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -262,7 +262,8 @@ fetchTemplateParameters(const TemplateParameterList *Params, if (NTTP->hasDefaultArgument()) { P.Default.emplace(); llvm::raw_string_ostream Out(*P.Default); -NTTP->getDefaultArgument()->printPretty(Out, nullptr, PP); +NTTP->getDefaultArgument().getArgument().print(PP, Out, + /*IncludeType=*/false); } } else if (const auto *TTPD = dyn_cast(Param)) { P.Type = printType(TTPD, PP); diff --git a/clang/include/clang/AST/ASTNodeTraverser.h b/clang/include/clang/AST/ASTNodeTraverser.h index 98db1cb578990..616f92691ec32 100644 --- a/clang/include/clang/AST/ASTNodeTraverser.h +++ b/clang/include/clang/AST/ASTNodeTraverser.h @@ -704,9 +704,9 @@ class ASTNodeTraverser if (const auto *E = D->getPlaceholderTypeConstraint()) Visit(E); if (D->hasDefaultArgument()) - Visit(D->getDefaultArgument(), SourceRange(), -D->getDefaultArgStorage().getInheritedFrom(), -D->defaultArgumentWasInherited() ? "inherited from" : "previous"); + dumpTemplateArgumentLoc( + D->getDefaultArgument(), D->getDefaultArgStorage().getInheritedFrom(), + D->defaultArgumentWasInherited() ? "inherited from" : "previous"); } void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D) { diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 07b08b5ed43ca..5b6a6b40b28ef 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -1360,7 +1360,8 @@ class NonTypeTemplateParmDecl final /// The default template argument, if any, and whether or not /// it was inherited. - using DefArgStorage = DefaultArgStorage; + using DefArgStorage = + DefaultArgStorage; DefArgStorage DefaultArgument; // FIXME: Collapse this into TemplateParamPosition; or, just move depth/index @@ -1430,7 +1431,10 @@ class NonTypeTemplateParmDecl final bool hasDefaultArgument() const { return DefaultArgument.isSet(); } /// Retrieve the default argument, if any. - Expr *getDefaultArgument() const { return DefaultArgument.get(); } + const TemplateArgumentLoc () const { +static const TemplateArgumentLoc NoneLoc; +return DefaultArgument.isSet() ? *DefaultArgument.get() : NoneLoc; + } /// Retrieve the location of the default argument, if any. SourceLocation getDefaultArgumentLoc() const; @@ -1444,7 +1448,8 @@ class NonTypeTemplateParmDecl final /// Set the default argument for this template parameter, and /// whether that default argument was inherited from another /// declaration. - void setDefaultArgument(Expr *DefArg) { DefaultArgument.set(DefArg); } + void setDefaultArgument(const ASTContext , + const TemplateArgumentLoc ); void setInheritedDefaultArgument(const ASTContext ,
[clang] [clang-tools-extra] [clang] Implement CWG2398 provisional TTP matching to class templates (PR #92855)
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-tools-extra] [clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (PR #92854)
https://github.com/mizvekov closed https://github.com/llvm/llvm-project/pull/92854 ___ 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 type-param DefaultArgument (PR #92854)
https://github.com/mizvekov updated https://github.com/llvm/llvm-project/pull/92854 >From 142c3f394e1b34dcefcaf0887a6fd4711b78eeb3 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Mon, 20 May 2024 16:30:46 -0300 Subject: [PATCH] [clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument This is an enabler for a future patch. --- .../ForwardingReferenceOverloadCheck.cpp | 4 +- .../bugprone/IncorrectEnableIfCheck.cpp | 5 +- .../modernize/UseConstraintsCheck.cpp | 8 ++- clang-tools-extra/clangd/Hover.cpp| 8 ++- clang/include/clang/AST/ASTNodeTraverser.h| 2 +- clang/include/clang/AST/DeclTemplate.h| 17 ++--- clang/include/clang/AST/RecursiveASTVisitor.h | 2 +- clang/include/clang/Sema/Sema.h | 4 +- clang/lib/AST/ASTContext.cpp | 3 +- clang/lib/AST/ASTImporter.cpp | 6 +- clang/lib/AST/DeclPrinter.cpp | 3 +- clang/lib/AST/DeclTemplate.cpp| 17 +++-- clang/lib/AST/JSONNodeDumper.cpp | 2 +- clang/lib/AST/ODRDiagsEmitter.cpp | 12 ++-- clang/lib/AST/ODRHash.cpp | 2 +- clang/lib/AST/TypePrinter.cpp | 4 +- clang/lib/ExtractAPI/DeclarationFragments.cpp | 8 +-- clang/lib/Index/IndexDecl.cpp | 3 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 48 +++-- clang/lib/Sema/SemaTemplate.cpp | 69 ++- clang/lib/Sema/SemaTemplateDeduction.cpp | 10 +-- clang/lib/Sema/SemaTemplateInstantiate.cpp| 11 +-- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 9 ++- clang/lib/Serialization/ASTReaderDecl.cpp | 3 +- clang/lib/Serialization/ASTWriterDecl.cpp | 2 +- clang/tools/libclang/CIndex.cpp | 7 +- clang/unittests/AST/ASTImporterTest.cpp | 2 +- 27 files changed, 144 insertions(+), 127 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp index 36687a8e761e8..c87b3ea7e2616 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp @@ -54,7 +54,9 @@ AST_MATCHER(QualType, isEnableIf) { AST_MATCHER_P(TemplateTypeParmDecl, hasDefaultArgument, clang::ast_matchers::internal::Matcher, TypeMatcher) { return Node.hasDefaultArgument() && - TypeMatcher.matches(Node.getDefaultArgument(), Finder, Builder); + TypeMatcher.matches( + Node.getDefaultArgument().getArgument().getAsType(), Finder, + Builder); } AST_MATCHER(TemplateDecl, hasAssociatedConstraints) { return Node.hasAssociatedConstraints(); diff --git a/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp index 09aaf3e31d5dd..75f1107904fce 100644 --- a/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp @@ -19,10 +19,11 @@ namespace { AST_MATCHER_P(TemplateTypeParmDecl, hasUnnamedDefaultArgument, ast_matchers::internal::Matcher, InnerMatcher) { if (Node.getIdentifier() != nullptr || !Node.hasDefaultArgument() || - Node.getDefaultArgumentInfo() == nullptr) + Node.getDefaultArgument().getArgument().isNull()) return false; - TypeLoc DefaultArgTypeLoc = Node.getDefaultArgumentInfo()->getTypeLoc(); + TypeLoc DefaultArgTypeLoc = + Node.getDefaultArgument().getTypeSourceInfo()->getTypeLoc(); return InnerMatcher.matches(DefaultArgTypeLoc, Finder, Builder); } diff --git a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp index 7a021fe14436a..ea4d99586c711 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp @@ -177,9 +177,11 @@ matchTrailingTemplateParam(const FunctionTemplateDecl *FunctionTemplate) { dyn_cast(LastParam)) { if (LastTemplateParam->hasDefaultArgument() && LastTemplateParam->getIdentifier() == nullptr) { - return {matchEnableIfSpecialization( - LastTemplateParam->getDefaultArgumentInfo()->getTypeLoc()), - LastTemplateParam}; + return { + matchEnableIfSpecialization(LastTemplateParam->getDefaultArgument() + .getTypeSourceInfo() + ->getTypeLoc()), + LastTemplateParam}; } } return {}; diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp index 06b949bc4a2b5..2ec0994e846e9 100644 --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -247,8 +247,12 @@
[clang] [clang-tools-extra] [clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (PR #92854)
https://github.com/mizvekov edited https://github.com/llvm/llvm-project/pull/92854 ___ 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)
mizvekov wrote: @erichkeane this is kind of the same as https://github.com/llvm/llvm-project/pull/92854, but for NTTP instead of type-parameters. 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] NFCI: use TemplateArgumentLoc for NTTP DefaultArgument (PR #92852)
mizvekov wrote: > Can you try to explain the what the patch does more and describe the > rationale? Done. 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] NFCI: use TemplateArgumentLoc for NTTP DefaultArgument (PR #92852)
@@ -1435,7 +1436,10 @@ class NonTypeTemplateParmDecl final bool hasDefaultArgument() const { return DefaultArgument.isSet(); } /// Retrieve the default argument, if any. - Expr *getDefaultArgument() const { return DefaultArgument.get(); } + const TemplateArgumentLoc () const { mizvekov wrote: All template parameters currently use that name, so this is kept for consistency. I wouldn't object a later separate patch to rename all of them at once. 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] NFCI: use TemplateArgumentLoc for NTTP DefaultArgument (PR #92852)
https://github.com/mizvekov edited 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] NFCI: use TemplateArgumentLoc for NTTP DefaultArgument (PR #92852)
https://github.com/mizvekov created https://github.com/llvm/llvm-project/pull/92852 This is an enabler for a future patch. >From 22964061e46ef0d37904f6c8e757dca9800c5cd0 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Mon, 20 May 2024 00:39:55 -0300 Subject: [PATCH] [clang] NFCI: use TemplateArgumentLoc for NTTP DefaultArgument This is an enabler for a future patch. --- clang-tools-extra/clangd/Hover.cpp| 3 +- clang/include/clang/AST/ASTNodeTraverser.h| 6 +-- clang/include/clang/AST/DeclTemplate.h| 11 +++-- clang/include/clang/AST/RecursiveASTVisitor.h | 2 +- clang/lib/AST/ASTContext.cpp | 6 ++- clang/lib/AST/ASTDiagnostic.cpp | 2 +- clang/lib/AST/ASTImporter.cpp | 5 +- clang/lib/AST/DeclPrinter.cpp | 4 +- clang/lib/AST/DeclTemplate.cpp| 15 -- clang/lib/AST/JSONNodeDumper.cpp | 2 +- clang/lib/AST/ODRDiagsEmitter.cpp | 7 ++- clang/lib/AST/ODRHash.cpp | 2 +- clang/lib/AST/TypePrinter.cpp | 5 +- clang/lib/ExtractAPI/DeclarationFragments.cpp | 5 +- clang/lib/Index/IndexDecl.cpp | 3 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 10 ++-- clang/lib/Sema/SemaTemplate.cpp | 46 +-- clang/lib/Sema/SemaTemplateDeduction.cpp | 10 ++-- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 7 +-- clang/lib/Serialization/ASTReaderDecl.cpp | 3 +- clang/lib/Serialization/ASTWriterDecl.cpp | 2 +- clang/test/AST/ast-dump-decl.cpp | 4 +- clang/test/SemaTemplate/deduction-guide.cpp | 6 +-- clang/tools/libclang/CIndex.cpp | 5 +- clang/unittests/AST/ASTImporterTest.cpp | 2 +- 25 files changed, 99 insertions(+), 74 deletions(-) diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp index 06b949bc4a2b5..51124ab371b2a 100644 --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -258,7 +258,8 @@ fetchTemplateParameters(const TemplateParameterList *Params, if (NTTP->hasDefaultArgument()) { P.Default.emplace(); llvm::raw_string_ostream Out(*P.Default); -NTTP->getDefaultArgument()->printPretty(Out, nullptr, PP); +NTTP->getDefaultArgument().getArgument().print(PP, Out, + /*IncludeType=*/false); } } else if (const auto *TTPD = dyn_cast(Param)) { P.Type = printType(TTPD, PP); diff --git a/clang/include/clang/AST/ASTNodeTraverser.h b/clang/include/clang/AST/ASTNodeTraverser.h index bf7c204e4ad73..a3918e30eadf5 100644 --- a/clang/include/clang/AST/ASTNodeTraverser.h +++ b/clang/include/clang/AST/ASTNodeTraverser.h @@ -704,9 +704,9 @@ class ASTNodeTraverser if (const auto *E = D->getPlaceholderTypeConstraint()) Visit(E); if (D->hasDefaultArgument()) - Visit(D->getDefaultArgument(), SourceRange(), -D->getDefaultArgStorage().getInheritedFrom(), -D->defaultArgumentWasInherited() ? "inherited from" : "previous"); + dumpTemplateArgumentLoc( + D->getDefaultArgument(), D->getDefaultArgStorage().getInheritedFrom(), + D->defaultArgumentWasInherited() ? "inherited from" : "previous"); } void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D) { diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index f3d6a321ecf10..8a471bea0eaba 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -1365,7 +1365,8 @@ class NonTypeTemplateParmDecl final /// The default template argument, if any, and whether or not /// it was inherited. - using DefArgStorage = DefaultArgStorage; + using DefArgStorage = + DefaultArgStorage; DefArgStorage DefaultArgument; // FIXME: Collapse this into TemplateParamPosition; or, just move depth/index @@ -1435,7 +1436,10 @@ class NonTypeTemplateParmDecl final bool hasDefaultArgument() const { return DefaultArgument.isSet(); } /// Retrieve the default argument, if any. - Expr *getDefaultArgument() const { return DefaultArgument.get(); } + const TemplateArgumentLoc () const { +static const TemplateArgumentLoc NoneLoc; +return DefaultArgument.isSet() ? *DefaultArgument.get() : NoneLoc; + } /// Retrieve the location of the default argument, if any. SourceLocation getDefaultArgumentLoc() const; @@ -1449,7 +1453,8 @@ class NonTypeTemplateParmDecl final /// Set the default argument for this template parameter, and /// whether that default argument was inherited from another /// declaration. - void setDefaultArgument(Expr *DefArg) { DefaultArgument.set(DefArg); } + void setDefaultArgument(const ASTContext , + const TemplateArgumentLoc ); void setInheritedDefaultArgument(const ASTContext ,
[clang] 4cebe5a - [clang] NFC: add test for cwg2398 ambiguity issue
Author: Matheus Izvekov Date: 2024-05-20T22:49:53-03:00 New Revision: 4cebe5a43ba83eab477358ef4da665b43463bb68 URL: https://github.com/llvm/llvm-project/commit/4cebe5a43ba83eab477358ef4da665b43463bb68 DIFF: https://github.com/llvm/llvm-project/commit/4cebe5a43ba83eab477358ef4da665b43463bb68.diff LOG: [clang] NFC: add test for cwg2398 ambiguity issue Added: Modified: clang/test/SemaTemplate/cwg2398.cpp Removed: diff --git a/clang/test/SemaTemplate/cwg2398.cpp b/clang/test/SemaTemplate/cwg2398.cpp index 31686c4bc9805..e3b5e575374d3 100644 --- a/clang/test/SemaTemplate/cwg2398.cpp +++ b/clang/test/SemaTemplate/cwg2398.cpp @@ -59,6 +59,21 @@ namespace templ { template struct C>; } // namespace templ +namespace class_template { + template struct A; + + template struct B; + + template class TT1, class T5> struct B>; + // new-note@-1 {{partial specialization matches}} + + template struct B> {}; + // new-note@-1 {{partial specialization matches}} + + template struct B>; + // new-error@-1 {{ambiguous partial specialization}} +} // namespace class_template + namespace type_pack1 { template struct A; template class TT1, class T4> struct A> ; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Don't build CXXDependentScopeMemberExprs for potentially implicit class member access expressions (PR #92318)
https://github.com/mizvekov approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/92318 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [Clang][Sema] Diagnose current instantiation used as an incomplete base class (PR #92597)
https://github.com/mizvekov approved this pull request. The change itself looks pretty good, but note that GCC only warns about this, and more importantly MSVC still accepts the code without complaint. So this means that we could find out from user feedback that we will need to keep the old behavior around behind a flag and for ms-compat mode. But I would be much in favor of going ahead, only making that change later depending on impact. https://github.com/llvm/llvm-project/pull/92597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Introduce `SemaCoroutine` (PR #92645)
mizvekov wrote: Was there ever an RFC on this whole 'splitting up Sema' project? I have my own reservations as well. I think starting up from the easier bits is a risky proposition, as we might realize this whole thing will fail when we get to the harder parts. I also think this can lead in the future to the same sort of problems overusing const got us in the first place: needing large amount of repetitive changes all around when a commonly used or deeply nested component starts depending on a larger chunk of Sema. Also, this will further cement current design lines, without considering where we want to be in the future. And lastly, it seems this will lead to large amounts of code churn without proportional benefit, impacting in-tree development as well as external projects. https://github.com/llvm/llvm-project/pull/92645 ___ 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)
mizvekov wrote: No problem! It looks like this example is salvageable, nothing is stopping us from just applying the same rules when deducing a template template parameter against other kinds of templates. This shouldn't stop you from cleaning up the code, whatever rules we come up here are for salvaging old code, not necessarily to entomb these as examples of good practice. 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] CTAD alias: Emit a more descriptive diagnostic message when is_deducible constraint is evaluated to false. (PR #92389)
mizvekov wrote: I already fixed this. We just had to constrain the triple, as there are differences in size_t underlying type which affect diagnostics. https://github.com/llvm/llvm-project/pull/92389 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)
mizvekov wrote: I just double checked, the issue is present on main before this PR was merged, it's completely unrelated. https://github.com/llvm/llvm-project/pull/90820 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)
https://github.com/mizvekov approved this pull request. LGTM, thanks for the fix! https://github.com/llvm/llvm-project/pull/92263 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)
mizvekov wrote: I just pushed a fix. https://github.com/llvm/llvm-project/pull/90820 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fe4d5f0 - [clang] NFC: stray space cleanup
Author: Matheus Izvekov Date: 2024-05-16T19:56:45-03:00 New Revision: fe4d5f0d0e457a0a7dec2c7dc87996706b30a25e URL: https://github.com/llvm/llvm-project/commit/fe4d5f0d0e457a0a7dec2c7dc87996706b30a25e DIFF: https://github.com/llvm/llvm-project/commit/fe4d5f0d0e457a0a7dec2c7dc87996706b30a25e.diff LOG: [clang] NFC: stray space cleanup Added: Modified: clang/test/SemaCXX/cxx20-ctad-type-alias.cpp Removed: diff --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp index 70e81cd79fd67..285532e3d80dd 100644 --- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp +++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp @@ -74,7 +74,7 @@ struct Foo { template using AF = Foo; -AF b{0}; +AF b{0}; } // namespace test6 namespace test7 { @@ -86,8 +86,8 @@ struct Foo { template using AF1 = Foo; template -using AF2 = AF1; -AF2 b = 1; +using AF2 = AF1; +AF2 b = 1; } // namespace test7 namespace test8 { @@ -149,7 +149,7 @@ namespace test12 { template struct Foo { template - struct Bar { + struct Bar { Bar(K); }; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] f210152 - [clang] constrain `SemaCXX/cxx20-ctad-type-alias.cpp` target triple
Author: Matheus Izvekov Date: 2024-05-16T19:56:45-03:00 New Revision: f210152e5fbcec1c50ff5ccc1f6680ab2c39b46f URL: https://github.com/llvm/llvm-project/commit/f210152e5fbcec1c50ff5ccc1f6680ab2c39b46f DIFF: https://github.com/llvm/llvm-project/commit/f210152e5fbcec1c50ff5ccc1f6680ab2c39b46f.diff LOG: [clang] constrain `SemaCXX/cxx20-ctad-type-alias.cpp` target triple The test expectations are otherwise affected by the underlying type of size_t. Added: Modified: clang/test/SemaCXX/cxx20-ctad-type-alias.cpp Removed: diff --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp index 21b2b8bff5002..70e81cd79fd67 100644 --- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp +++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wno-c++11-narrowing -Wno-literal-conversion -std=c++20 -verify %s +// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-linux -Wno-c++11-narrowing -Wno-literal-conversion -std=c++20 -verify %s namespace test1 { template ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)
mizvekov wrote: Yep, I confirm the behavior happens if I add `-triple x86_64-windows-msvc` to RUN line. https://github.com/llvm/llvm-project/pull/90820 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)
mizvekov wrote: Weirdly enough the test passes on my machine, latest MacOS. Maybe the test is not constrained on target, and this is causing differences between machines? https://github.com/llvm/llvm-project/pull/90820 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)
mizvekov wrote: The quick fix would be to change the expectations of the test, I can do it for you. https://github.com/llvm/llvm-project/pull/90820 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)
mizvekov wrote: That test was merged after the last time pre-commit CI was run on this MR. The change looks like a consequence of my refactoring, we now preserve the type sugar from the injected arguments. https://github.com/llvm/llvm-project/pull/90820 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)
https://github.com/mizvekov closed https://github.com/llvm/llvm-project/pull/90820 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)
https://github.com/mizvekov edited https://github.com/llvm/llvm-project/pull/90820 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)
https://github.com/mizvekov edited https://github.com/llvm/llvm-project/pull/90820 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)
https://github.com/mizvekov edited https://github.com/llvm/llvm-project/pull/90820 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)
https://github.com/mizvekov updated https://github.com/llvm/llvm-project/pull/90820 >From 39e0af93163068f8de190649eccf91fda84178b6 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Wed, 1 May 2024 22:29:45 -0300 Subject: [PATCH] [clang] Implement provisional wording for CWG2398 regarding packs This solves some ambuguity introduced in P0522 regarding how template template parameters are partially ordered, and should reduce the negative impact of enabling `-frelaxed-template-template-args` by default. When performing template argument deduction, a template template parameter containing no packs should be more specialized than one that does. Given the following example: ```C++ template struct A; template class TT1, class T4> struct A>; // #1 template class TT2, class T6> struct A>; // #2 template struct B; template struct A>; ``` Prior to P0522, candidate #2 would be more specialized. After P0522, neither is more specialized, so this becomes ambiguous. With this change, #2 becomes more specialized again, maintaining compatibility with pre-P0522 implementations. The problem is that in P0522, candidates are at least as specialized when matching packs to fixed-size lists both ways, whereas before, a fixed-size list is more specialized. This patch keeps the original behavior when checking template arguments outside deduction, but restores this aspect of pre-P0522 matching during deduction. --- Since this changes provisional implementation of CWG2398 which has not been released yet, and already contains a changelog entry, we don't provide a changelog entry here. --- clang/include/clang/Sema/Sema.h | 5 +- clang/lib/Sema/SemaTemplate.cpp | 10 ++-- clang/lib/Sema/SemaTemplateDeduction.cpp | 67 +++- clang/test/SemaTemplate/cwg2398.cpp | 15 ++ 4 files changed, 65 insertions(+), 32 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 6a414aa57f32b..7d7eb6c559110 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -9133,7 +9133,7 @@ class Sema final : public SemaBase { CheckTemplateArgumentKind CTAK); bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param, TemplateParameterList *Params, - TemplateArgumentLoc ); + TemplateArgumentLoc , bool IsDeduced); void NoteTemplateLocation(const NamedDecl , std::optional ParamRange = {}); @@ -9603,7 +9603,8 @@ class Sema final : public SemaBase { sema::TemplateDeductionInfo ); bool isTemplateTemplateParameterAtLeastAsSpecializedAs( - TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc); + TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc, + bool IsDeduced); void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced, unsigned Depth, llvm::SmallBitVector ); diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index c7aac068e264b..116d1ac077b29 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -6484,7 +6484,8 @@ bool Sema::CheckTemplateArgument( case TemplateArgument::Template: case TemplateArgument::TemplateExpansion: -if (CheckTemplateTemplateArgument(TempParm, Params, Arg)) +if (CheckTemplateTemplateArgument(TempParm, Params, Arg, + /*IsDeduced=*/CTAK != CTAK_Specified)) return true; SugaredConverted.push_back(Arg.getArgument()); @@ -8402,7 +8403,8 @@ static void DiagnoseTemplateParameterListArityMismatch( /// It returns true if an error occurred, and false otherwise. bool Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param, TemplateParameterList *Params, - TemplateArgumentLoc ) { + TemplateArgumentLoc , + bool IsDeduced) { TemplateName Name = Arg.getArgument().getAsTemplateOrTemplatePattern(); TemplateDecl *Template = Name.getAsTemplateDecl(); if (!Template) { @@ -8454,8 +8456,8 @@ bool Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param, !Template->hasAssociatedConstraints()) return false; -if (isTemplateTemplateParameterAtLeastAsSpecializedAs(Params, Template, - Arg.getLocation())) { +if (isTemplateTemplateParameterAtLeastAsSpecializedAs( +Params, Template, Arg.getLocation(), IsDeduced)) { // P2113 // C++20[temp.func.order]p2 // [...] If both deductions succeed, the partial ordering selects the diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp
[clang] 70a926c - [clang] NFC: Add a few more interesting test cases for CWG2398
Author: Matheus Izvekov Date: 2024-05-16T02:45:50-03:00 New Revision: 70a926cfb1d4af326be5afe6419991aeff8f44b2 URL: https://github.com/llvm/llvm-project/commit/70a926cfb1d4af326be5afe6419991aeff8f44b2 DIFF: https://github.com/llvm/llvm-project/commit/70a926cfb1d4af326be5afe6419991aeff8f44b2.diff LOG: [clang] NFC: Add a few more interesting test cases for CWG2398 Added: Modified: clang/test/SemaTemplate/cwg2398.cpp Removed: diff --git a/clang/test/SemaTemplate/cwg2398.cpp b/clang/test/SemaTemplate/cwg2398.cpp index a20155486b123..d163354b2e5fe 100644 --- a/clang/test/SemaTemplate/cwg2398.cpp +++ b/clang/test/SemaTemplate/cwg2398.cpp @@ -137,3 +137,61 @@ namespace ttp_defaults { // old-error@-2 {{template template argument has diff erent template parameters}} // old-error@-3 {{explicit instantiation of 'f' does not refer to a function template}} } // namespace ttp_defaults + +namespace ttp_only { + template class TT1> struct A { static constexpr int V = 0; }; + // new-note@-1 2{{template is declared here}} + template class TT2> struct A { static constexpr int V = 1; }; + // new-error@-1 {{not more specialized than the primary template}} + // new-note@-2 {{partial specialization matches}} + template class TT3> struct A { static constexpr int V = 2; }; + // new-error@-1 {{not more specialized than the primary template}} + // new-note@-2 {{partial specialization matches}} + + template struct B; + template struct C; + template struct D; + template struct E; + + static_assert(A::V == 0); // new-error {{ambiguous partial specializations}} + static_assert(A::V == 1); + static_assert(A::V == 2); + static_assert(A::V == 0); +} // namespace ttp_only + +namespace consistency { + template struct nondeduced { using type = T; }; + template struct B; + + namespace t1 { +template struct A; + +template class TT1, + class T1, class T2, class T3, class T4> +struct A, TT1, typename nondeduced>::type> {}; + +template class UU1, + template class UU2, + class U1, class U2> +struct A, UU2, typename nondeduced>::type>; + +template struct A, B, B>; + } // namespace t1 + namespace t2 { +template struct A; + +template class TT1, + class T1, class T2, class T3, class T4> +struct A, TT1, typename nondeduced>::type> {}; +// new-note@-1 {{partial specialization matches}} + +template class UU1, + template class UU2, + class U1, class U2> +struct A, UU2, typename nondeduced>::type>; +// new-note@-1 {{partial specialization matches}} + +template struct A, B, B>; +// new-error@-1 {{ambiguous partial specializations}} + } // namespace t1 +} // namespace consistency ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)
@@ -5591,7 +5592,11 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate( IsRValRef1); Args2.push_back(Obj2Ty); } -size_t NumComparedArguments = NumCallArguments1 + ShouldConvert1; +size_t NumComparedArguments = NumCallArguments1; +// Either added an argument above or the prototype includes an explicit +// object argument we need to count +if (Method1) + ++NumComparedArguments; mizvekov wrote: It seems like changing the `ExplicitCallArguments` member of `OverloadCandidate` into just `CallArguments` might simplify this whole thing. https://github.com/llvm/llvm-project/pull/92263 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)
https://github.com/mizvekov edited https://github.com/llvm/llvm-project/pull/90820 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)
https://github.com/mizvekov updated https://github.com/llvm/llvm-project/pull/90820 >From c4b72afa655c0e35005dca8aea18e651189f8938 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Wed, 1 May 2024 22:29:45 -0300 Subject: [PATCH] [clang] Implement provisional wording for CWG2398 regarding packs This solves some ambuguity introduced in P0522 regarding how template template parameters are partially ordered, and should reduce the negative impact of enabling `-frelaxed-template-template-args` by default. When performing template argument deduction, a template template parameter containing no packs should be more specialized than one that does. Given the following example: ```C++ template struct A; template class TT1, class T4> struct A>; // #1 template class TT2, class T6> struct A>; // #2 template struct B; template struct A>; ``` Prior to P0522, candidate #2 would be more specialized. After P0522, neither is more specialized, so this becomes ambiguous. With this change, #2 becomes more specialized again, maintaining compatibility with pre-P0522 implementations. The problem is that in P0522, candidates are at least as specialized when matching packs to fixed-size lists both ways, whereas before, a fixed-size list is more specialized. This patch keeps the original behavior when checking template arguments outside deduction, but restores this aspect of pre-P0522 matching during deduction. --- Since this changes provisional implementation of CWG2398 which has not been released yet, and already contains a changelog entry, we don't provide a changelog entry here. --- clang/include/clang/Sema/Sema.h | 5 +- clang/lib/Sema/SemaTemplate.cpp | 10 ++-- clang/lib/Sema/SemaTemplateDeduction.cpp | 67 +++- clang/test/SemaTemplate/cwg2398.cpp | 24 ++--- 4 files changed, 80 insertions(+), 26 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 6a414aa57f32b..7d7eb6c559110 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -9133,7 +9133,7 @@ class Sema final : public SemaBase { CheckTemplateArgumentKind CTAK); bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param, TemplateParameterList *Params, - TemplateArgumentLoc ); + TemplateArgumentLoc , bool IsDeduced); void NoteTemplateLocation(const NamedDecl , std::optional ParamRange = {}); @@ -9603,7 +9603,8 @@ class Sema final : public SemaBase { sema::TemplateDeductionInfo ); bool isTemplateTemplateParameterAtLeastAsSpecializedAs( - TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc); + TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc, + bool IsDeduced); void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced, unsigned Depth, llvm::SmallBitVector ); diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index c7aac068e264b..116d1ac077b29 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -6484,7 +6484,8 @@ bool Sema::CheckTemplateArgument( case TemplateArgument::Template: case TemplateArgument::TemplateExpansion: -if (CheckTemplateTemplateArgument(TempParm, Params, Arg)) +if (CheckTemplateTemplateArgument(TempParm, Params, Arg, + /*IsDeduced=*/CTAK != CTAK_Specified)) return true; SugaredConverted.push_back(Arg.getArgument()); @@ -8402,7 +8403,8 @@ static void DiagnoseTemplateParameterListArityMismatch( /// It returns true if an error occurred, and false otherwise. bool Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param, TemplateParameterList *Params, - TemplateArgumentLoc ) { + TemplateArgumentLoc , + bool IsDeduced) { TemplateName Name = Arg.getArgument().getAsTemplateOrTemplatePattern(); TemplateDecl *Template = Name.getAsTemplateDecl(); if (!Template) { @@ -8454,8 +8456,8 @@ bool Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param, !Template->hasAssociatedConstraints()) return false; -if (isTemplateTemplateParameterAtLeastAsSpecializedAs(Params, Template, - Arg.getLocation())) { +if (isTemplateTemplateParameterAtLeastAsSpecializedAs( +Params, Template, Arg.getLocation(), IsDeduced)) { // P2113 // C++20[temp.func.order]p2 // [...] If both deductions succeed, the partial ordering selects the diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp
[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)
mizvekov wrote: @joanahalili This is now merged in main: https://github.com/llvm/llvm-project/pull/92324 You can pass `-Wno-deprecated-no-relaxed-template-template-args` to disable the deprecation warning for `-fno-relaxed-template-template-args` specifically, without affecting other warnings. 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] Create new warning group for deprecation of '-fno-relaxed-template-template-args' (PR #92324)
https://github.com/mizvekov closed https://github.com/llvm/llvm-project/pull/92324 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Create new warning group for deprecation of '-fno-relaxed-template-template-args' (PR #92324)
https://github.com/mizvekov created https://github.com/llvm/llvm-project/pull/92324 This allows the warning to be disabled in isolation, as it helps when treating them as errors. >From 8b70909746ec85483b6d7f54fec4989956fb4c21 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Wed, 15 May 2024 19:41:03 -0300 Subject: [PATCH] [clang] Create new warning group for deprecation of '-fno-relaxed-template-template-args' This allows this warning to be disabled in isolation. This helps when treating warnings as errors. --- clang/docs/ReleaseNotes.rst | 3 ++- clang/include/clang/Basic/DiagnosticDriverKinds.td| 3 +++ clang/include/clang/Basic/DiagnosticGroups.td | 2 ++ clang/lib/Driver/ToolChains/Clang.cpp | 10 +++--- clang/test/Driver/frelaxed-template-template-args.cpp | 4 +++- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ae699ebfc6038..8f847a4376247 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -51,7 +51,8 @@ C++ Specific Potentially Breaking Changes - The behavior controlled by the `-frelaxed-template-template-args` flag is now on by default, and the flag is deprecated. Until the flag is finally removed, it's negative spelling can be used to obtain compatibility with previous - versions of clang. + versions of clang. The deprecation warning for the negative spelling can be + disabled with `-Wno-deprecated-no-relaxed-template-template-args`. - Clang now rejects pointer to member from parenthesized expression in unevaluated context such as ``decltype(&(foo::bar))``. (#GH40906). diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 9781fcaa4ff5e..9d97a75f696f6 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -436,6 +436,9 @@ def warn_drv_clang_unsupported : Warning< "the clang compiler does not support '%0'">; def warn_drv_deprecated_arg : Warning< "argument '%0' is deprecated%select{|, use '%2' instead}1">, InGroup; +def warn_drv_deprecated_arg_no_relaxed_template_template_args : Warning< + "argument '-fno-relaxed-template-template-args' is deprecated">, + InGroup; def warn_drv_deprecated_custom : Warning< "argument '%0' is deprecated, %1">, InGroup; def warn_drv_assuming_mfloat_abi_is : Warning< diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 2beb1d45124b4..4cb4f3d999f7a 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -104,6 +104,7 @@ def EnumConversion : DiagGroup<"enum-conversion", [EnumEnumConversion, EnumFloatConversion, EnumCompareConditional]>; +def DeprecatedNoRelaxedTemplateTemplateArgs : DiagGroup<"deprecated-no-relaxed-template-template-args">; def ObjCSignedCharBoolImplicitIntConversion : DiagGroup<"objc-signed-char-bool-implicit-int-conversion">; def Shorten64To32 : DiagGroup<"shorten-64-to-32">; @@ -228,6 +229,7 @@ def Deprecated : DiagGroup<"deprecated", [DeprecatedAnonEnumEnumConversion, DeprecatedLiteralOperator, DeprecatedPragma, DeprecatedRegister, + DeprecatedNoRelaxedTemplateTemplateArgs, DeprecatedThisCapture, DeprecatedType, DeprecatedVolatile, diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 42feb1650574e..c3e6d563f3bd2 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -7253,10 +7253,14 @@ void Clang::ConstructJob(Compilation , const JobAction , if (Arg *A = Args.getLastArg(options::OPT_frelaxed_template_template_args, options::OPT_fno_relaxed_template_template_args)) { -D.Diag(diag::warn_drv_deprecated_arg) -<< A->getAsString(Args) << /*hasReplacement=*/false; -if (A->getOption().matches(options::OPT_fno_relaxed_template_template_args)) +if (A->getOption().matches( +options::OPT_fno_relaxed_template_template_args)) { + D.Diag(diag::warn_drv_deprecated_arg_no_relaxed_template_template_args); CmdArgs.push_back("-fno-relaxed-template-template-args"); +} else { + D.Diag(diag::warn_drv_deprecated_arg) + << A->getAsString(Args) << /*hasReplacement=*/false; +} } // -fsized-deallocation is off by default, as it is an ABI-breaking change for diff --git
[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)
mizvekov wrote: > I think I prefer pretty fine-grained ones TBH, it makes our deprecation > warnings more valuable. In a perfect world, it would change every release of > the compiler so that folks would be frequently reminded of it, but it isn't a > perfect world :) I meant something fine grained, but generic, like `-Wno-deprecated-flag=-fno-relaxed-template-template-args`. We have something similar for generic warnings. That would probably take a little longer to get everyone onboard the design, and may lack other motivators presently. > Is doing so much of a task? I would expect it to be like other diagnostics > and take roughly the same amount of time as reverting the > negative-spelling-deprecation. I don't see the request to remove the > deprecation (it IS just a warning afterall!) to be particularly motivating > until release time (it IS just a warning afterall!), so I'd think it would a > better spending of time to implement what Richard suggested. Right, it takes about the same amount of time, so we may as well implement the simple thing, and argue about something else later if someone sees motivation. 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)
mizvekov wrote: Regarding @joanahalili 's post Does it sound good for everyone that we revert the deprecation of the positive spelling of the flag for a while, until we come up with a patch for a new flag which helps ignore these deprecations? 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)
mizvekov wrote: > Would it be reasonable to add a > `-Wno-deprecated-relaxed-template-template-args` flag (or something like > that) for this specific deprecation? I had similar idea, but what about instead implementing something generic to ignore deprecation of any driver flag? 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] Fix some assertions not looking through type sugar (PR #92299)
https://github.com/mizvekov approved this pull request. LGTM, Thanks! https://github.com/llvm/llvm-project/pull/92299 ___ 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)
mizvekov wrote: The fix was committed, and we just reverted the revert, so default is back to `-frelaxed-template-template-args`. 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] Revert "[clang] Revert default behavior change of P0522R0 implementation (#91811)" (PR #91837)
https://github.com/mizvekov closed https://github.com/llvm/llvm-project/pull/91837 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Revert "[clang] Revert default behavior change of P0522R0 implementation (#91811)" (PR #91837)
https://github.com/mizvekov ready_for_review https://github.com/llvm/llvm-project/pull/91837 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Revert "[clang] Revert default behavior change of P0522R0 implementation (#91811)" (PR #91837)
https://github.com/mizvekov updated https://github.com/llvm/llvm-project/pull/91837 >From 1a5b4761ba804a0998faf009370d74fa486014d9 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Sat, 11 May 2024 00:42:27 -0300 Subject: [PATCH] Revert "[clang] Revert default behavior change of P0522R0 implementation (#91811)" With blocking issues fixed, re-enable relaxed template template argument matching by reverting these commits. This reverts commit 4198aebc96cb0236fc63e29a92d886e6a2e3fedb. This reverts commit 2d5634a4b39d8e5497b6a67caa54049b3cfade8e. --- clang/lib/Driver/ToolChains/Clang.cpp | 14 +++--- .../Driver/frelaxed-template-template-args.cpp | 6 +++--- clang/test/Driver/rewrite-legacy-objc.m| 6 +++--- clang/test/Driver/rewrite-objc.m | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index f0cc018b6668f..42feb1650574e 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -7249,15 +7249,15 @@ void Clang::ConstructJob(Compilation , const JobAction , Args.addOptOutFlag(CmdArgs, options::OPT_fassume_unique_vtables, options::OPT_fno_assume_unique_vtables); - // -fno-relaxed-template-template-args is deprecated. - if (Arg *A = Args.getLastArg(options::OPT_frelaxed_template_template_args, - options::OPT_fno_relaxed_template_template_args); - A && - A->getOption().matches(options::OPT_fno_relaxed_template_template_args)) + // -frelaxed-template-template-args is deprecated. + if (Arg *A = + Args.getLastArg(options::OPT_frelaxed_template_template_args, + options::OPT_fno_relaxed_template_template_args)) { D.Diag(diag::warn_drv_deprecated_arg) << A->getAsString(Args) << /*hasReplacement=*/false; - else -CmdArgs.push_back("-fno-relaxed-template-template-args"); +if (A->getOption().matches(options::OPT_fno_relaxed_template_template_args)) + CmdArgs.push_back("-fno-relaxed-template-template-args"); + } // -fsized-deallocation is off by default, as it is an ABI-breaking change for // most platforms. diff --git a/clang/test/Driver/frelaxed-template-template-args.cpp b/clang/test/Driver/frelaxed-template-template-args.cpp index 136c360276a15..57fc4e3da6e5d 100644 --- a/clang/test/Driver/frelaxed-template-template-args.cpp +++ b/clang/test/Driver/frelaxed-template-template-args.cpp @@ -1,7 +1,7 @@ // RUN: %clang -fsyntax-only -### %s 2>&1 | FileCheck --check-prefix=CHECK-DEF %s -// RUN: %clang -fsyntax-only -frelaxed-template-template-args %s 2>&1 | FileCheck --check-prefix=CHECK-ON --allow-empty %s +// RUN: %clang -fsyntax-only -frelaxed-template-template-args %s 2>&1 | FileCheck --check-prefix=CHECK-ON %s // RUN: %clang -fsyntax-only -fno-relaxed-template-template-args %s 2>&1 | FileCheck --check-prefix=CHECK-OFF %s -// CHECK-DEF: "-cc1"{{.*}} "-fno-relaxed-template-template-args" -// CHECK-ON-NOT: warning: argument '-frelaxed-template-template-args' is deprecated [-Wdeprecated] +// CHECK-DEF-NOT: "-cc1"{{.*}} "-fno-relaxed-template-template-args" +// CHECK-ON: warning: argument '-frelaxed-template-template-args' is deprecated [-Wdeprecated] // CHECK-OFF: warning: argument '-fno-relaxed-template-template-args' is deprecated [-Wdeprecated] diff --git a/clang/test/Driver/rewrite-legacy-objc.m b/clang/test/Driver/rewrite-legacy-objc.m index d45fb8c405c52..413a7a7a61f05 100644 --- a/clang/test/Driver/rewrite-legacy-objc.m +++ b/clang/test/Driver/rewrite-legacy-objc.m @@ -3,11 +3,11 @@ // TEST0: "-cc1" // TEST0: "-rewrite-objc" // FIXME: CHECK-NOT is broken somehow, it doesn't work here. Check adjacency instead. -// TEST0: "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" "-fno-relaxed-template-template-args" "-fmax-type-align=16" +// TEST0: "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" "-fmax-type-align=16" // TEST0: rewrite-legacy-objc.m" // RUN: %clang --target=i386-apple-macosx10.9.0 -rewrite-legacy-objc %s -o - -### 2>&1 | \ // RUN: FileCheck -check-prefix=TEST1 %s // RUN: %clang --target=i386-apple-macosx10.6.0 -rewrite-legacy-objc %s -o - -### 2>&1 | \ // RUN: FileCheck -check-prefix=TEST2 %s -// TEST1: "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1"{{.*}} "-fobjc-runtime=macosx-fragile" "-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type"
[clang] Revert "[clang] Revert default behavior change of P0522R0 implementation (#91811)" (PR #91837)
https://github.com/mizvekov edited https://github.com/llvm/llvm-project/pull/91837 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Allow pack expansions when partial ordering against template template parameters (PR #91833)
https://github.com/mizvekov closed https://github.com/llvm/llvm-project/pull/91833 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Allow pack expansions when partial ordering against template template parameters (PR #91833)
https://github.com/mizvekov updated https://github.com/llvm/llvm-project/pull/91833 >From 06b9c19a1d194240be3199d50819090b10d697b6 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Fri, 10 May 2024 23:21:22 -0300 Subject: [PATCH] [clang] Allow pack expansions when partial ordering against template template parameters When partial ordering alias templates against template template parameters, allow pack expansions when the alias has a fixed-size parameter list. These expansions were generally disallowed by proposed resolution for CWG1430. By previously diagnosing these when checking template template parameters, we would be too strict in trying to prevent any potential invalid use. This flows against the more general idea that template template parameters are weakly typed, that we would rather allow an argument that might be possibly misused, and only diagnose the actual misuses during instantiation. Since this interaction between P0522R0 and CWG1430 is also a backwards-compat breaking change, we implement provisional wording to allow these. Fixes https://github.com/llvm/llvm-project/issues/62529 --- clang/docs/ReleaseNotes.rst| 2 ++ clang/include/clang/Sema/Sema.h| 8 +++- clang/lib/Sema/SemaTemplate.cpp| 14 ++ clang/lib/Sema/SemaTemplateDeduction.cpp | 4 +++- ...plate_cxx1z.cpp => temp_arg_template_p0522.cpp} | 12 ++-- 5 files changed, 32 insertions(+), 8 deletions(-) rename clang/test/SemaTemplate/{temp_arg_template_cxx1z.cpp => temp_arg_template_p0522.cpp} (91%) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 4702b8c10cdbb..28ac54127383a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -708,6 +708,8 @@ Bug Fixes to C++ Support expression. - Fix a bug in access control checking due to dealyed checking of friend declaration. Fixes (#GH12361). - Correctly treat the compound statement of an ``if consteval`` as an immediate context. Fixes (#GH91509). +- When partial ordering alias templates against template template parameters, + allow pack expansions when the alias has a fixed-size parameter list. Fixes (#GH62529). Bug Fixes to AST Handling ^ diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 4efd3878e861b..869769f95fd7f 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -9216,6 +9216,12 @@ class Sema final : public SemaBase { /// receive true if the cause for the error is the associated constraints of /// the template not being satisfied by the template arguments. /// + /// \param PartialOrderingTTP If true, assume these template arguments are + /// the injected template arguments for a template template parameter. + /// This will relax the requirement that all its possible uses are valid: + /// TTP checking is loose, and assumes that invalid uses will be diagnosed + /// during instantiation. + /// /// \returns true if an error occurred, false otherwise. bool CheckTemplateArgumentList( TemplateDecl *Template, SourceLocation TemplateLoc, @@ -9223,7 +9229,7 @@ class Sema final : public SemaBase { SmallVectorImpl , SmallVectorImpl , bool UpdateArgsWithConversions = true, - bool *ConstraintsNotSatisfied = nullptr); + bool *ConstraintsNotSatisfied = nullptr, bool PartialOrderingTTP = false); bool CheckTemplateTypeArgument( TemplateTypeParmDecl *Param, TemplateArgumentLoc , diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index bae00c6292703..8219d5eed8db7 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -6556,7 +6556,8 @@ bool Sema::CheckTemplateArgumentList( TemplateArgumentListInfo , bool PartialTemplateArgs, SmallVectorImpl , SmallVectorImpl , -bool UpdateArgsWithConversions, bool *ConstraintsNotSatisfied) { +bool UpdateArgsWithConversions, bool *ConstraintsNotSatisfied, +bool PartialOrderingTTP) { if (ConstraintsNotSatisfied) *ConstraintsNotSatisfied = false; @@ -6627,9 +6628,14 @@ bool Sema::CheckTemplateArgumentList( bool PackExpansionIntoNonPack = NewArgs[ArgIdx].getArgument().isPackExpansion() && (!(*Param)->isTemplateParameterPack() || getExpandedPackSize(*Param)); - if (PackExpansionIntoNonPack && (isa(Template) || - isa(Template))) { -// Core issue 1430: we have a pack expansion as an argument to an + // CWG1430: Don't diagnose this pack expansion when partial + // ordering template template parameters. Some uses of the template could + // be valid, and invalid uses will be diagnosed later during + // instantiation. + if (PackExpansionIntoNonPack && !PartialOrderingTTP && + (isa(Template) || + isa(Template))) { +//