This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC][AIX] Packed zero-width bitfields do not affect alignment.
ClosedPublic

Authored by sfertile on Jul 27 2021, 11:25 AM.

Details

Summary

Zero-width bitfields on AIX pad out to the natral alignment boundary but do not change the containing records alignment when they are packed.

Diff Detail

Event Timeline

sfertile created this revision.Jul 27 2021, 11:25 AM
sfertile requested review of this revision.Jul 27 2021, 11:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 27 2021, 11:25 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
sfertile updated this revision to Diff 362365.Jul 28 2021, 6:53 AM

clang-formatted

stevewan accepted this revision.Jul 29 2021, 6:26 PM

LGTM with some nits.

clang/lib/AST/RecordLayoutBuilder.cpp
1781

Just noting that the comment says MaxFieldAlignment - The maximum allowed field alignment. This is set by #pragma pack, but __attribute__(packed) also seems to set it to some large value that is at least as large as the FieldAlign. Maybe edit the comment accordingly for now, and a future follow-on patch if necessary.

clang/test/Layout/aix-packed-bitfields.c
95

nit: might be helpful to use a different type for the zero-width bitfield here. (e.g., long long : 0

This revision is now accepted and ready to land.Jul 29 2021, 6:26 PM
ZarkoCA accepted this revision.Jul 29 2021, 6:35 PM

LGTM also. Just a comment typo.

clang/lib/AST/RecordLayoutBuilder.cpp
1779
1779
sfertile added inline comments.Jul 30 2021, 7:06 AM
clang/lib/AST/RecordLayoutBuilder.cpp
1781

Sorry Steven, not sure what you are asking for.

attribute packed will set 'FieldPacked` to true, in which case we ignore the max field alignment (and why the new comment says, or 1 if packed). IIUC the MaXFieldAlign is set by only by pragma pack and pragma align in the Itanium recored layout builder, and the place where it is set based on attribute packed is int he Microsoft record layout builder and doesn't affect us here.

sfertile updated this revision to Diff 363147.Jul 30 2021, 10:44 AM

Fixed spelling and added a 'long long' zero width bitfield to the testing.

stevewan added inline comments.Jul 30 2021, 11:01 AM
clang/lib/AST/RecordLayoutBuilder.cpp
1781

Sorry Sean, my previous comment was indeed confusing. The old buggy behaviour confused me, and for some reason I thought the code must had went down this if statement when attribute packed is set, hence the previous comment. Now that I take a second look, I realize the problem was actually that we never went into the if to fix the FieldAlign. Sorry for the churn.

stevewan added inline comments.Jul 30 2021, 12:46 PM
clang/lib/AST/RecordLayoutBuilder.cpp
1783

UnpackedFieldAlign is used to check if the packed attribute is unnecessary (-Wpacked). here the attribute is making a difference, we probably shouldn't set FieldAlign = UnpackedFieldAlign?

sfertile updated this revision to Diff 364097.Aug 4 2021, 7:25 AM

Don't update the unpacked field align based on IsPacked.

sfertile marked 2 inline comments as done.Aug 4 2021, 7:25 AM
sfertile added inline comments.
clang/lib/AST/RecordLayoutBuilder.cpp
1783

Good catch, updated.

stevewan accepted this revision.Aug 4 2021, 7:50 AM

LGTM. Thanks.

This revision was landed with ongoing or failed builds.Aug 4 2021, 8:04 AM
This revision was automatically updated to reflect the committed changes.
sfertile marked an inline comment as done.