[clang] [clang][Sema] GH58548 (PR #80395)

2024-02-02 Thread Younan Zhang via cfe-commits

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


[clang] [clang][Sema] GH58548 (PR #80395)

2024-02-01 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/80395

>From 24a8251aab9a1a03953412ae47508d039d926212 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 2 Feb 2024 15:24:13 +0800
Subject: [PATCH 1/2] [clang][Sema] Fix GH58548

---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/Sema/SemaOverload.cpp   |  3 ++-
 .../SemaTemplate/concepts-recovery-expr.cpp   | 27 +++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 37f2423441a30..f4c5c3421f2e8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -183,6 +183,9 @@ Bug Fixes to C++ Support
 - Fix for crash when using a erroneous type in a return statement.
   Fixes (`#63244 `_)
   and (`#79745 `_)
+- Fixed an out-of-bounds error caused by building a recovery expression for 
ill-formed
+  function calls while substituting into constraints.
+  (`https://github.com/llvm/llvm-project/issues/58548`_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
 
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 940bcccb9e261..6a04d68b4f041 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7623,7 +7623,8 @@ void Sema::AddTemplateOverloadCandidate(
   //   functions. In such a case, the candidate functions generated from each
   //   function template are combined with the set of non-template candidate
   //   functions.
-  TemplateDeductionInfo Info(CandidateSet.getLocation());
+  TemplateDeductionInfo Info(CandidateSet.getLocation(),
+ FunctionTemplate->getTemplateDepth());
   FunctionDecl *Specialization = nullptr;
   ConversionSequenceList Conversions;
   if (TemplateDeductionResult Result = DeduceTemplateArguments(
diff --git a/clang/test/SemaTemplate/concepts-recovery-expr.cpp 
b/clang/test/SemaTemplate/concepts-recovery-expr.cpp
index 2f9d432ebac0e..b338f3bc271bf 100644
--- a/clang/test/SemaTemplate/concepts-recovery-expr.cpp
+++ b/clang/test/SemaTemplate/concepts-recovery-expr.cpp
@@ -180,3 +180,30 @@ void StaticMemOVCUse() {
   // expected-note@#SMEMOVC3 {{candidate template ignored: constraints not 
satisfied}}
   // expected-note@#SMEMOVC3REQ{{because substituted constraint expression is 
ill-formed: constraint depends on a previously diagnosed expression}}
 }
+
+namespace GH58548 {
+
+template  struct formatter; // #primary-template
+template  struct basic_format_context {};
+
+template 
+concept has_format_function =
+format(basic_format_context());
+
+template 
+  requires has_format_function
+struct formatter {
+  template 
+  CharType format(basic_format_context);
+};
+
+template  int handle_replacement_field(Ctx arg) {
+  formatter ctx; // expected-error {{implicit 
instantiation of undefined template}}
+  return 0;
+}
+
+int x = handle_replacement_field(0);
+// expected-note@-1 {{template specialization 
'GH58548::handle_replacement_field' requested here}}
+// expected-note@#primary-template {{is declared here}}
+
+} // GH58548

>From 4b0ad32d98e2e8f515db2e6163aa3a7394d76ccf Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 2 Feb 2024 15:38:56 +0800
Subject: [PATCH 2/2] fixup

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f4c5c3421f2e8..67661b9d94db9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -185,7 +185,7 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fixed an out-of-bounds error caused by building a recovery expression for 
ill-formed
   function calls while substituting into constraints.
-  (`https://github.com/llvm/llvm-project/issues/58548`_)
+  (`#58548 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
 

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


[clang] [clang][Sema] GH58548 (PR #80395)

2024-02-01 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/80395

Draft for triggering the libc++ CI.

>From 24a8251aab9a1a03953412ae47508d039d926212 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 2 Feb 2024 15:24:13 +0800
Subject: [PATCH] [clang][Sema] Fix GH58548

---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/Sema/SemaOverload.cpp   |  3 ++-
 .../SemaTemplate/concepts-recovery-expr.cpp   | 27 +++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 37f2423441a30..f4c5c3421f2e8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -183,6 +183,9 @@ Bug Fixes to C++ Support
 - Fix for crash when using a erroneous type in a return statement.
   Fixes (`#63244 `_)
   and (`#79745 `_)
+- Fixed an out-of-bounds error caused by building a recovery expression for 
ill-formed
+  function calls while substituting into constraints.
+  (`https://github.com/llvm/llvm-project/issues/58548`_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
 
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 940bcccb9e261..6a04d68b4f041 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7623,7 +7623,8 @@ void Sema::AddTemplateOverloadCandidate(
   //   functions. In such a case, the candidate functions generated from each
   //   function template are combined with the set of non-template candidate
   //   functions.
-  TemplateDeductionInfo Info(CandidateSet.getLocation());
+  TemplateDeductionInfo Info(CandidateSet.getLocation(),
+ FunctionTemplate->getTemplateDepth());
   FunctionDecl *Specialization = nullptr;
   ConversionSequenceList Conversions;
   if (TemplateDeductionResult Result = DeduceTemplateArguments(
diff --git a/clang/test/SemaTemplate/concepts-recovery-expr.cpp 
b/clang/test/SemaTemplate/concepts-recovery-expr.cpp
index 2f9d432ebac0e..b338f3bc271bf 100644
--- a/clang/test/SemaTemplate/concepts-recovery-expr.cpp
+++ b/clang/test/SemaTemplate/concepts-recovery-expr.cpp
@@ -180,3 +180,30 @@ void StaticMemOVCUse() {
   // expected-note@#SMEMOVC3 {{candidate template ignored: constraints not 
satisfied}}
   // expected-note@#SMEMOVC3REQ{{because substituted constraint expression is 
ill-formed: constraint depends on a previously diagnosed expression}}
 }
+
+namespace GH58548 {
+
+template  struct formatter; // #primary-template
+template  struct basic_format_context {};
+
+template 
+concept has_format_function =
+format(basic_format_context());
+
+template 
+  requires has_format_function
+struct formatter {
+  template 
+  CharType format(basic_format_context);
+};
+
+template  int handle_replacement_field(Ctx arg) {
+  formatter ctx; // expected-error {{implicit 
instantiation of undefined template}}
+  return 0;
+}
+
+int x = handle_replacement_field(0);
+// expected-note@-1 {{template specialization 
'GH58548::handle_replacement_field' requested here}}
+// expected-note@#primary-template {{is declared here}}
+
+} // GH58548

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