From 56fc62bf01a8f2a9ff9590fa768b3e9ff7ad4c0b Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Thu, 17 Jul 2014 20:25:23 +0000 Subject: MS compatibility: always emit dllexported in-class initialized static data members (PR20140) This makes us emit dllexported in-class initialized static data members (which are treated as definitions in MSVC), even when they're not referenced. It also makes their special linkage reflected in the GVA linkage instead of getting massaged in CodeGen. Differential Revision: http://reviews.llvm.org/D4563 llvm-svn: 213304 --- clang/lib/CodeGen/CodeGenModule.cpp | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 66ac524..6c33f92 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1256,7 +1256,8 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) { const auto *VD = cast(Global); assert(VD->isFileVarDecl() && "Cannot emit local var decl as global."); - if (VD->isThisDeclarationADefinition() != VarDecl::Definition) + if (VD->isThisDeclarationADefinition() != VarDecl::Definition && + !Context.isMSStaticDataMemberInlineDefinition(VD)) return; } @@ -1592,18 +1593,6 @@ bool CodeGenModule::isTypeConstant(QualType Ty, bool ExcludeCtor) { return true; } -static bool isVarDeclInlineInitializedStaticDataMember(const VarDecl *VD) { - if (!VD->isStaticDataMember()) - return false; - const VarDecl *InitDecl; - const Expr *InitExpr = VD->getAnyInitializer(InitDecl); - if (!InitExpr) - return false; - if (InitDecl->isThisDeclarationADefinition()) - return false; - return true; -} - /// GetOrCreateLLVMGlobal - If the specified mangled name is not in the module, /// create and return an llvm GlobalVariable with the specified type. If there /// is something in the module with the specified name, return it potentially @@ -1666,9 +1655,9 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, // If required by the ABI, treat declarations of static data members with // inline initializers as definitions. - if (getCXXABI().isInlineInitializedStaticDataMemberLinkOnce() && - isVarDeclInlineInitializedStaticDataMember(D)) + if (getContext().isMSStaticDataMemberInlineDefinition(D)) { EmitGlobalVarDefinition(D); + } // Handle XCore specific ABI requirements. if (getTarget().getTriple().getArch() == llvm::Triple::xcore && @@ -2087,18 +2076,6 @@ llvm::GlobalValue::LinkageTypes CodeGenModule::getLLVMLinkageForDeclarator( return !Context.getLangOpts().AppleKext ? llvm::Function::WeakODRLinkage : llvm::Function::ExternalLinkage; - // If required by the ABI, give definitions of static data members with inline - // initializers at least linkonce_odr linkage. - auto const VD = dyn_cast(D); - if (getCXXABI().isInlineInitializedStaticDataMemberLinkOnce() && - VD && isVarDeclInlineInitializedStaticDataMember(VD)) { - if (VD->hasAttr()) - return llvm::GlobalValue::AvailableExternallyLinkage; - if (VD->hasAttr()) - return llvm::GlobalValue::WeakODRLinkage; - return llvm::GlobalValue::LinkOnceODRLinkage; - } - // C++ doesn't have tentative definitions and thus cannot have common // linkage. if (!getLangOpts().CPlusPlus && isa(D) && -- cgit v1.1