[cfe-commits] r130795 - in /cfe/trunk: lib/AST/ASTContext.cpp lib/AST/RecordLayoutBuilder.cpp test/CodeGen/ms_struct-bitfield-1.c
Fariborz Jahanian
fjahanian at apple.com
Tue May 3 15:07:14 PDT 2011
Author: fjahanian
Date: Tue May 3 17:07:14 2011
New Revision: 130795
URL: http://llvm.org/viewvc/llvm-project?rev=130795&view=rev
Log:
Only the first zero-length bitfield decides alignment of
the followup data member in an ms_struct struct.
// rdar:// 8823265
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
cfe/trunk/test/CodeGen/ms_struct-bitfield-1.c
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=130795&r1=130794&r2=130795&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue May 3 17:07:14 2011
@@ -546,7 +546,8 @@
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);
}
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=130795&r1=130794&r2=130795&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Tue May 3 17:07:14 2011
@@ -1359,9 +1359,11 @@
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;
}
}
Modified: cfe/trunk/test/CodeGen/ms_struct-bitfield-1.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms_struct-bitfield-1.c?rev=130795&r1=130794&r2=130795&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/ms_struct-bitfield-1.c (original)
+++ cfe/trunk/test/CodeGen/ms_struct-bitfield-1.c Tue May 3 17:07:14 2011
@@ -43,3 +43,49 @@
} 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];
More information about the cfe-commits
mailing list