Skip to content

Commit

Permalink
[clang][Itanium Mangle] Enable mangling of enclosing class for member…
Browse files Browse the repository at this point in the history
…-like friend function templates only if ` -fclang-abi-compat>=19`.
  • Loading branch information
VitaNuo committed Sep 30, 2024
1 parent 735a5f6 commit f22108b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ ABI Changes in This Version

- Fixed Microsoft name mangling of placeholder, auto and decltype(auto), return types for MSVC 1920+. This change resolves incompatibilities with code compiled by MSVC 1920+ but will introduce incompatibilities with code compiled by earlier versions of Clang unless such code is built with the compiler option -fms-compatibility-version=19.14 to imitate the MSVC 1914 mangling behavior.
- Fixed the Itanium mangling of the construction vtable name. This change will introduce incompatibilities with code compiled by Clang 19 and earlier versions, unless the -fclang-abi-compat=19 option is used. (#GH108015)
- Mangle friend function templates with a constraint that depends on a template parameter from an enclosing template as members of the enclosing class. (#GH110247, #GH110503)

AST Dumping Potentially Breaking Changes
----------------------------------------
Expand Down Expand Up @@ -447,7 +448,6 @@ Bug Fixes to C++ Support
- Fixed an assertion failure in debug mode, and potential crashes in release mode, when
diagnosing a failed cast caused indirectly by a failed implicit conversion to the type of the constructor parameter.
- Fixed an assertion failure by adjusting integral to boolean vector conversions (#GH108326)
- Mangle friend function templates with a constraint that depends on a template parameter from an enclosing template as members of the enclosing class. (#GH110247)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
3 changes: 2 additions & 1 deletion clang/include/clang/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ class LangOptionsBase {

/// Attempt to be ABI-compatible with code generated by Clang 19.0.x.
/// This causes clang to:
/// - Incorrectly mangles the 'base type' substitutions of the CXX
/// - Incorrectly mangle the 'base type' substitutions of the CXX
/// construction vtable because it hasn't added 'type' as a substitution.
/// - Skip mangling enclosing class templates of member-like friend function templates.
Ver19,

/// Conform to the underlying platform's C and C++ ABIs as closely
Expand Down
11 changes: 10 additions & 1 deletion clang/lib/AST/ItaniumMangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}

Expand Down
4 changes: 4 additions & 0 deletions clang/test/CodeGenCXX/mangle-concept.cpp
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit f22108b

Please sign in to comment.