]> granicus.if.org Git - clang/commitdiff
Don't update the struct alignment when adding fields to a packed struct. Fixes PR5118.
authorAnders Carlsson <andersca@mac.com>
Fri, 2 Oct 2009 04:52:12 +0000 (04:52 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 2 Oct 2009 04:52:12 +0000 (04:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83235 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprConstant.cpp
test/CodeGen/const-init.c

index fae0e369a972dc1e34d59e0b0c587f11c86434a8..c67b41f4e2dddf5bcfe62d2a571d9b273bf009f5 100644 (file)
@@ -85,7 +85,12 @@ class VISIBILITY_HIDDEN ConstStructBuilder {
     // 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;
   }
 
index 13bfcd9cdf3be520a6510a31422105f19b56039d..296a01d8a4b630f6bdd5f60454744f532b1fdc5e 100644 (file)
@@ -48,11 +48,18 @@ int g9 = (2 + 3i) * (5 + 7i) != (-11 + 29i);
 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 {
+// 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 &&