With xlc and xlC pragma align(packed) will pack bitfields the same way as pragma align(bit_packed). xlclang, xlclang++ and clang will pack bitfields the same way as pragma pack(1). Issue a warning when source code using pragma align(packed) to alert the user it may not be compatible with xlc/xlC.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/lib/Sema/SemaAttr.cpp | ||
---|---|---|
238 | Does this diagnostic need to be emitted for any struct or only structs that contain bitfield members? As it is it will be very verbose. |
Only emit diagnostic on bitfield members, which is the only difference in align(packed) behaviour XL and clang/xlclang.
Good point Chris. The only difference in layout is related to bitfield members, so I have moved the warning to VerifyBitField as suggested.
It would be nice if the diagnostic could be deferred to layout, in case the struct is defined but not used in a header, but I understand that #pragma pack(1) and #pragma align(packed) become ambiguous at the point of layout. I think this is a reasonable diagnostic given the impact of silently incompatible codegen.
clang/test/Sema/aix-pragma-align-packed-warn.c | ||
---|---|---|
14 | It's undesirable to warn for each bitfield member. Perhaps diagnose this in Sema::ActOnTagFinishDefinition? |
clang/test/Sema/aix-pragma-align-packed-warn.c | ||
---|---|---|
14 | Thanks for the suggestion Chris, I've moved it as suggested. |
Add a couple more struct layouts to the testing to show cases diagnostic is not issued.
Does this diagnostic need to be emitted for any struct or only structs that contain bitfield members? As it is it will be very verbose.