llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: eiytoq (eiytoq)

<details>
<summary>Changes</summary>

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<LinkageSpecDecl>(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 0000000000000..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 <typename Predicate>
+void foo(Predicate pred) {
+  pred(42);
+}
+
+template <typename Predicate>
+auto bar(Predicate pred) {
+  foo(pred);
+}
+
+template <typename T>
+concept Baz = requires(const T& x) {
+  {
+    bar([](const auto&) { return true; })
+  };
+};
+
+static_assert(Baz<int>);
+}
+
+namespace PR {
+template <typename Predicate>
+void foo(Predicate pred) {
+  pred(42);
+}
+
+template <typename Predicate>
+auto bar(Predicate pred) {
+  foo(pred);
+}
+
+extern "C++" {
+static_assert(requires(const int& x) {
+  {
+    bar([](const auto&) { return true; })
+  };
+});
+}
+}

``````````

</details>


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

Reply via email to