diff options
author | Hans Wennborg <hans@hanshq.net> | 2014-07-17 20:25:23 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2014-07-17 20:25:23 +0000 |
commit | 56fc62bf01a8f2a9ff9590fa768b3e9ff7ad4c0b (patch) | |
tree | 94ac98dbb80b5a6523aa4afa15c241b006d0759f /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 42f79dbf02545fb36c78b07ccb89e61ab2f50e03 (diff) | |
download | bcm5719-llvm-56fc62bf01a8f2a9ff9590fa768b3e9ff7ad4c0b.tar.gz bcm5719-llvm-56fc62bf01a8f2a9ff9590fa768b3e9ff7ad4c0b.zip |
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
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 31 |
1 files changed, 4 insertions, 27 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 66ac524f2b9..6c33f922792 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<VarDecl>(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<VarDecl>(D); - if (getCXXABI().isInlineInitializedStaticDataMemberLinkOnce() && - VD && isVarDeclInlineInitializedStaticDataMember(VD)) { - if (VD->hasAttr<DLLImportAttr>()) - return llvm::GlobalValue::AvailableExternallyLinkage; - if (VD->hasAttr<DLLExportAttr>()) - return llvm::GlobalValue::WeakODRLinkage; - return llvm::GlobalValue::LinkOnceODRLinkage; - } - // C++ doesn't have tentative definitions and thus cannot have common // linkage. if (!getLangOpts().CPlusPlus && isa<VarDecl>(D) && |