Skip to content

Commit 10cc3a8

Browse files
authored
[MS-ABI] skip generate comdat for vftable defined with internal alias. (llvm#71748)
We got a error: `LLVM ERROR: Associative COMDAT symbol '??_7?$T@V<lambda_0>@@@@6b@' is not a key for its COMDAT` Current we create internal alias for vftable when lambd is used. For the test, IR generate: ``` $"??_7?$T@V<lambda_0>@@$0A@@@6b@" = comdat any @0 = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4?$T@V<lambda_0>@@$0A@@@6b@", ptr @"?c@b@@UEAAXXZ"] }, comdat($"??_7?$T@V<lambda_0>@@$0A@@@6b@") @"??_7?$T@V<lambda_0>@@$0A@@@6b@" = internal unnamed_addr alias ptr, getelementptr inbounds ({ [2 x ptr] }, ptr @0, i32 0, i32 0, i32 1) ``` According LLVM language reference manual section on COMDATs: There are some restrictions on the properties of the global object. It, or an alias to it, must have the same name as the COMDAT group when targeting COFF. The contents and size of this object may be used during link-time to determine which COMDAT groups get selected depending on the selection kind. Because the name of the object must match the name of the COMDAT group, the linkage of the global object must not be local; local symbols can get renamed if a collision occurs in the symbol table. So one way to fix this is to not create comdat for the alias. @0 = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4?$T@V<lambda_0>@@@@6b@", ptr @"?c@?$T@V<lambda_0>@@@@UEAAXXZ"] }
1 parent 8a40fca commit 10cc3a8

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

clang/lib/CodeGen/MicrosoftCXXABI.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,9 +1892,7 @@ llvm::GlobalVariable *MicrosoftCXXABI::getAddrOfVTable(const CXXRecordDecl *RD,
18921892

18931893
llvm::Comdat *C = nullptr;
18941894
if (!VFTableComesFromAnotherTU &&
1895-
(llvm::GlobalValue::isWeakForLinker(VFTableLinkage) ||
1896-
(llvm::GlobalValue::isLocalLinkage(VFTableLinkage) &&
1897-
VTableAliasIsRequred)))
1895+
llvm::GlobalValue::isWeakForLinker(VFTableLinkage))
18981896
C = CGM.getModule().getOrInsertComdat(VFTableName.str());
18991897

19001898
// Only insert a pointer into the VFTable for RTTI data if we are not
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %clang_cc1 -fcxx-exceptions -triple=x86_64-windows-msvc \
2+
// RUN: -Wmicrosoft-template -fms-compatibility -emit-llvm %s -o - \
3+
// RUN: | FileCheck %s
4+
5+
template <typename a> struct T {
6+
virtual void c();
7+
T(a h) {}
8+
};
9+
struct m {
10+
template <typename j> void ab(j ac) {
11+
using ad = T<j>;
12+
ad j(ac);
13+
}
14+
};
15+
template <typename ae> struct n {
16+
template <typename j> n(j ac) { q.ab(ac); }
17+
ae q;
18+
};
19+
class s : n<m> {
20+
using ag = n<m>;
21+
public:
22+
template <typename j> s(j ac) : ag(ac) {}
23+
};
24+
struct ah {
25+
ah(s);
26+
} a([]{});
27+
28+
//CHECK: @0 = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4?$T@V<lambda_0>@@@@6B@", ptr @"?c@?$T@V<lambda_0>@@@@UEAAXXZ"] }
29+
//CHECK: @"??_7?$T@V<lambda_0>@@@@6B@" = internal unnamed_addr alias ptr, getelementptr inbounds ({ [2 x ptr] }, ptr @0, i32 0, i32 0, i32 1)
30+
//CHECK-NOT : "??_7?$e@V<lambda_0>@@@@6B@" = comdat any

clang/test/CodeGenCXX/type-metadata.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@
125125
// MS-TYPEMETADATA: comdat($"??_7B@@6B0@@"), !type [[B8:![0-9]+]]
126126
// MS-TYPEMETADATA: comdat($"??_7B@@6BA@@@"), !type [[A8]]
127127
// MS-TYPEMETADATA: comdat($"??_7C@@6B@"), !type [[A8]]
128-
// MS-TYPEMETADATA: comdat($"??_7D@?A0x{{[^@]*}}@@6BB@@@"), !type [[B8]], !type [[D8:![0-9]+]]
129-
// MS-TYPEMETADATA: comdat($"??_7D@?A0x{{[^@]*}}@@6BA@@@"), !type [[A8]]
130-
// MS-TYPEMETADATA: comdat($"??_7FA@?1??foo@@YAXXZ@6B@"), !type [[A8]], !type [[FA8:![0-9]+]]
128+
// MS-TYPEMETADATA: private unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr @"??_R4D@?{{.*}}@@6BB@@@", ptr @"?g@B@@UEAAXXZ", ptr @"?h@D@?{{.*}}@@UEAAXXZ"] }, !type [[B8]], !type [[D8:![0-9]+]]
129+
// MS-TYPEMETADATA: private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4D@?{{.*}}@@6BA@@@", ptr @"?f@D@?{{.*}}@@$4PPPPPPPM@A@EAAXXZ"] }, !type !0
130+
// MS: private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4FA@?1??foo@@YAXXZ@6B@", ptr @"?f@FA@?1??foo@@YAXXZ@UEAAXXZ"] }, !type !0, !type [[FA8:![0-9]+]]
131131

132132
struct A {
133133
A();

0 commit comments

Comments
 (0)