This CL is for discussion how to better fix bit-filed layout compatibility issue with GCC (see PR25575 for test case and more details). Current clang behavior is compatible with GCC 4.1-4.3 series but it was fixed in 4.4+. Ignoring packed attribute looks very odd and because it was also fixed in GCC 4.4+, it makes sense also fix it in clang.
Open questions:
- Should we add warning about changes in layout for packed bit-fileds of char type? GCC has it "note: offset of packed bit-field ‘b’ has changed in GCC 4.4" will add if needed.
- This CL completely removes warning "packed attribute ignored for field of type char". Should we keep it but apply only to normal fields (i.e. not bit-fields)?
This CL removes the warning because IMHO it makes no sense if we fix bit-field case to match GCC 4.4+. Packed attribute was actually ignored only for bit-field. For all other cases it is not ignored but reported only when alignment is already fulfilled (i.e. attribute just is not required and doesn't change anything). But there are tons of cases when packed attribute doesn't change anything but warning is not emitted, for example:
struct S1 {
char a; char b __attribute((packed)); // warning: 'packed' attribute ignored for field of type 'char' char c;
};
extern int a[sizeof(struct S1) == 3 ? 1 : -1];
extern int b[__alignof(struct S1) == 1 ? 1 : -1];
struct S2 {
short a; short b __attribute((packed)); // no warning short c;
};
extern int c[sizeof(struct S2) == 6 ? 1 : -1];
extern int d[__alignof(struct S2) == 2 ? 1 : -1];
In both cases you can remove __attribute((packed)) and program behavior will not change. But warning is generated only in the first case.