diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-07-02 01:32:16 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-07-02 01:32:16 +0000 |
commit | d9b9009c611a03b47b40f780de5562b141810682 (patch) | |
tree | 8b850ec1d6b4ca2c214a840077cd0b9827d0c880 /clang/lib/CodeGen | |
parent | 27cdf401eaa84e0d4ae82d174ddba6453e882856 (diff) | |
download | bcm5719-llvm-d9b9009c611a03b47b40f780de5562b141810682.tar.gz bcm5719-llvm-d9b9009c611a03b47b40f780de5562b141810682.zip |
PR28394: For compatibility with c++11 and c++14, if a static constexpr data
member is redundantly redeclared outside the class definition in code built in
c++17 mode, ensure we emit a non-discardable definition of the data member for
c++11 and c++14 compilations to use.
llvm-svn: 274416
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index fb1763551a3..c6e20a5f9c7 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1447,6 +1447,12 @@ bool CodeGenModule::MayBeEmittedEagerly(const ValueDecl *Global) { // Implicit template instantiations may change linkage if they are later // explicitly instantiated, so they should not be emitted eagerly. return false; + if (const auto *VD = dyn_cast<VarDecl>(Global)) + if (Context.getInlineVariableDefinitionKind(VD) == + ASTContext::InlineVariableDefinitionKind::WeakUnknown) + // A definition of an inline constexpr static data member may change + // linkage later if it's redeclared outside the class. + return false; // If OpenMP is enabled and threadprivates must be generated like TLS, delay // codegen for global variables, because they may be marked as threadprivate. if (LangOpts.OpenMP && LangOpts.OpenMPUseTLS && @@ -1595,8 +1601,14 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) { VD->hasAttr<CUDADeviceAttr>()); if (!MustEmitForCuda && VD->isThisDeclarationADefinition() != VarDecl::Definition && - !Context.isMSStaticDataMemberInlineDefinition(VD)) + !Context.isMSStaticDataMemberInlineDefinition(VD)) { + // If this declaration may have caused an inline variable definition to + // change linkage, make sure that it's emitted. + if (Context.getInlineVariableDefinitionKind(VD) == + ASTContext::InlineVariableDefinitionKind::Strong) + GetAddrOfGlobalVar(VD); return; + } } // Defer code generation to first use when possible, e.g. if this is an inline |