]> granicus.if.org Git - clang/commitdiff
fix a bogus assertion exposed by a recent change: packing the
authorChris Lattner <sabre@nondot.org>
Fri, 16 Apr 2010 21:02:32 +0000 (21:02 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 16 Apr 2010 21:02:32 +0000 (21:02 +0000)
struct may cause it to shrink more than one byte.  Before
my recent changes we compiled the new test into:

%0 = type { [6 x i8] }
@x = global %0 { [6 x i8] undef }, align 2        ; <%0*> [#uses=0]

which is obviously bogus.  Now we compile it into:

%0 = type <{ i32, i8, i8 }>
@x = global %0 zeroinitializer, align 2           ; <%0*> [#uses=0]

Where the last byte only is tail padding.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101536 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprConstant.cpp
test/CodeGen/decl.c

index 52e7d045e609c5177be04cd2fc23b25ce160bd6a..82156f7260297cb0c7b314d0df00fe00e1397be2 100644 (file)
@@ -372,7 +372,7 @@ bool ConstStructBuilder::Build(InitListExpr *ILE) {
     assert(!Packed && "Size mismatch!");
     
     ConvertStructToPacked();
-    assert(NextFieldOffsetInBytes == LayoutSizeInBytes &&
+    assert(NextFieldOffsetInBytes <= LayoutSizeInBytes &&
            "Converting to packed did not help!");
   }
 
index 8bbeb24fe1584a6a8edda7c97e1d9d9de1ceda6a..7ffb7006b05b1af30bb6f9be58644a53c248c005 100644 (file)
@@ -84,3 +84,8 @@ struct test7s { int a; int b; } test7[] = {
   {4},
 };
 
+// rdar://7872531
+#pragma pack(push, 2)
+struct test8s { int f0; char f1; } test8g = {};
+
+