[clang] [Clang][ItaniumMangle] Preserve field-name closure-prefix for instantiated lambdas (PR #195340)

via cfe-commits cfe-commits at lists.llvm.org
Fri May 1 12:52:21 PDT 2026


https://github.com/eiytoq created https://github.com/llvm/llvm-project/pull/195340

Previously, instantiation did not pass `LambdaContextDecl`, so the NSDMI lambda in the class template used the wrong `ContextDecl`.

Fixes: #190555 

>From 1b147eae437eb07b214db51dc14600e2a7d30b7e Mon Sep 17 00:00:00 2001
From: eiytoq <eiytoq at outlook.com>
Date: Sat, 2 May 2026 02:45:43 +0800
Subject: [PATCH 1/2] [Clang][ItaniumMangle] Preserve field-name closure-prefix
 for instantiated lambdas

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp                  | 3 ++-
 clang/test/CodeGenCXX/dtor-local-lambda-mangle.cpp          | 2 +-
 clang/test/CodeGenCXX/lambda-expressions-nested-linkage.cpp | 4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index f9dcd8b24b783..f4cd6ca9930ff 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3873,7 +3873,8 @@ bool Sema::InstantiateInClassInitializer(
   // we don't have a scope.
   ContextRAII SavedContext(*this, Instantiation->getParent());
   EnterExpressionEvaluationContext EvalContext(
-      *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
+      *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated,
+      Instantiation);
   ExprEvalContexts.back().DelayedDefaultInitializationContext = {
       PointOfInstantiation, Instantiation, CurContext};
 
diff --git a/clang/test/CodeGenCXX/dtor-local-lambda-mangle.cpp b/clang/test/CodeGenCXX/dtor-local-lambda-mangle.cpp
index 2c0269ecdaec5..95283dad4a933 100644
--- a/clang/test/CodeGenCXX/dtor-local-lambda-mangle.cpp
+++ b/clang/test/CodeGenCXX/dtor-local-lambda-mangle.cpp
@@ -18,7 +18,7 @@ E::E() {
 template<typename T>
 E::E(T t) {
   struct {
-    // CHECK-DAG: _ZTSN1EC1IiEUt_UlvE_E
+    // CHECK-DAG: _ZTSN1EC1IiEUt_12anotherValueMUlvE_E
     int anotherValue = [x = 1] { return x; }();
   } obj;
 }
diff --git a/clang/test/CodeGenCXX/lambda-expressions-nested-linkage.cpp b/clang/test/CodeGenCXX/lambda-expressions-nested-linkage.cpp
index bb21c87eed8ff..1b4268f56ab48 100644
--- a/clang/test/CodeGenCXX/lambda-expressions-nested-linkage.cpp
+++ b/clang/test/CodeGenCXX/lambda-expressions-nested-linkage.cpp
@@ -43,8 +43,8 @@ L<int> l;
 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZNK12non_template1L1tMUliE_clEiENKUliE_clEi(ptr
 
 
-// CHECK-LABEL: define linkonce_odr void @_ZNK32lambdas_in_NSDMIs_template_class1LIiEUliE_clEi(ptr
-// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZNK32lambdas_in_NSDMIs_template_class1LIiEUliE_clEiENKUliE_clEi(ptr
+// CHECK-LABEL: define linkonce_odr void @_ZNK32lambdas_in_NSDMIs_template_class1LIiE2t2MUliE_clEi(ptr
+// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZNK32lambdas_in_NSDMIs_template_class1LIiE2t2MUliE_clEiENKUliE_clEi(ptr
 
 // CHECK-LABEL: define linkonce_odr void @_ZZN15inline_function3fooEvENKUliE_clEi
 // CHECK-LABEL: define linkonce_odr noundef signext i8 @_ZZZN15inline_function3fooEvENKUliE_clEiENKUlcE_clEc

>From e2233a96d050a22985311c22f73eb54fe1510cd1 Mon Sep 17 00:00:00 2001
From: eiytoq <eiytoq at outlook.com>
Date: Sat, 2 May 2026 02:53:29 +0800
Subject: [PATCH 2/2] Update release notes

---
 clang/docs/ReleaseNotes.rst | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c408196c3816b..de0ab38137c32 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -62,6 +62,9 @@ ABI Changes in This Version
   types, or ``_Complex float`` types are passed, and may introduce
   incompatibilities with code compiled by earlier versions of Clang that uses
   the ``__regcall`` calling convention on these targets. (#GH62999) (#GH98635)
+- Fixed Itanium mangling for lambdas in instantiated non-static data member
+  initializers by preserving the field-name closure-prefix. This changes the
+  mangled names for affected lambdas. (#GH190555)
 
 AST Dumping Potentially Breaking Changes
 ----------------------------------------



More information about the cfe-commits mailing list