[clang] [Clang][ItaniumMangle] Skip requires-expression body contexts (PR #202221)

2026-08-21 Thread Corentin Jabot via cfe-commits

https://github.com/cor3ntin commented:

This change needs a release note.
Please add an entry to `clang/docs/ReleaseNotes.md` in the section the most 
adapted to the change, and referencing any Github issue this change fixes. 
Thanks!

https://github.com/llvm/llvm-project/pull/202221
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][ItaniumMangle] Skip requires-expression body contexts (PR #202221)

2026-06-30 Thread via cfe-commits

eiytoq wrote:

Ping

https://github.com/llvm/llvm-project/pull/202221
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][ItaniumMangle] Skip requires-expression body contexts (PR #202221)

2026-06-07 Thread via cfe-commits

https://github.com/eiytoq edited 
https://github.com/llvm/llvm-project/pull/202221
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ItaniumMangle] Skip requires-expression body contexts (PR #202221)

2026-06-07 Thread via cfe-commits

https://github.com/eiytoq updated 
https://github.com/llvm/llvm-project/pull/202221

>From 519402905ba442500e71cd02c0de500473c570fd Mon Sep 17 00:00:00 2001
From: eiytoq 
Date: Mon, 8 Jun 2026 02:23:05 +0800
Subject: [PATCH 1/2] fix

---
 clang/lib/AST/ItaniumMangle.cpp   |  5 ++-
 .../CodeGenCXX/mangle-lambdas-gh181933.cpp| 42 +++
 2 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCXX/mangle-lambdas-gh181933.cpp

diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 85a01c6f4f727..82d47804268eb 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -1090,7 +1090,7 @@ void CXXNameMangler::mangleNameWithAbiTags(
   }
 
   while (DC->isRequiresExprBody())
-DC = DC->getParent();
+DC = Context.getEffectiveParentContext(DC);
 
   if (DC->isTranslationUnit() || isStdNamespace(DC)) {
 // Check if we have a template.
@@ -2205,6 +2205,9 @@ void CXXNameMangler::manglePrefix(const DeclContext *DC, 
bool NoFunction) {
 
   assert(!isa(DC) && "prefix cannot be LinkageSpecDecl");
 
+  while (DC->isRequiresExprBody())
+  DC = Context.getEffectiveParentContext(DC);
+
   if (DC->isTranslationUnit())
 return;
 
diff --git a/clang/test/CodeGenCXX/mangle-lambdas-gh181933.cpp 
b/clang/test/CodeGenCXX/mangle-lambdas-gh181933.cpp
new file mode 100644
index 0..6fd913d9534cd
--- /dev/null
+++ b/clang/test/CodeGenCXX/mangle-lambdas-gh181933.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-llvm -o 
/dev/null %s
+
+namespace GH181933 {
+template 
+void foo(Predicate pred) {
+  pred(42);
+}
+
+template 
+auto bar(Predicate pred) {
+  foo(pred);
+}
+
+template 
+concept Baz = requires(const T& x) {
+  {
+bar([](const auto&) { return true; })
+  };
+};
+
+static_assert(Baz);
+}
+
+namespace PR {
+template 
+void foo(Predicate pred) {
+  pred(42);
+}
+
+template 
+auto bar(Predicate pred) {
+  foo(pred);
+}
+
+extern "C++" {
+static_assert(requires(const int& x) {
+  {
+bar([](const auto&) { return true; })
+  };
+});
+}
+}

>From 5c165ade898cf41bf387d7c5f4a48943a71b5117 Mon Sep 17 00:00:00 2001
From: eiytoq 
Date: Mon, 8 Jun 2026 02:39:30 +0800
Subject: [PATCH 2/2] ci

---
 clang/lib/AST/ItaniumMangle.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 82d47804268eb..08cf61a26e507 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -2206,7 +2206,7 @@ void CXXNameMangler::manglePrefix(const DeclContext *DC, 
bool NoFunction) {
   assert(!isa(DC) && "prefix cannot be LinkageSpecDecl");
 
   while (DC->isRequiresExprBody())
-  DC = Context.getEffectiveParentContext(DC);
+DC = Context.getEffectiveParentContext(DC);
 
   if (DC->isTranslationUnit())
 return;

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ItaniumMangle] Skip requires-expression body contexts (PR #202221)

2026-06-07 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff origin/main HEAD --extensions cpp -- 
clang/test/CodeGenCXX/mangle-lambdas-gh181933.cpp 
clang/lib/AST/ItaniumMangle.cpp --diff_from_common_commit
``

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index ceafbdeba..c7d0ba785 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -2206,7 +2206,7 @@ void CXXNameMangler::manglePrefix(const DeclContext *DC, 
bool NoFunction) {
   assert(!isa(DC) && "prefix cannot be LinkageSpecDecl");
 
   while (DC->isRequiresExprBody())
-  DC = Context.getEffectiveParentContext(DC);
+DC = Context.getEffectiveParentContext(DC);
 
   if (DC->isTranslationUnit())
 return;

``




https://github.com/llvm/llvm-project/pull/202221
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ItaniumMangle] Skip requires-expression body contexts (PR #202221)

2026-06-07 Thread via cfe-commits

llvmorg-github-actions[bot] wrote:




@llvm/pr-subscribers-clang

Author: eiytoq (eiytoq)


Changes

DC's parent may not be a `RequiresExprBody`, but a `RequiresExprBody` may 
indirectly exist in the context chain. In this case, `RequiresExprBody` will 
leak into `manglePrefix` and cause a crash. This patch makes `manglePrefix` 
skip `RequiresExprBody` DCs to fix it.

Use `getEffectiveParentContext` instead of `getParent` because some contexts, 
such as `extern`, also cannot be leaked into the next mangling step.

Fixes #181933

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


2 Files Affected:

- (modified) clang/lib/AST/ItaniumMangle.cpp (+4-1) 
- (added) clang/test/CodeGenCXX/mangle-lambdas-gh181933.cpp (+42) 


``diff
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 85a01c6f4f727..82d47804268eb 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -1090,7 +1090,7 @@ void CXXNameMangler::mangleNameWithAbiTags(
   }
 
   while (DC->isRequiresExprBody())
-DC = DC->getParent();
+DC = Context.getEffectiveParentContext(DC);
 
   if (DC->isTranslationUnit() || isStdNamespace(DC)) {
 // Check if we have a template.
@@ -2205,6 +2205,9 @@ void CXXNameMangler::manglePrefix(const DeclContext *DC, 
bool NoFunction) {
 
   assert(!isa(DC) && "prefix cannot be LinkageSpecDecl");
 
+  while (DC->isRequiresExprBody())
+  DC = Context.getEffectiveParentContext(DC);
+
   if (DC->isTranslationUnit())
 return;
 
diff --git a/clang/test/CodeGenCXX/mangle-lambdas-gh181933.cpp 
b/clang/test/CodeGenCXX/mangle-lambdas-gh181933.cpp
new file mode 100644
index 0..6fd913d9534cd
--- /dev/null
+++ b/clang/test/CodeGenCXX/mangle-lambdas-gh181933.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-llvm -o 
/dev/null %s
+
+namespace GH181933 {
+template 
+void foo(Predicate pred) {
+  pred(42);
+}
+
+template 
+auto bar(Predicate pred) {
+  foo(pred);
+}
+
+template 
+concept Baz = requires(const T& x) {
+  {
+bar([](const auto&) { return true; })
+  };
+};
+
+static_assert(Baz);
+}
+
+namespace PR {
+template 
+void foo(Predicate pred) {
+  pred(42);
+}
+
+template 
+auto bar(Predicate pred) {
+  foo(pred);
+}
+
+extern "C++" {
+static_assert(requires(const int& x) {
+  {
+bar([](const auto&) { return true; })
+  };
+});
+}
+}

``




https://github.com/llvm/llvm-project/pull/202221
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ItaniumMangle] Skip requires-expression body contexts (PR #202221)

2026-06-07 Thread via cfe-commits

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

DC's parent may not be a `RequiresExprBody`, but a `RequiresExprBody` may 
indirectly exist in the context chain. In this case, `RequiresExprBody` will 
leak into `manglePrefix` and cause a crash. This patch makes `manglePrefix` 
skip `RequiresExprBody` DCs to fix it.

Use `getEffectiveParentContext` instead of `getParent` because some contexts, 
such as `extern`, also cannot be leaked into the next mangling step.

Fixes #181933

>From 519402905ba442500e71cd02c0de500473c570fd Mon Sep 17 00:00:00 2001
From: eiytoq 
Date: Mon, 8 Jun 2026 02:23:05 +0800
Subject: [PATCH] fix

---
 clang/lib/AST/ItaniumMangle.cpp   |  5 ++-
 .../CodeGenCXX/mangle-lambdas-gh181933.cpp| 42 +++
 2 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCXX/mangle-lambdas-gh181933.cpp

diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 85a01c6f4f727..82d47804268eb 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -1090,7 +1090,7 @@ void CXXNameMangler::mangleNameWithAbiTags(
   }
 
   while (DC->isRequiresExprBody())
-DC = DC->getParent();
+DC = Context.getEffectiveParentContext(DC);
 
   if (DC->isTranslationUnit() || isStdNamespace(DC)) {
 // Check if we have a template.
@@ -2205,6 +2205,9 @@ void CXXNameMangler::manglePrefix(const DeclContext *DC, 
bool NoFunction) {
 
   assert(!isa(DC) && "prefix cannot be LinkageSpecDecl");
 
+  while (DC->isRequiresExprBody())
+  DC = Context.getEffectiveParentContext(DC);
+
   if (DC->isTranslationUnit())
 return;
 
diff --git a/clang/test/CodeGenCXX/mangle-lambdas-gh181933.cpp 
b/clang/test/CodeGenCXX/mangle-lambdas-gh181933.cpp
new file mode 100644
index 0..6fd913d9534cd
--- /dev/null
+++ b/clang/test/CodeGenCXX/mangle-lambdas-gh181933.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-llvm -o 
/dev/null %s
+
+namespace GH181933 {
+template 
+void foo(Predicate pred) {
+  pred(42);
+}
+
+template 
+auto bar(Predicate pred) {
+  foo(pred);
+}
+
+template 
+concept Baz = requires(const T& x) {
+  {
+bar([](const auto&) { return true; })
+  };
+};
+
+static_assert(Baz);
+}
+
+namespace PR {
+template 
+void foo(Predicate pred) {
+  pred(42);
+}
+
+template 
+auto bar(Predicate pred) {
+  foo(pred);
+}
+
+extern "C++" {
+static_assert(requires(const int& x) {
+  {
+bar([](const auto&) { return true; })
+  };
+});
+}
+}

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits