Skip to content

[MS-ABI] skip generate comdat for vftable defined with internal alias. #71748

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

Merged
merged 5 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions clang/lib/CodeGen/MicrosoftCXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1892,9 +1892,7 @@ llvm::GlobalVariable *MicrosoftCXXABI::getAddrOfVTable(const CXXRecordDecl *RD,

llvm::Comdat *C = nullptr;
if (!VFTableComesFromAnotherTU &&
(llvm::GlobalValue::isWeakForLinker(VFTableLinkage) ||
(llvm::GlobalValue::isLocalLinkage(VFTableLinkage) &&
VTableAliasIsRequred)))
llvm::GlobalValue::isWeakForLinker(VFTableLinkage))
C = CGM.getModule().getOrInsertComdat(VFTableName.str());

// Only insert a pointer into the VFTable for RTTI data if we are not
Expand Down
30 changes: 30 additions & 0 deletions clang/test/CodeGenCXX/ms-local-vft-alias-comdat.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// RUN: %clang_cc1 -fcxx-exceptions -triple=x86_64-windows-msvc \
// RUN: -Wmicrosoft-template -fms-compatibility -emit-llvm %s -o - \
// RUN: | FileCheck %s

template <typename a> struct T {
virtual void c();
T(a h) {}
};
struct m {
template <typename j> void ab(j ac) {
using ad = T<j>;
ad j(ac);
}
};
template <typename ae> struct n {
template <typename j> n(j ac) { q.ab(ac); }
ae q;
};
class s : n<m> {
using ag = n<m>;
public:
template <typename j> s(j ac) : ag(ac) {}
};
struct ah {
ah(s);
} a([]{});

//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"] }
//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)
//CHECK-NOT : "??_7?$e@V<lambda_0>@@@@6B@" = comdat any
6 changes: 3 additions & 3 deletions clang/test/CodeGenCXX/type-metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@
// MS-TYPEMETADATA: comdat($"??_7B@@6B0@@"), !type [[B8:![0-9]+]]
// MS-TYPEMETADATA: comdat($"??_7B@@6BA@@@"), !type [[A8]]
// MS-TYPEMETADATA: comdat($"??_7C@@6B@"), !type [[A8]]
// MS-TYPEMETADATA: comdat($"??_7D@?A0x{{[^@]*}}@@6BB@@@"), !type [[B8]], !type [[D8:![0-9]+]]
// MS-TYPEMETADATA: comdat($"??_7D@?A0x{{[^@]*}}@@6BA@@@"), !type [[A8]]
// MS-TYPEMETADATA: comdat($"??_7FA@?1??foo@@YAXXZ@6B@"), !type [[A8]], !type [[FA8:![0-9]+]]
// 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]+]]
// MS-TYPEMETADATA: private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4D@?{{.*}}@@6BA@@@", ptr @"?f@D@?{{.*}}@@$4PPPPPPPM@A@EAAXXZ"] }, !type !0
// 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]+]]

struct A {
A();
Expand Down