forked from OSchip/llvm-project
More rule enforcement of zero bitfields for ms_struct.
llvm-svn: 130696
This commit is contained in:
parent
d47ba853fc
commit
eb39741c0b
|
@ -402,6 +402,11 @@ public:
|
|||
bool ZeroBitfieldFollowsNonBitfield(const FieldDecl *FD,
|
||||
const FieldDecl *LastFD) const;
|
||||
|
||||
/// ZeroBitfieldFollowsBitfield - return 'true" if 'FD' is a zero-length
|
||||
/// bitfield which follows the bitfield 'LastFD'.
|
||||
bool ZeroBitfieldFollowsBitfield(const FieldDecl *FD,
|
||||
const FieldDecl *LastFD) const;
|
||||
|
||||
// Access to the set of methods overridden by the given C++ method.
|
||||
typedef CXXMethodVector::iterator overridden_cxx_method_iterator;
|
||||
overridden_cxx_method_iterator
|
||||
|
|
|
@ -543,6 +543,13 @@ 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);
|
||||
|
||||
}
|
||||
|
||||
ASTContext::overridden_cxx_method_iterator
|
||||
ASTContext::overridden_methods_begin(const CXXMethodDecl *Method) const {
|
||||
llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector>::const_iterator Pos
|
||||
|
|
|
@ -2059,7 +2059,8 @@ unsigned FieldDecl::getFieldIndex() const {
|
|||
|
||||
if (IsMsStruct) {
|
||||
// Zero-length bitfields following non-bitfield members are ignored.
|
||||
if (getASTContext().ZeroBitfieldFollowsNonBitfield((*i), LastFD)) {
|
||||
if (getASTContext().ZeroBitfieldFollowsNonBitfield((*i), LastFD) ||
|
||||
getASTContext().ZeroBitfieldFollowsBitfield((*i), LastFD)) {
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -582,6 +582,8 @@ protected:
|
|||
CharUnits NonVirtualSize;
|
||||
CharUnits NonVirtualAlignment;
|
||||
|
||||
CharUnits ZeroLengthBitfieldAlignment;
|
||||
|
||||
/// PrimaryBase - the primary base class (if one exists) of the class
|
||||
/// we're laying out.
|
||||
const CXXRecordDecl *PrimaryBase;
|
||||
|
@ -618,7 +620,8 @@ protected:
|
|||
IsMac68kAlign(false), IsMsStruct(false),
|
||||
UnfilledBitsInLastByte(0), MaxFieldAlignment(CharUnits::Zero()),
|
||||
DataSize(0), NonVirtualSize(CharUnits::Zero()),
|
||||
NonVirtualAlignment(CharUnits::One()), PrimaryBase(0),
|
||||
NonVirtualAlignment(CharUnits::One()),
|
||||
ZeroLengthBitfieldAlignment(CharUnits::Zero()), PrimaryBase(0),
|
||||
PrimaryBaseIsVirtual(false), FirstNearlyEmptyVBase(0) { }
|
||||
|
||||
void Layout(const RecordDecl *D);
|
||||
|
@ -1258,9 +1261,18 @@ void RecordLayoutBuilder::LayoutFields(const RecordDecl *D) {
|
|||
for (RecordDecl::field_iterator Field = D->field_begin(),
|
||||
FieldEnd = D->field_end(); Field != FieldEnd; ++Field) {
|
||||
if (IsMsStruct) {
|
||||
const FieldDecl *FD = (*Field);
|
||||
if (Context.ZeroBitfieldFollowsBitfield(FD, LastFD)) {
|
||||
// FIXME. Multiple zero bitfields may follow a bitfield.
|
||||
// set ZeroLengthBitfieldAlignment to max. of its
|
||||
// currrent and alignment of 'FD'.
|
||||
std::pair<CharUnits, CharUnits> FieldInfo =
|
||||
Context.getTypeInfoInChars(FD->getType());
|
||||
ZeroLengthBitfieldAlignment = FieldInfo.second;
|
||||
continue;
|
||||
}
|
||||
// Zero-length bitfields following non-bitfield members are
|
||||
// ignored:
|
||||
const FieldDecl *FD = (*Field);
|
||||
if (Context.ZeroBitfieldFollowsNonBitfield(FD, LastFD))
|
||||
continue;
|
||||
LastFD = FD;
|
||||
|
@ -1443,6 +1455,9 @@ void RecordLayoutBuilder::LayoutField(const FieldDecl *D) {
|
|||
Context.getTypeInfoInChars(D->getType());
|
||||
FieldSize = FieldInfo.first;
|
||||
FieldAlign = FieldInfo.second;
|
||||
if (ZeroLengthBitfieldAlignment > FieldAlign)
|
||||
FieldAlign = ZeroLengthBitfieldAlignment;
|
||||
ZeroLengthBitfieldAlignment = CharUnits::Zero();
|
||||
|
||||
if (Context.getLangOptions().MSBitfields) {
|
||||
// If MS bitfield layout is required, figure out what type is being
|
||||
|
|
|
@ -628,7 +628,8 @@ CollectRecordFields(const RecordDecl *record, llvm::DIFile tunit,
|
|||
FieldDecl *field = *I;
|
||||
if (IsMsStruct) {
|
||||
// Zero-length bitfields following non-bitfield members are ignored
|
||||
if (CGM.getContext().ZeroBitfieldFollowsNonBitfield((field), LastFD)) {
|
||||
if (CGM.getContext().ZeroBitfieldFollowsNonBitfield((field), LastFD) ||
|
||||
CGM.getContext().ZeroBitfieldFollowsBitfield((field), LastFD)) {
|
||||
--fieldNo;
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -352,7 +352,8 @@ bool ConstStructBuilder::Build(InitListExpr *ILE) {
|
|||
if (IsMsStruct) {
|
||||
// Zero-length bitfields following non-bitfield members are
|
||||
// ignored:
|
||||
if (CGM.getContext().ZeroBitfieldFollowsNonBitfield((*Field), LastFD)) {
|
||||
if (CGM.getContext().ZeroBitfieldFollowsNonBitfield((*Field), LastFD) ||
|
||||
CGM.getContext().ZeroBitfieldFollowsBitfield((*Field), LastFD)) {
|
||||
--FieldNo;
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -753,7 +753,8 @@ bool CGRecordLayoutBuilder::LayoutFields(const RecordDecl *D) {
|
|||
// Zero-length bitfields following non-bitfield members are
|
||||
// ignored:
|
||||
const FieldDecl *FD = (*Field);
|
||||
if (Types.getContext().ZeroBitfieldFollowsNonBitfield(FD, LastFD)) {
|
||||
if (Types.getContext().ZeroBitfieldFollowsNonBitfield(FD, LastFD) ||
|
||||
Types.getContext().ZeroBitfieldFollowsBitfield(FD, LastFD)) {
|
||||
--FieldNo;
|
||||
continue;
|
||||
}
|
||||
|
@ -996,7 +997,8 @@ CGRecordLayout *CodeGenTypes::ComputeRecordLayout(const RecordDecl *D) {
|
|||
if (IsMsStruct) {
|
||||
// Zero-length bitfields following non-bitfield members are
|
||||
// ignored:
|
||||
if (getContext().ZeroBitfieldFollowsNonBitfield(FD, LastFD)) {
|
||||
if (getContext().ZeroBitfieldFollowsNonBitfield(FD, LastFD) ||
|
||||
getContext().ZeroBitfieldFollowsBitfield(FD, LastFD)) {
|
||||
--i;
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -107,6 +107,13 @@ struct
|
|||
char :4;
|
||||
} ATTR t9;
|
||||
|
||||
struct
|
||||
{
|
||||
char foo: 8;
|
||||
long : 0;
|
||||
char bar;
|
||||
} ATTR t10;
|
||||
|
||||
static int arr1[(sizeof(t1) == 2) -1];
|
||||
static int arr2[(sizeof(t2) == 2) -1];
|
||||
static int arr3[(sizeof(t3) == 2) -1];
|
||||
|
@ -116,6 +123,7 @@ static int arr6[(sizeof(t6) == 1) -1];
|
|||
static int arr7[(sizeof(t7) == 9) -1];
|
||||
static int arr8[(sizeof(t8) == 0) -1];
|
||||
static int arr9[(sizeof(t9) == 28) -1];
|
||||
static int arr10[(sizeof(t10) == 16) -1];
|
||||
|
||||
int main() {
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue