This is an archive of the discontinued LLVM Phabricator instance.

[clang-format][PR45816] Add AlignConsecutiveBitFields
ClosedPublic

Authored by JakeMerdichAMD on May 18 2020, 9:07 PM.

Details

Summary

The following revision follows D80115 since @MyDeveloperDay and I apparently both had the same idea at the same time, for https://bugs.llvm.org/show_bug.cgi?id=45816 and my efforts on tooling support for AMDVLK, respectively.

This option aligns adjacent bitfield separators across lines, in a manner similar to AlignConsecutiveAssignments and friends.

Example:

struct RawFloat {
  uint32_t sign : 1;
  uint32_t exponent : 8;
  uint32_t mantissa : 23;
};

would become

struct RawFloat {
  uint32_t sign     : 1;
  uint32_t exponent : 8;
  uint32_t mantissa : 23;
};

This also handles c++2a style bitfield-initializers with AlignConsecutiveAssignments.

struct RawFloat {
  uint32_t sign     : 1  = 0;
  uint32_t exponent : 8  = 127;
  uint32_t mantissa : 23 = 0;
}; // defaults to 1.0f

Things this change does not do:

  • Align multiple comma-chained bitfield variables. None of the other AlignConsecutive* options seem to implement that either.
  • Detect bitfields that have a width specified with something other than a numeric literal (ie, int a : SOME_MACRO;). That'd be fairly difficult to parse and is rare.

Diff Detail

Event Timeline

JakeMerdichAMD created this revision.May 18 2020, 9:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 18 2020, 9:07 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
JakeMerdichAMD edited the summary of this revision. (Show Details)May 18 2020, 9:12 PM
JakeMerdichAMD edited the summary of this revision. (Show Details)
MyDeveloperDay accepted this revision.May 19 2020, 12:43 AM

The LGTM (nit: clang-format)

This revision is now accepted and ready to land.May 19 2020, 12:43 AM

Reformat with a newer clang-format

Can I get your assistance committing this?

This revision was automatically updated to reflect the committed changes.