Only the first zero-length bitfield decides alignment of

the followup data member in an ms_struct struct.
// rdar:// 8823265

llvm-svn: 130795
This commit is contained in:
Fariborz Jahanian
2011-05-03 22:07:14 +00:00
parent 543596d57b
commit 759e4a1add
3 changed files with 52 additions and 3 deletions

View File

@@ -546,7 +546,8 @@ bool ASTContext::ZeroBitfieldFollowsNonBitfield(const FieldDecl *FD,
bool ASTContext::ZeroBitfieldFollowsBitfield(const FieldDecl *FD,
const FieldDecl *LastFD) const {
return (FD->isBitField() && LastFD && LastFD->isBitField() &&
FD->getBitWidth()-> EvaluateAsInt(*this).getZExtValue() == 0);
FD->getBitWidth()-> EvaluateAsInt(*this).getZExtValue() == 0 &&
LastFD->getBitWidth()-> EvaluateAsInt(*this).getZExtValue() != 0);
}

View File

@@ -1359,9 +1359,11 @@ void RecordLayoutBuilder::LayoutBitField(const FieldDecl *D) {
std::pair<uint64_t, unsigned> FieldInfo =
Context.getTypeInfo(ZeroLengthBitfield->getType());
unsigned ZeroLengthBitfieldAlignment = FieldInfo.second;
if (ZeroLengthBitfieldAlignment > FieldAlign)
// Ignore alignment of subsequent zero-length bitfields.
if ((ZeroLengthBitfieldAlignment > FieldAlign) || (FieldSize == 0))
FieldAlign = ZeroLengthBitfieldAlignment;
ZeroLengthBitfield = 0;
if (FieldSize)
ZeroLengthBitfield = 0;
}
}

View File

@@ -43,3 +43,49 @@ struct
} ATTR t5;
static int a5[(sizeof(t5) == 4) -1];
struct
{
char foo : 4;
short : 0;
long :0;
char bar;
} ATTR t6;
static int a6[(sizeof(t6) == 4) -1];
struct
{
char foo : 4;
long :0;
short : 0;
char bar;
} ATTR t7;
static int a7[(sizeof(t7) == 16) -1];
struct
{
char foo : 4;
short : 0;
long :0;
char bar:7;
} ATTR t8;
static int a8[(sizeof(t8) == 4) -1];
struct
{
char foo : 4;
long :0;
short : 0;
char bar: 8;
} ATTR t9;
static int a9[(sizeof(t9) == 16) -1];
struct
{
char foo : 4;
char : 0;
short : 0;
int : 0;
long :0;
char bar;
} ATTR t10;
static int a10[(sizeof(t10) == 2) -1];