aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/TargetData.cpp
diff options
context:
space:
mode:
authorCameron Zwarich <zwarich@apple.com>2011-04-13 06:03:16 +0000
committerCameron Zwarich <zwarich@apple.com>2011-04-13 06:03:16 +0000
commitd8b88d8558e00ed1ca1a97d6b7a86ead757412fc (patch)
tree12d438945bf039246042d262144abd040d46387c /lib/Target/TargetData.cpp
parent8a7f4ecbc1eca4359f56e76f74f6211943eafd68 (diff)
If a global variable has a specified alignment that is less than the preferred
alignment for its type, use the minimum of the specified alignment and the ABI alignment. This fixes <rdar://problem/9275290>. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129428 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/TargetData.cpp')
-rw-r--r--lib/Target/TargetData.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp
index c628df04e7..d15855ce12 100644
--- a/lib/Target/TargetData.cpp
+++ b/lib/Target/TargetData.cpp
@@ -617,8 +617,12 @@ uint64_t TargetData::getIndexedOffset(const Type *ptrTy, Value* const* Indices,
unsigned TargetData::getPreferredAlignment(const GlobalVariable *GV) const {
const Type *ElemType = GV->getType()->getElementType();
unsigned Alignment = getPrefTypeAlignment(ElemType);
- if (GV->getAlignment() > Alignment)
- Alignment = GV->getAlignment();
+ unsigned GVAlignment = GV->getAlignment();
+ if (GVAlignment >= Alignment) {
+ Alignment = GVAlignment;
+ } else if (GVAlignment != 0) {
+ Alignment = std::min(GVAlignment, getABITypeAlignment(ElemType));
+ }
if (GV->hasInitializer()) {
if (Alignment < 16) {