Skip to content
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

[clang][Itanium Mangle] Enable mangling of enclosing class for member… #110503

Merged
merged 2 commits into from
Oct 2, 2024

Conversation

VitaNuo
Copy link
Contributor

@VitaNuo VitaNuo commented Sep 30, 2024

…-like friend function templates only if -fclang-abi-compat>19.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Sep 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 30, 2024

@llvm/pr-subscribers-libcxxabi

@llvm/pr-subscribers-clang

Author: Viktoriia Bakalova (VitaNuo)

Changes

…-like friend function templates only if -fclang-abi-compat>=19.


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

2 Files Affected:

  • (modified) clang/lib/AST/ItaniumMangle.cpp (+10-1)
  • (modified) clang/test/CodeGenCXX/mangle-concept.cpp (+4)
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 117255178eebb4..3d9d1e3f22f832 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -693,7 +693,7 @@ ItaniumMangleContextImpl::getEffectiveDeclContext(const Decl *D) {
     if (VD->isExternC())
       return getASTContext().getTranslationUnitDecl();
 
-  if (const auto *FD = D->getAsFunction()) {
+  if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
     if (FD->isExternC())
       return getASTContext().getTranslationUnitDecl();
     // Member-like constrained friends are mangled as if they were members of
@@ -704,6 +704,15 @@ ItaniumMangleContextImpl::getEffectiveDeclContext(const Decl *D) {
       return D->getLexicalDeclContext()->getRedeclContext();
   }
 
+  if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(D)) {
+    // Member-like constrained friends are mangled as if they were members of
+    // the enclosing class.
+    if (FTD->getTemplatedDecl()->isMemberLikeConstrainedFriend() &&
+        getASTContext().getLangOpts().getClangABICompat() >
+            LangOptions::ClangABI::Ver19)
+      return D->getLexicalDeclContext()->getRedeclContext();
+  }
+
   return DC->getRedeclContext();
 }
 
diff --git a/clang/test/CodeGenCXX/mangle-concept.cpp b/clang/test/CodeGenCXX/mangle-concept.cpp
index 6053511c00a7b5..aa0940c35b237a 100644
--- a/clang/test/CodeGenCXX/mangle-concept.cpp
+++ b/clang/test/CodeGenCXX/mangle-concept.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -verify -std=c++20 -emit-llvm -triple %itanium_abi_triple -o - %s -fclang-abi-compat=latest | FileCheck %s
+// RUN: %clang_cc1 -verify -std=c++20 -emit-llvm -triple %itanium_abi_triple -o - %s -fclang-abi-compat=19 | FileCheck %s --check-prefix=CLANG19
 // RUN: %clang_cc1 -verify -std=c++20 -emit-llvm -triple %itanium_abi_triple -o - %s -fclang-abi-compat=17 | FileCheck %s --check-prefix=CLANG17
 // expected-no-diagnostics
 
@@ -59,18 +60,21 @@ namespace test2 {
     // CLANG17: call {{.*}}@_ZN5test21fEz(
     f(ai);
     // CHECK: call {{.*}}@_ZN5test21AIiEF1gIvEEvzQaa4TrueIT_E4TrueITL0__E(
+    // CLANG19: call {{.*}}@_ZN5test2F1gIvEEvzQaa4TrueIT_E4TrueITL0__E(
     // CLANG17: call {{.*}}@_ZN5test21gIvEEvz(
     g(ai);
     // CHECK: call {{.*}}@_ZN5test21hIvEEvzQ4TrueITL0__E(
     // CLANG17: call {{.*}}@_ZN5test21hIvEEvz(
     h(ai);
     // CHECK: call {{.*}}@_ZN5test21AIiEF1iIvQaa4TrueIT_E4TrueITL0__EEEvz(
+    // CLANG19: call {{.*}}@_ZN5test2F1iIvQaa4TrueIT_E4TrueITL0__EEEvz(
     // CLANG17: call {{.*}}@_ZN5test21iIvEEvz(
     i(ai);
     // CHECK: call {{.*}}@_ZN5test21jIvQ4TrueITL0__EEEvz(
     // CLANG17: call {{.*}}@_ZN5test21jIvEEvz(
     j(ai);
     // CHECK: call {{.*}}@_ZN5test21AIiEF1kITk4TruevQ4TrueIT_EEEvz(
+    // CLANG19: call {{.*}}@_ZN5test2F1kITk4TruevQ4TrueIT_EEEvz(
     // CLANG17: call {{.*}}@_ZN5test21kIvEEvz(
     k(ai);
     // CHECK: call {{.*}}@_ZN5test21lITk4TruevEEvz(

@VitaNuo VitaNuo linked an issue Sep 30, 2024 that may be closed by this pull request
@VitaNuo VitaNuo self-assigned this Sep 30, 2024
@VitaNuo VitaNuo added ABI Application Binary Interface concepts C++20 concepts libc++abi libc++abi C++ Runtime Library. Not libc++. tools:llvm-cxxfilt labels Sep 30, 2024
@hokein
Copy link
Collaborator

hokein commented Sep 30, 2024

Thanks.

Can you update the comment here to mention this case?

And I think it is better to move the release note Mangle friend function ... from the Bug Fixes to C++ Support to ABI Changes in This Version.

@VitaNuo VitaNuo force-pushed the fix-abi-compat branch 2 times, most recently from f22108b to 53ef5a1 Compare September 30, 2024 13:22
@VitaNuo
Copy link
Contributor Author

VitaNuo commented Sep 30, 2024

Thanks.

Can you update the comment here to mention this case?

And I think it is better to move the release note Mangle friend function ... from the Bug Fixes to C++ Support to ABI Changes in This Version.

Thank you, the comments should be addressed now.

Copy link
Collaborator

@hokein hokein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this looks good to me. Let’s wait for a bit to see if other reviewers have any additional comments.

Copy link
Contributor

@usx95 usx95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Left a comment about adding a FIXME to remove ABI compat checks and figuring out the support for past ABI.

if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(D)) {
// Member-like constrained friends are mangled as if they were members of
// the enclosing class.
if (FTD->getTemplatedDecl()->isMemberLikeConstrainedFriend() &&
getASTContext().getLangOpts().getClangABICompat() >
LangOptions::ClangABI::Ver19)
return D->getLexicalDeclContext()->getRedeclContext();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks quite a tech debt. I am not aware of our policy regarding the past ABIs we should be supporting, but there definitely should be a time limit.
We should add a fixme to remove ABI checks after supported time

FIXME: Remove check for Ver17 and use D->getAsFunction() after clang-X
FIXME: Remove check for Ver19 after clang-Y

@zygoloid Are you aware of a reasonable clang version (X and Y here) after which we should stop supporting Ver17 ? I can guess maybe 1-3 years ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have maintained more burdensome things for ABI compatibility for longer. I don't think we have a policy for removing old ABI things, but some Clang users depend on setting the ABI compat back quite a long way. Establishing a policy seems like a good idea.

@@ -693,7 +693,7 @@ ItaniumMangleContextImpl::getEffectiveDeclContext(const Decl *D) {
if (VD->isExternC())
return getASTContext().getTranslationUnitDecl();

if (const auto *FD = D->getAsFunction()) {
if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can reduce the duplication a little?

Suggested change
if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
if (const auto *FD =
getASTContext().getLangOpts().getClangABICompat() >
LangOptions::ClangABI::Ver19 ? D->getAsFunction() : dyn_cast<FunctionDecl>(D)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, simplified.

Copy link

github-actions bot commented Oct 2, 2024

✅ With the latest revision this PR passed the Python code formatter.

Copy link

github-actions bot commented Oct 2, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

if (FD->isMemberLikeConstrainedFriend() &&
getASTContext().getLangOpts().getClangABICompat() >
LangOptions::ClangABI::Ver17)
if (FD->isMemberLikeConstrainedFriend())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a behavior change, we should keep the getClangABICompat() > LangOptions::ClangABI::Ver17 check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sorry, I might have misinterpreted the comment above.

@@ -693,14 +693,13 @@ ItaniumMangleContextImpl::getEffectiveDeclContext(const Decl *D) {
if (VD->isExternC())
return getASTContext().getTranslationUnitDecl();

if (const auto *FD = D->getAsFunction()) {
if (FD->isExternC())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why removing the isExternC()? this will change the behavior.

Copy link
Contributor Author

@VitaNuo VitaNuo Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's back, thanks.

…-like friend function templates only if ` -fclang-abi-compat>=19`.
Copy link
Contributor

@usx95 usx95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. LGTM.

@VitaNuo VitaNuo merged commit 91e3fb3 into llvm:main Oct 2, 2024
6 of 8 checks passed
Sterling-Augustine pushed a commit to Sterling-Augustine/llvm-project that referenced this pull request Oct 3, 2024
llvm#110503)

…-like friend function templates only if ` -fclang-abi-compat>19`.
xgupta pushed a commit to xgupta/llvm-project that referenced this pull request Oct 4, 2024
llvm#110503)

…-like friend function templates only if ` -fclang-abi-compat>19`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ABI Application Binary Interface clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category concepts C++20 concepts libc++abi libc++abi C++ Runtime Library. Not libc++. tools:llvm-cxxfilt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[abi] Declaring class of a member-like friend method is not mangled.
5 participants