Change the condition of this unnecessary packed warning. The packed is unnecessary when
- the alignment of the struct/class won't alter.
- the size is unchanged.
- the offset of each field is the same.
Remove all field-level warning.
Differential D34114
[clang] Change the condition of unnecessary packed warning yawanng on Jun 12 2017, 12:24 PM. Authored by
Details Change the condition of this unnecessary packed warning. The packed is unnecessary when
Remove all field-level warning.
Diff Detail Event TimelineComment Actions Richard, can you take a look at this, or suggest someone who would be a good reviewer for this improved diagnostic? Thanks. Comment Actions Some concrete suggestions throughout the patch, but I think we should take a step back and reconsider this warning approach: it seems bizarre for us to warn on any packed struct that happens to contain a char. It would make sense to warn if an __attribute__((packed)) written in the source has *no* effect (because it's applied to a struct where all fields already have alignment 1, or because it's applied to a field that has alignment 1) -- even then I'm not entirely convinced this is a valuable warning, but I assume there's some reason you want to warn on it :)
Comment Actions Richard's points are really valid here. I missed the aspect that packed always implies alignment 1, which does have an effect on the code in most of the cases listed here. I agree that the value of this warning is low, since the possibility of false-positive is quite high. Would this make for a better clang-tidy check instead (although only for cases where there is no padding and/or cases where the struct is also declared to have a stricter alignment guarantee)?
Comment Actions These warnings are triggered by -Wpadded -Wpacked I found it too tedious to suppress one warning per struct field, One alternative for users is to ignore these checks or warnings I am not against removing these warnings completely. Comment Actions Change the condition of this unnecessary packed warning to when the alignment of the class is one byte. Remove all field-level warning. Comment Actions Yes. I think the only case for this warning to be useful is when the alignment of the class or struct is 1 byte :-)
Comment Actions Including cases 'attribute((packed, aligned(X)));'. When the alignment before packing is less or equal to the packed one, he 'packed' attribute not including 'aligned(X)' seems unnecessary. Because the alignment won't change as well as the size after removing 'packed'.
|
s/IsFieldOffsetChangedWithPacked/HasPackedField/