From d8b88d8558e00ed1ca1a97d6b7a86ead757412fc Mon Sep 17 00:00:00 2001 From: Cameron Zwarich Date: Wed, 13 Apr 2011 06:03:16 +0000 Subject: [PATCH] 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 . git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129428 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/TargetData.cpp | 8 ++++++-- test/CodeGen/ARM/2011-04-12-AlignBug.ll | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/CodeGen/ARM/2011-04-12-AlignBug.ll diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp index c628df04e71..d15855ce126 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) { diff --git a/test/CodeGen/ARM/2011-04-12-AlignBug.ll b/test/CodeGen/ARM/2011-04-12-AlignBug.ll new file mode 100644 index 00000000000..c657b796255 --- /dev/null +++ b/test/CodeGen/ARM/2011-04-12-AlignBug.ll @@ -0,0 +1,9 @@ +; RUN: llc < %s | FileCheck %s +target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:32:64-v128:32:128-a0:0:32-n32" +target triple = "thumbv7-apple-darwin10.0.0" + +; CHECK: align 2 +@.strA = linker_private unnamed_addr constant [4 x i8] c"bar\00" +; CHECK-NOT: align +@.strB = linker_private unnamed_addr constant [4 x i8] c"foo\00", align 1 +@.strC = linker_private unnamed_addr constant [4 x i8] c"baz\00", section "__TEXT,__cstring,cstring_literals", align 1 -- 2.34.1