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 <[email protected]> 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<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; }) + }; +}); +} +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
