[clang] 1d0bd8e - [MSABI] Remove comdat attribute for inheriting ctor.
Jennifer Yu via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 28 15:28:24 PDT 2023
Author: Jennifer Yu
Date: 2023-08-28T15:19:23-07:00
New Revision: 1d0bd8e51be2627f79bede54735c38b917ea04ee
URL: https://github.com/llvm/llvm-project/commit/1d0bd8e51be2627f79bede54735c38b917ea04ee
DIFF: https://github.com/llvm/llvm-project/commit/1d0bd8e51be2627f79bede54735c38b917ea04ee.diff
LOG: [MSABI] Remove comdat attribute for inheriting ctor.
Currently, for MS, the linkage for the inheriting constructors is set to
internal. However, the comdat attribute is also set like:
define internal noundef ptr @"??0?$B at _N@@qeaa at AEBVF@@aebua@@@z"(ptr noundef nonnull returned align 1 dereferenceable(1) %this, ptr noundef nonnull align 1 dereferenceable(1) %0, ptr noundef nonnull align 1 dereferenceable(1) %1) unnamed_addr comdat
This could cause linker to fail.
The change is to remove comdat attribute for the inheriting constructor
to make linker happy.
Differential Revision: https://reviews.llvm.org/D158538
Added:
clang/test/CodeGenCXX/ms-inheriting-ctor.cpp
Modified:
clang/lib/AST/ASTContext.cpp
clang/lib/CodeGen/CodeGenModule.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 42cc68c9b66285..8ab499be1ed2c7 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -11688,6 +11688,14 @@ static GVALinkage basicGVALinkageForFunction(const ASTContext &Context,
if (FD->isMSExternInline())
return GVA_StrongODR;
+ if (Context.getTargetInfo().getCXXABI().isMicrosoft() &&
+ isa<CXXConstructorDecl>(FD) &&
+ cast<CXXConstructorDecl>(FD)->isInheritingConstructor())
+ // Our approach to inheriting constructors is fundamentally
diff erent from
+ // that used by the MS ABI, so keep our inheriting constructor thunks
+ // internal rather than trying to pick an unambiguous mangling for them.
+ return GVA_Internal;
+
return GVA_DiscardableODR;
}
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 9b241165b7c579..08bc1a8d018606 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1970,15 +1970,6 @@ CodeGenModule::getFunctionLinkage(GlobalDecl GD) {
if (const auto *Dtor = dyn_cast<CXXDestructorDecl>(D))
return getCXXABI().getCXXDestructorLinkage(Linkage, Dtor, GD.getDtorType());
- if (isa<CXXConstructorDecl>(D) &&
- cast<CXXConstructorDecl>(D)->isInheritingConstructor() &&
- Context.getTargetInfo().getCXXABI().isMicrosoft()) {
- // Our approach to inheriting constructors is fundamentally
diff erent from
- // that used by the MS ABI, so keep our inheriting constructor thunks
- // internal rather than trying to pick an unambiguous mangling for them.
- return llvm::GlobalValue::InternalLinkage;
- }
-
return getLLVMLinkageForDeclarator(D, Linkage);
}
diff --git a/clang/test/CodeGenCXX/ms-inheriting-ctor.cpp b/clang/test/CodeGenCXX/ms-inheriting-ctor.cpp
new file mode 100644
index 00000000000000..6c6cdcf2c358c2
--- /dev/null
+++ b/clang/test/CodeGenCXX/ms-inheriting-ctor.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -fcxx-exceptions -triple=x86_64-windows-msvc -emit-llvm %s -o - | FileCheck %s
+
+class F {
+public:
+ F(wchar_t *);
+};
+using a = F;
+struct A {};
+struct b {
+ b(a, F, A);
+};
+template <typename, typename> struct c : b {
+ c(const a &p1, const A &d) : b(p1, 0, d) {}
+};
+template <typename e> struct B : c<e, b> {
+ using c<e, b>::c;
+};
+class f {
+public:
+ f(...);
+}
+
+typedef g;
+class C {
+public:
+ C(g, f);
+};
+static wchar_t h;
+class D {
+public:
+ static C E();
+};
+
+C D::E() {
+ C i(B<bool>(&h, {}), f());
+ return i;
+}
+
+// Inheriting ctor has internal linkage without comdat.
+
+// CHECK-LABEL: define internal noundef ptr @"??0?$B at _N@@QEAA at AEBVF@@AEBUA@@@Z"
+// CHECK-NOT:comdat
+// CHECK-SAME: {{\{$}}
+
+// non-inheriting ctro should has linkonce_odr with comdat attribute.
+
+// CHECK-LABEL: define linkonce_odr dso_local noundef ptr @"??0?$c at _NUb@@@@QEAA at AEBVF@@AEBUA@@@Z"
+// CHECK:comdat
+// CHECK-SAME: {{\{$}}
More information about the cfe-commits
mailing list