-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[clang] Fix Name Mangling Crashes #134486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang Author: Vincent (Mr-Anyone) ChangesIt appears that Clang currently mangles names incorrectly when handling lambda expressions in constraint ( The issue likely stems from 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: 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: Full diff: https://github.com/llvm/llvm-project/pull/134486.diff 1 Files Affected:
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;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs tests as well as release notes.
Also please run clang-format on the changes.
Given that @mizvekov is working on fixing unevaluated lambda contexts, I wonder if these issues could be resolved the other way around, especially since there seems to be a crash on the existing test.
It appears that Clang currently mangles names incorrectly when handling lambda expressions in constraint (
requires
) clauses.The issue likely stems from
mangleLocalName
being used, whereasmangleNestedName
should be invoked instead. This is supported by the fact that GCC generates the following mangled name for the example below:GCC produces this mangled name:
Example output from clang after this change with previously crashing code:
It seems that something like this resolves these issues:
resolve #132925
resolve #131620
resolve #102169