diff options
author | Yaxun Liu <Yaxun.Liu@amd.com> | 2016-12-15 08:09:08 +0000 |
---|---|---|
committer | Yaxun Liu <Yaxun.Liu@amd.com> | 2016-12-15 08:09:08 +0000 |
commit | 402804b6d67c880c97e575342189025fe28c0f81 (patch) | |
tree | f05c793f67afb7f12b82a43b0926afd04c0ae4ec /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 61ef150d53e4a9a3f14f614991f8132a5bb4eedc (diff) | |
download | bcm5719-llvm-402804b6d67c880c97e575342189025fe28c0f81.tar.gz bcm5719-llvm-402804b6d67c880c97e575342189025fe28c0f81.zip |
Re-commit r289252 and r289285, and fix PR31374
llvm-svn: 289787
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 404cbae1d83..64c2bd673cc 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2663,9 +2663,16 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D, else GV->setDLLStorageClass(llvm::GlobalVariable::DefaultStorageClass); - if (Linkage == llvm::GlobalVariable::CommonLinkage) + if (Linkage == llvm::GlobalVariable::CommonLinkage) { // common vars aren't constant even if declared const. GV->setConstant(false); + // Tentative definition of global variables may be initialized with + // non-zero null pointers. In this case they should have weak linkage + // since common linkage must have zero initializer and must not have + // explicit section therefore cannot have non-zero initial value. + if (!GV->getInitializer()->isNullValue()) + GV->setLinkage(llvm::GlobalVariable::WeakAnyLinkage); + } setNonAliasAttributes(D, GV); |