[CLANG][MS-STRUCT] bitfield padding warning presents padding to exact bit count (#136062)
Aims to fix #131647.
This commit is contained in:
parent
6d765e1c91
commit
3ca2fa704e
@ -1539,6 +1539,7 @@ void ItaniumRecordLayoutBuilder::LayoutBitField(const FieldDecl *D) {
|
|||||||
uint64_t StorageUnitSize = FieldInfo.Width;
|
uint64_t StorageUnitSize = FieldInfo.Width;
|
||||||
unsigned FieldAlign = FieldInfo.Align;
|
unsigned FieldAlign = FieldInfo.Align;
|
||||||
bool AlignIsRequired = FieldInfo.isAlignRequired();
|
bool AlignIsRequired = FieldInfo.isAlignRequired();
|
||||||
|
unsigned char PaddingInLastUnit = 0;
|
||||||
|
|
||||||
// UnfilledBitsInLastUnit is the difference between the end of the
|
// UnfilledBitsInLastUnit is the difference between the end of the
|
||||||
// last allocated bitfield (i.e. the first bit offset available for
|
// last allocated bitfield (i.e. the first bit offset available for
|
||||||
@ -1611,6 +1612,7 @@ void ItaniumRecordLayoutBuilder::LayoutBitField(const FieldDecl *D) {
|
|||||||
if (!LastBitfieldStorageUnitSize && !FieldSize)
|
if (!LastBitfieldStorageUnitSize && !FieldSize)
|
||||||
FieldAlign = 1;
|
FieldAlign = 1;
|
||||||
|
|
||||||
|
PaddingInLastUnit = UnfilledBitsInLastUnit;
|
||||||
UnfilledBitsInLastUnit = 0;
|
UnfilledBitsInLastUnit = 0;
|
||||||
LastBitfieldStorageUnitSize = 0;
|
LastBitfieldStorageUnitSize = 0;
|
||||||
}
|
}
|
||||||
@ -1707,7 +1709,7 @@ void ItaniumRecordLayoutBuilder::LayoutBitField(const FieldDecl *D) {
|
|||||||
// For purposes of diagnostics, we're going to simultaneously
|
// For purposes of diagnostics, we're going to simultaneously
|
||||||
// compute the field offsets that we would have used if we weren't
|
// compute the field offsets that we would have used if we weren't
|
||||||
// adding any alignment padding or if the field weren't packed.
|
// adding any alignment padding or if the field weren't packed.
|
||||||
uint64_t UnpaddedFieldOffset = FieldOffset;
|
uint64_t UnpaddedFieldOffset = FieldOffset - PaddingInLastUnit;
|
||||||
uint64_t UnpackedFieldOffset = FieldOffset;
|
uint64_t UnpackedFieldOffset = FieldOffset;
|
||||||
|
|
||||||
// Check if we need to add padding to fit the bitfield within an
|
// Check if we need to add padding to fit the bitfield within an
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// RUN: %clang_cc1 -triple x86_64-windows-msvc -fsyntax-only -verify -Wpadded %s
|
// RUN: %clang_cc1 -triple x86_64-windows-msvc -fsyntax-only -verify -Wpadded %s
|
||||||
|
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify -Wpadded %s
|
||||||
|
|
||||||
struct __attribute__((ms_struct)) BitfieldStruct { // expected-warning {{padding size of 'BitfieldStruct' with 3 bytes to alignment boundary}}
|
struct __attribute__((ms_struct)) BitfieldStruct { // expected-warning {{padding size of 'BitfieldStruct' with 3 bytes to alignment boundary}}
|
||||||
char c : 1;
|
char c : 1;
|
||||||
@ -24,9 +25,23 @@ struct __attribute__((ms_struct)) DifferentUnitSizeBitfield { // expected-warnin
|
|||||||
char i; // expected-warning {{padding struct 'DifferentUnitSizeBitfield' with 31 bits to align 'i'}}
|
char i; // expected-warning {{padding struct 'DifferentUnitSizeBitfield' with 31 bits to align 'i'}}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct __attribute__((ms_struct)) BitfieldBigPadding { // expected-warning {{padding size of 'BitfieldBigPadding' with 63 bits to alignment boundary}}
|
||||||
|
long long x;
|
||||||
|
char a : 1;
|
||||||
|
long long b : 1; // expected-warning {{padding struct 'BitfieldBigPadding' with 63 bits to align 'b'}}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct __attribute__((ms_struct)) SameUnitSizeMultiple { // expected-warning {{padding size of 'SameUnitSizeMultiple' with 2 bits to alignment boundary}}
|
||||||
|
char c : 1;
|
||||||
|
char cc : 2;
|
||||||
|
char ccc : 3;
|
||||||
|
};
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
BitfieldStruct b;
|
BitfieldStruct b;
|
||||||
SevenBitfieldStruct s;
|
SevenBitfieldStruct s;
|
||||||
SameUnitSizeBitfield su;
|
SameUnitSizeBitfield su;
|
||||||
DifferentUnitSizeBitfield du;
|
DifferentUnitSizeBitfield du;
|
||||||
|
BitfieldBigPadding bbp;
|
||||||
|
SameUnitSizeMultiple susm;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user