From a49d5469df472d80c9cc17394c71fa8244e6a759 Mon Sep 17 00:00:00 2001
From: dim <dim@FreeBSD.org>
Date: Sat, 16 Jan 2016 18:00:58 +0000
Subject: Pull in r257902 from upstream llvm trunk, by James Y Knight (this
 will be merged to the official release_38 branch soon, but we need it ASAP):

  Stop increasing alignment of externally-visible globals on ELF
  platforms.

  With ELF, the alignment of a global variable in a shared library will
  get copied into an executables linked against it, if the executable even
  accesss the variable. So, it's not possible to implicitly increase
  alignment based on access patterns, or you'll break existing binaries.

  This happened to affect libc++'s std::cout symbol, for example. See
  thread: http://thread.gmane.org/gmane.comp.compilers.clang.devel/45311

  (This is a re-commit of r257719, without the bug reported in
  PR26144. I've tweaked the code to not assert-fail in
  enforceKnownAlignment when computeKnownBits doesn't recurse far enough
  to find the underlying Alloca/GlobalObject value.)

  Differential Revision: http://reviews.llvm.org/D16145
---
 contrib/llvm/lib/CodeGen/CodeGenPrepare.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'contrib/llvm/lib/CodeGen')

diff --git a/contrib/llvm/lib/CodeGen/CodeGenPrepare.cpp b/contrib/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 03e5778..fd4ee46 100644
--- a/contrib/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/contrib/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -1742,8 +1742,8 @@ bool CodeGenPrepare::optimizeCallInst(CallInst *CI, bool& ModifiedDT) {
       // over-aligning global variables that have an explicit section is
       // forbidden.
       GlobalVariable *GV;
-      if ((GV = dyn_cast<GlobalVariable>(Val)) && GV->hasUniqueInitializer() &&
-          !GV->hasSection() && GV->getAlignment() < PrefAlign &&
+      if ((GV = dyn_cast<GlobalVariable>(Val)) && GV->canIncreaseAlignment() &&
+          GV->getAlignment() < PrefAlign &&
           DL->getTypeAllocSize(GV->getType()->getElementType()) >=
               MinSize + Offset2)
         GV->setAlignment(PrefAlign);
-- 
cgit v1.1