From: Dario Domizioli Date: Fri, 19 Sep 2014 22:06:24 +0000 (+0000) Subject: Fix ctor/dtor aliases losing 'dllexport' (for Itanium ABI) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b96c3eeb86ded2991bed7b236d51f45b0f0d83a4;p=clang Fix ctor/dtor aliases losing 'dllexport' (for Itanium ABI) This patch makes sure that the dllexport attribute is transferred to the alias when such alias is created. It only affects the Itanium ABI because for the MSVC ABI a workaround is in place to not generate aliases of dllexport ctors/dtors. A new CodeGenModule function is provided, CodeGenModule::setAliasAttributes, to factor the code for transferring attributes to aliases. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@218159 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 5e87fc2799..6e7da49a44 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -786,6 +786,16 @@ void CodeGenModule::SetCommonAttributes(const Decl *D, addUsedGlobal(GV); } +void CodeGenModule::setAliasAttributes(const Decl *D, + llvm::GlobalValue *GV) { + SetCommonAttributes(D, GV); + + // Process the dllexport attribute based on whether the original definition + // (not necessarily the aliasee) was exported. + if (D->hasAttr()) + GV->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass); +} + void CodeGenModule::setNonAliasAttributes(const Decl *D, llvm::GlobalObject *GO) { SetCommonAttributes(D, GO); diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index a095c9ddbb..afd5b5d404 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -1069,6 +1069,12 @@ public: /// NOTE: This should only be called for definitions. void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV); + /// Set attributes which must be preserved by an alias. This includes common + /// attributes (i.e. it includes a call to SetCommonAttributes). + /// + /// NOTE: This should only be called for definitions. + void setAliasAttributes(const Decl *D, llvm::GlobalValue *GV); + void addReplacement(StringRef Name, llvm::Constant *C); private: diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp index ed7b4e9dad..84bfb6aa50 100644 --- a/lib/CodeGen/ItaniumCXXABI.cpp +++ b/lib/CodeGen/ItaniumCXXABI.cpp @@ -3077,7 +3077,7 @@ static void emitConstructorDestructorAlias(CodeGenModule &CGM, } // Finally, set up the alias with its proper name and attributes. - CGM.SetCommonAttributes(cast(AliasDecl.getDecl()), Alias); + CGM.setAliasAttributes(cast(AliasDecl.getDecl()), Alias); } void ItaniumCXXABI::emitCXXStructor(const CXXMethodDecl *MD, diff --git a/test/CodeGenCXX/dllexport-alias.cpp b/test/CodeGenCXX/dllexport-alias.cpp new file mode 100644 index 0000000000..479595d057 --- /dev/null +++ b/test/CodeGenCXX/dllexport-alias.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -triple x86_64-windows-gnu -mconstructor-aliases %s -S -emit-llvm -o - | FileCheck %s + +// This test assumes that the C1 constructor will be aliased to the C2 +// constructor, and the D1 destructor to the D2. It then checks that the aliases +// are dllexport'ed. + +class __declspec(dllexport) A { +public: + A(); + ~A(); +}; + +A::A() {} + +A::~A() {} + +// CHECK: @_ZN1AC1Ev = dllexport alias void (%class.A*)* @_ZN1AC2Ev +// CHECK: @_ZN1AD1Ev = dllexport alias void (%class.A*)* @_ZN1AD2Ev