From f9e5dc7d82c98bd3d3588557237a2dda18c57635 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 15 Jul 2015 14:48:06 +0000 Subject: [PATCH] Set comdat when an available_externally thunk is converted to linkonce_odr. Fixes pr24130. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242293 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGVTables.cpp | 29 +++++++++++++++++------------ test/CodeGenCXX/thunks.cpp | 17 +++++++++++++++++ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/lib/CodeGen/CGVTables.cpp b/lib/CodeGen/CGVTables.cpp index 373009e8bf..7321dbfe34 100644 --- a/lib/CodeGen/CGVTables.cpp +++ b/lib/CodeGen/CGVTables.cpp @@ -56,6 +56,21 @@ static void setThunkVisibility(CodeGenModule &CGM, const CXXMethodDecl *MD, CGM.setGlobalVisibility(Fn, MD); } +static void setThunkProperties(CodeGenModule &CGM, const ThunkInfo &Thunk, + llvm::Function *ThunkFn, bool ForVTable, + GlobalDecl GD) { + CGM.setFunctionLinkage(GD, ThunkFn); + CGM.getCXXABI().setThunkLinkage(ThunkFn, ForVTable, GD, + !Thunk.Return.isEmpty()); + + // Set the right visibility. + const CXXMethodDecl *MD = cast(GD.getDecl()); + setThunkVisibility(CGM, MD, Thunk, ThunkFn); + + if (CGM.supportsCOMDAT() && ThunkFn->isWeakForLinker()) + ThunkFn->setComdat(CGM.getModule().getOrInsertComdat(ThunkFn->getName())); +} + #ifndef NDEBUG static bool similar(const ABIArgInfo &infoL, CanQualType typeL, const ABIArgInfo &infoR, CanQualType typeR) { @@ -429,8 +444,7 @@ void CodeGenVTables::emitThunk(GlobalDecl GD, const ThunkInfo &Thunk, return; } - // Change the linkage. - CGM.setFunctionLinkage(GD, ThunkFn); + setThunkProperties(CGM, Thunk, ThunkFn, ForVTable, GD); return; } @@ -451,16 +465,7 @@ void CodeGenVTables::emitThunk(GlobalDecl GD, const ThunkInfo &Thunk, CodeGenFunction(CGM).generateThunk(ThunkFn, FnInfo, GD, Thunk); } - CGM.setFunctionLinkage(GD, ThunkFn); - CGM.getCXXABI().setThunkLinkage(ThunkFn, ForVTable, GD, - !Thunk.Return.isEmpty()); - - // Set the right visibility. - const CXXMethodDecl *MD = cast(GD.getDecl()); - setThunkVisibility(CGM, MD, Thunk, ThunkFn); - - if (CGM.supportsCOMDAT() && ThunkFn->isWeakForLinker()) - ThunkFn->setComdat(CGM.getModule().getOrInsertComdat(ThunkFn->getName())); + setThunkProperties(CGM, Thunk, ThunkFn, ForVTable, GD); } void CodeGenVTables::maybeEmitThunkForVTable(GlobalDecl GD, diff --git a/test/CodeGenCXX/thunks.cpp b/test/CodeGenCXX/thunks.cpp index 0e97255cc6..38afb9d0db 100644 --- a/test/CodeGenCXX/thunks.cpp +++ b/test/CodeGenCXX/thunks.cpp @@ -361,6 +361,23 @@ namespace Test15 { // CHECK: declare void @_ZThn8_N6Test151C1fEiz } +namespace Test16 { +struct A { + virtual ~A(); +}; +struct B { + virtual void foo(); +}; +struct C : public A, public B { + void foo() {} +}; +struct D : public C { + ~D(); +}; +D::~D() {} +// CHECK: define linkonce_odr void @_ZThn8_N6Test161C3fooEv({{.*}}) {{.*}} comdat +} + /**** The following has to go at the end of the file ****/ // This is from Test5: -- 2.40.0