[cfe-commits] r83235 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp test/CodeGen/const-init.c

Anders Carlsson andersca at mac.com
Thu Oct 1 21:52:12 PDT 2009


Author: andersca
Date: Thu Oct  1 23:52:12 2009
New Revision: 83235

URL: http://llvm.org/viewvc/llvm-project?rev=83235&view=rev
Log:
Don't update the struct alignment when adding fields to a packed struct. Fixes PR5118.

Modified:
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp
    cfe/trunk/test/CodeGen/const-init.c

Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=83235&r1=83234&r2=83235&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Thu Oct  1 23:52:12 2009
@@ -85,7 +85,12 @@
     // Add the field.
     Elements.push_back(C);
     NextFieldOffsetInBytes = AlignedNextFieldOffsetInBytes + getSizeInBytes(C);
-    LLVMStructAlignment = std::max(LLVMStructAlignment, FieldAlignment);
+    
+    if (Packed)
+      assert(LLVMStructAlignment == 1 && "Packed struct not byte-aligned!");
+    else
+      LLVMStructAlignment = std::max(LLVMStructAlignment, FieldAlignment);
+
     return true;
   }
 

Modified: cfe/trunk/test/CodeGen/const-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/const-init.c?rev=83235&r1=83234&r2=83235&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/const-init.c (original)
+++ cfe/trunk/test/CodeGen/const-init.c Thu Oct  1 23:52:12 2009
@@ -48,11 +48,18 @@
 int g10 = (2.0 + 3.0i) * (5.0 + 7.0i) != (-11.0 + 29.0i);
 
 // PR5108
-// CHECK: @ss = global %4 <{ i32 0, i8 7 }>, align 1
-struct s {
+// CHECK: @gv1 = global %4 <{ i32 0, i8 7 }>, align 1
+struct {
   unsigned long a;
   unsigned long b:3;
-} __attribute__((__packed__)) ss  = { .a = 0x0, .b = 7,  };
+} __attribute__((__packed__)) gv1  = { .a = 0x0, .b = 7,  };
+
+// PR5118
+// CHECK: @gv2 = global %5 <{ i8 1, i8* null }>, align 1 
+struct {
+  unsigned char a;
+  char *b;
+} __attribute__((__packed__)) gv2 = { 1, (void*)0 };
 
 // Global references
 // RUN: grep '@g11.l0 = internal global i32 ptrtoint (i32 ()\* @g11 to i32)' %t &&





More information about the cfe-commits mailing list