llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Corentin Jabot (cor3ntin)

<details>
<summary>Changes</summary>

When we create a lambda, we would skip over declaration contexts representing a 
require expression body, which would lead to wrong lookup.

Note that I wasn't able to establish why the code
in `Sema::createLambdaClosureType` was there to begin with (it's not exactly 
recent)

The changes to mangling only ensure the status quo is preserved and do not 
attempt to address the known issues of
mangling lambdas in require clauses.

In particular the itanium mangling is consistent with Clang before this patch 
but differs from GCC's.

Fixes #<!-- -->147650

---
Full diff: https://github.com/llvm/llvm-project/pull/147764.diff


6 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+3) 
- (modified) clang/lib/Sema/SemaLambda.cpp (-2) 
- (modified) clang/test/CodeGenCXX/mangle-requires.cpp (+13) 
- (modified) clang/test/CodeGenCXX/ms-mangle-requires.cpp (+12) 
- (modified) clang/test/SemaTemplate/concepts-lambda.cpp (+10) 


``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 805095e4c77ef..bcc913498ee12 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -913,6 +913,7 @@ Bug Fixes to C++ Support
 - Fix a bug where private access specifier of overloaded function not 
respected. (#GH107629)
 - Correctly handle allocations in the condition of a ``if 
constexpr``.(#GH120197) (#GH134820)
 - Fixed a crash when handling invalid member using-declaration in C++20+ mode. 
(#GH63254)
+- Fix name lookup in lambda appearing in the body of a requires expression. 
(#GH147650)
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 8a1d4e8313e28..0520987ce6b3a 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -1088,6 +1088,9 @@ void CXXNameMangler::mangleNameWithAbiTags(GlobalDecl GD,
     return;
   }
 
+  while (DC->isRequiresExprBody())
+    DC = DC->getParent();
+
   if (DC->isTranslationUnit() || isStdNamespace(DC)) {
     // Check if we have a template.
     const TemplateArgumentList *TemplateArgs = nullptr;
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 2c00616bc62d7..bc3c4b0addeba 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -249,8 +249,6 @@ Sema::createLambdaClosureType(SourceRange IntroducerRange, 
TypeSourceInfo *Info,
                               unsigned LambdaDependencyKind,
                               LambdaCaptureDefault CaptureDefault) {
   DeclContext *DC = CurContext;
-  while (!(DC->isFunctionOrMethod() || DC->isRecord() || DC->isFileContext()))
-    DC = DC->getParent();
 
   bool IsGenericLambda =
       Info && getGenericLambdaTemplateParameterList(getCurLambda(), *this);
diff --git a/clang/test/CodeGenCXX/mangle-requires.cpp 
b/clang/test/CodeGenCXX/mangle-requires.cpp
index 9e2bdde03407a..506c5aaf43b9b 100644
--- a/clang/test/CodeGenCXX/mangle-requires.cpp
+++ b/clang/test/CodeGenCXX/mangle-requires.cpp
@@ -32,3 +32,16 @@ template <typename T> void g(int n) requires requires (T m) {
 } {}
 // CHECK: define {{.*}}@_Z1gIiEviQrQT__XplfL0p_fp_E(
 template void g<int>(int);
+
+
+namespace GH147650 {
+
+template <int> int b;
+template <int b>
+void f()
+    requires requires { [] { (void)b; }; } {}
+void test() {
+    f<42>();
+}
+// CHECK-LABEL:define {{.*}} void @"_ZN8GH1476501fILi42EEEvvQrqXLNS_3$_0EEE"()
+}
diff --git a/clang/test/CodeGenCXX/ms-mangle-requires.cpp 
b/clang/test/CodeGenCXX/ms-mangle-requires.cpp
index 15318ecffaf01..88c432c54b117 100644
--- a/clang/test/CodeGenCXX/ms-mangle-requires.cpp
+++ b/clang/test/CodeGenCXX/ms-mangle-requires.cpp
@@ -57,3 +57,15 @@ void m_fn2() {
 } // namespace Regression2
 
 }
+
+namespace GH147650 {
+
+template <int> int b;
+template <int b>
+void f()
+    requires requires { [] { (void)b; }; } {}
+void test() {
+    f<42>();
+}
+// CHECK-LABEL:define {{.*}} void @"??$f@$0CK@@GH147650@@YAXXZ"()
+}
diff --git a/clang/test/SemaTemplate/concepts-lambda.cpp 
b/clang/test/SemaTemplate/concepts-lambda.cpp
index 1f67c2511e096..f5b1c2277f601 100644
--- a/clang/test/SemaTemplate/concepts-lambda.cpp
+++ b/clang/test/SemaTemplate/concepts-lambda.cpp
@@ -340,3 +340,13 @@ void foo() {
 }
 
 }
+
+namespace GH147650 {
+template <int> int b;
+template <int b>
+void f()
+    requires requires { [] { (void)b; static_assert(b == 42); }; } {}
+void test() {
+    f<42>();
+}
+}

``````````

</details>


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

Reply via email to