diff options
author | David Majnemer <david.majnemer@gmail.com> | 2015-02-19 19:25:17 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2015-02-19 19:25:17 +0000 |
commit | c9a9c7a67344fc50c80cfc2cd78f4b1666a7483f (patch) | |
tree | d0b2e2ff6fd6e298eca104991e58c8f7495d5585 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 57ac766ee995d717dc032ba35c9100bc7aa77652 (diff) | |
download | llvm-c9a9c7a67344fc50c80cfc2cd78f4b1666a7483f.zip llvm-c9a9c7a67344fc50c80cfc2cd78f4b1666a7483f.tar.gz llvm-c9a9c7a67344fc50c80cfc2cd78f4b1666a7483f.tar.bz2 |
CodeGen: static constexpr data members should have a linkonce_odr init
Classes can be defined in multiple translation units. This means that
the static constexpr data members should have identical initializers in
all translation units. Implement this by giving the reference temporary
linkonce_odr linkage.
llvm-svn: 229900
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 76ef789..e3c5a2b 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3082,10 +3082,19 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalTemporary( // Create a global variable for this lifetime-extended temporary. llvm::GlobalValue::LinkageTypes Linkage = getLLVMLinkageVarDefinition(VD, Constant); - // There is no need for this temporary to have global linkage if the global - // variable has external linkage. - if (Linkage == llvm::GlobalVariable::ExternalLinkage) - Linkage = llvm::GlobalVariable::PrivateLinkage; + if (Linkage == llvm::GlobalVariable::ExternalLinkage) { + const VarDecl *InitVD; + if (VD->isStaticDataMember() && VD->getAnyInitializer(InitVD) && + isa<CXXRecordDecl>(InitVD->getLexicalDeclContext())) { + // Temporaries defined inside a class get linkonce_odr linkage because the + // class can be defined in multipe translation units. + Linkage = llvm::GlobalVariable::LinkOnceODRLinkage; + } else { + // There is no need for this temporary to have external linkage if the + // VarDecl has external linkage. + Linkage = llvm::GlobalVariable::InternalLinkage; + } + } unsigned AddrSpace = GetGlobalVarAddressSpace( VD, getContext().getTargetAddressSpace(MaterializedType)); auto *GV = new llvm::GlobalVariable( |