From 0334832bd5fc9c6bb7db848b0df92a796cce45a5 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sun, 19 Oct 2014 19:41:46 +0000 Subject: [PATCH] Revert r220153: "CodeGen: ConstStructBuilder must verify packed constraints after padding" This commit caused two tests in LNT to regress. I'm able to reproduce on any platform and will send reproduction steps to the original commit log. This should restore the LNT bots that have been failing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220169 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprConstant.cpp | 19 +++++++++---------- test/CodeGen/const-init.c | 11 ----------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index dd87dd4657..421e7deccc 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -106,6 +106,15 @@ AppendBytes(CharUnits FieldOffsetInChars, llvm::Constant *InitCst) { CharUnits AlignedNextFieldOffsetInChars = NextFieldOffsetInChars.RoundUpToAlignment(FieldAlignment); + if (AlignedNextFieldOffsetInChars > FieldOffsetInChars) { + assert(!Packed && "Alignment is wrong even with a packed struct!"); + + // Convert the struct to a packed struct. + ConvertStructToPacked(); + + AlignedNextFieldOffsetInChars = NextFieldOffsetInChars; + } + if (AlignedNextFieldOffsetInChars < FieldOffsetInChars) { // We need to append padding. AppendPadding(FieldOffsetInChars - NextFieldOffsetInChars); @@ -113,16 +122,6 @@ AppendBytes(CharUnits FieldOffsetInChars, llvm::Constant *InitCst) { assert(NextFieldOffsetInChars == FieldOffsetInChars && "Did not add enough padding!"); - AlignedNextFieldOffsetInChars = - NextFieldOffsetInChars.RoundUpToAlignment(FieldAlignment); - } - - if (AlignedNextFieldOffsetInChars > FieldOffsetInChars) { - assert(!Packed && "Alignment is wrong even with a packed struct!"); - - // Convert the struct to a packed struct. - ConvertStructToPacked(); - AlignedNextFieldOffsetInChars = NextFieldOffsetInChars; } diff --git a/test/CodeGen/const-init.c b/test/CodeGen/const-init.c index ccc6604c45..7d7ccae370 100644 --- a/test/CodeGen/const-init.c +++ b/test/CodeGen/const-init.c @@ -159,14 +159,3 @@ void g29() { static int b[1] = { "asdf" }; // expected-warning {{incompatible pointer to integer conversion initializing 'int' with an expression of type 'char [5]'}} static int c[1] = { L"a" }; } - -// PR21300 -void g30() { -#pragma pack(1) - static struct { - int : 1; - int x; - } a = {}; - // CHECK: @g30.a = internal global %struct.anon.1 <{ i8 undef, i32 0 }>, align 1 -#pragma pack() -} -- 2.50.1