This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC][AIX] Warn when using pragma align(packed) on AIX.
ClosedPublic

Authored by sfertile on Aug 4 2021, 3:10 PM.

Details

Summary

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.

Diff Detail

Event Timeline

sfertile created this revision.Aug 4 2021, 3:10 PM
sfertile requested review of this revision.Aug 4 2021, 3:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2021, 3:10 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
cebowleratibm added inline comments.Aug 5 2021, 10:22 AM
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.

sfertile updated this revision to Diff 364570.Aug 5 2021, 12:10 PM

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.

cebowleratibm accepted this revision.Aug 5 2021, 2:22 PM

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.

This revision is now accepted and ready to land.Aug 5 2021, 2:22 PM
cebowleratibm added inline comments.Aug 5 2021, 7:38 PM
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?

sfertile updated this revision to Diff 364782.Aug 6 2021, 6:43 AM

Moved the diagnostic emission to Sema::ActOnTagFinishDefinition as suggested.

Moved the diagnostic emission to Sema::ActOnTagFinishDefinition as suggested.

Sorry, uploaded wrong diff. Will updated again shortly.

sfertile updated this revision to Diff 364814.Aug 6 2021, 9:06 AM

Fixed diagnostic to only emit when there is a bitfield member.

sfertile marked an inline comment as done.Aug 6 2021, 9:07 AM
sfertile added inline comments.
clang/test/Sema/aix-pragma-align-packed-warn.c
14

Thanks for the suggestion Chris, I've moved it as suggested.

sfertile updated this revision to Diff 364996.Aug 7 2021, 5:51 PM
sfertile marked an inline comment as done.

Add a couple more struct layouts to the testing to show cases diagnostic is not issued.

cebowleratibm accepted this revision.Aug 9 2021, 5:58 AM

The new version is better than the previous. LGTM.