Skip to content

Commit 1d0bd8e

Browse files
committed
[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@_N@@qeaa@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
1 parent 8885296 commit 1d0bd8e

File tree

3 files changed

+57
-9
lines changed

3 files changed

+57
-9
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11688,6 +11688,14 @@ static GVALinkage basicGVALinkageForFunction(const ASTContext &Context,
1168811688
if (FD->isMSExternInline())
1168911689
return GVA_StrongODR;
1169011690

11691+
if (Context.getTargetInfo().getCXXABI().isMicrosoft() &&
11692+
isa<CXXConstructorDecl>(FD) &&
11693+
cast<CXXConstructorDecl>(FD)->isInheritingConstructor())
11694+
// Our approach to inheriting constructors is fundamentally different from
11695+
// that used by the MS ABI, so keep our inheriting constructor thunks
11696+
// internal rather than trying to pick an unambiguous mangling for them.
11697+
return GVA_Internal;
11698+
1169111699
return GVA_DiscardableODR;
1169211700
}
1169311701

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,15 +1970,6 @@ CodeGenModule::getFunctionLinkage(GlobalDecl GD) {
19701970
if (const auto *Dtor = dyn_cast<CXXDestructorDecl>(D))
19711971
return getCXXABI().getCXXDestructorLinkage(Linkage, Dtor, GD.getDtorType());
19721972

1973-
if (isa<CXXConstructorDecl>(D) &&
1974-
cast<CXXConstructorDecl>(D)->isInheritingConstructor() &&
1975-
Context.getTargetInfo().getCXXABI().isMicrosoft()) {
1976-
// Our approach to inheriting constructors is fundamentally different from
1977-
// that used by the MS ABI, so keep our inheriting constructor thunks
1978-
// internal rather than trying to pick an unambiguous mangling for them.
1979-
return llvm::GlobalValue::InternalLinkage;
1980-
}
1981-
19821973
return getLLVMLinkageForDeclarator(D, Linkage);
19831974
}
19841975

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// RUN: %clang_cc1 -fcxx-exceptions -triple=x86_64-windows-msvc -emit-llvm %s -o - | FileCheck %s
2+
3+
class F {
4+
public:
5+
F(wchar_t *);
6+
};
7+
using a = F;
8+
struct A {};
9+
struct b {
10+
b(a, F, A);
11+
};
12+
template <typename, typename> struct c : b {
13+
c(const a &p1, const A &d) : b(p1, 0, d) {}
14+
};
15+
template <typename e> struct B : c<e, b> {
16+
using c<e, b>::c;
17+
};
18+
class f {
19+
public:
20+
f(...);
21+
}
22+
23+
typedef g;
24+
class C {
25+
public:
26+
C(g, f);
27+
};
28+
static wchar_t h;
29+
class D {
30+
public:
31+
static C E();
32+
};
33+
34+
C D::E() {
35+
C i(B<bool>(&h, {}), f());
36+
return i;
37+
}
38+
39+
// Inheriting ctor has internal linkage without comdat.
40+
41+
// CHECK-LABEL: define internal noundef ptr @"??0?$B@_N@@QEAA@AEBVF@@AEBUA@@@Z"
42+
// CHECK-NOT:comdat
43+
// CHECK-SAME: {{\{$}}
44+
45+
// non-inheriting ctro should has linkonce_odr with comdat attribute.
46+
47+
// CHECK-LABEL: define linkonce_odr dso_local noundef ptr @"??0?$c@_NUb@@@@QEAA@AEBVF@@AEBUA@@@Z"
48+
// CHECK:comdat
49+
// CHECK-SAME: {{\{$}}

0 commit comments

Comments
 (0)