https://github.com/Mr-Anyone created 
https://github.com/llvm/llvm-project/pull/134486
It appears that Clang currently mangles names incorrectly when handling lambda 
expressions in constraint (`requires`) clauses.

 The issue likely stems from `mangleLocalName` being used, whereas 
`mangleNestedName` should be invoked instead. This is supported by the fact 
that GCC generates the following mangled name for the example below:

```cpp
template<typename T>
auto a = [](T a) requires requires {
    [](T a){}(a);
} {
    return a;
};

// _ZNK1aIiEUliE_clEiQrqXcltlNS_IT_EUlS2_E_EEfL0p_EE
//                           ^
//                           |
//                         Nested Name
void func() {
    a<int>(1);
}
```

GCC produces this mangled name:

Example output from clang after this change with previously crashing code:

```cpp
template<typename T>
auto a = [](T a)requires requires{
    [](T a){}(a);
}{
    return a;
};

//
void func(){
//_ZNK1aIiEMUliE_clEiQrqXclLN1aMUlT_E_clUlS3_E_EEfp_EE
    a<int>(1);
}

void func2() {
// _ZZ5func2vENK3$_0clIiEEDaT_QrqXclLNS_clUlTnivE_EEEE
    [](auto x) requires requires {
        []<int = 0>() {}();
    } {}(0);
}
```

It seems that something like this resolves these issues:
resolve #132925 
resolve #131620
resolve #102169

>From 75310f7fbdae35e8e8a8acb5d3b27c28b34a1813 Mon Sep 17 00:00:00 2001
From: Mr-Anyone <53135664+mr-any...@users.noreply.github.com>
Date: Sat, 5 Apr 2025 01:09:00 -0700
Subject: [PATCH] [clang] Fix Mame Mangling Crashes

---
 clang/lib/AST/ItaniumMangle.cpp | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index fdd84d0bf7c5c..90d6255917654 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -1088,6 +1088,16 @@ void CXXNameMangler::mangleNameWithAbiTags(GlobalDecl GD,
     return;
   }
 
+  const RecordDecl *RD = GetLocalClassDecl(GD.getDecl());
+  if(RD){
+      const DeclContext *DC = Context.getEffectiveDeclContext(RD);
+      const FunctionDecl* FD = dyn_cast<FunctionDecl>(DC);
+      if(FD->getTrailingRequiresClause() && IsLambda){
+          mangleNestedName(GD, DC, AdditionalAbiTags);
+          return;
+      }
+  }
+
   if (isLocalContainerContext(DC)) {
     mangleLocalName(GD, AdditionalAbiTags);
     return;

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to