r187897 - Correctly allign arrays on 32 bit systems.

Rafael Espindola rafael.espindola at gmail.com
Wed Aug 7 11:08:20 PDT 2013


Author: rafael
Date: Wed Aug  7 13:08:19 2013
New Revision: 187897

URL: http://llvm.org/viewvc/llvm-project?rev=187897&view=rev
Log:
Correctly allign arrays on 32 bit systems.

Before this patch we would align

long long int big[1024];

to 4 bytes on 32 bit systems. The problem is that we were only looking
at the element type when getLargeArrayMinWidth returned non zero.

Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/test/CodeGen/alignment.c

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=187897&r1=187896&r2=187897&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Aug  7 13:08:19 2013
@@ -1286,13 +1286,14 @@ CharUnits ASTContext::getDeclAlign(const
       // Adjust alignments of declarations with array type by the
       // large-array alignment on the target.
       unsigned MinWidth = Target->getLargeArrayMinWidth();
-      const ArrayType *arrayType;
-      if (MinWidth && (arrayType = getAsArrayType(T))) {
-        if (isa<VariableArrayType>(arrayType))
-          Align = std::max(Align, Target->getLargeArrayAlign());
-        else if (isa<ConstantArrayType>(arrayType) &&
-                 MinWidth <= getTypeSize(cast<ConstantArrayType>(arrayType)))
-          Align = std::max(Align, Target->getLargeArrayAlign());
+      if (const ArrayType *arrayType = getAsArrayType(T)) {
+        if (MinWidth) {
+          if (isa<VariableArrayType>(arrayType))
+            Align = std::max(Align, Target->getLargeArrayAlign());
+          else if (isa<ConstantArrayType>(arrayType) &&
+                   MinWidth <= getTypeSize(cast<ConstantArrayType>(arrayType)))
+            Align = std::max(Align, Target->getLargeArrayAlign());
+        }
 
         // Walk through any array types while we're at it.
         T = getBaseElementType(arrayType);

Modified: cfe/trunk/test/CodeGen/alignment.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/alignment.c?rev=187897&r1=187896&r2=187897&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/alignment.c (original)
+++ cfe/trunk/test/CodeGen/alignment.c Wed Aug  7 13:08:19 2013
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s
 
 __attribute((aligned(16))) float a[128];
 union {int a[4]; __attribute((aligned(16))) float b[4];} b;
@@ -6,7 +6,8 @@ union {int a[4]; __attribute((aligned(16
 // CHECK: @a = {{.*}}zeroinitializer, align 16
 // CHECK: @b = {{.*}}zeroinitializer, align 16
 
-
+long long int test5[1024];
+// CHECK-DAG: @test5 = common global [1024 x i64] zeroinitializer, align 8
 
 // PR5279 - Reduced alignment on typedef.
 typedef int myint __attribute__((aligned(1)));





More information about the cfe-commits mailing list