Page MenuHomeFreeBSD

clang-format: Minor tweaks
ClosedPublic

Authored by markj on Apr 20 2021, 4:27 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Dec 22, 9:18 PM
Unknown Object (File)
Thu, Dec 5, 9:11 PM
Unknown Object (File)
Thu, Dec 5, 9:10 PM
Unknown Object (File)
Thu, Dec 5, 9:10 PM
Unknown Object (File)
Thu, Dec 5, 11:40 AM
Unknown Object (File)
Sun, Dec 1, 2:14 PM
Unknown Object (File)
Nov 16 2024, 7:58 AM
Unknown Object (File)
Nov 6 2024, 1:36 PM
Subscribers

Details

Summary

Invert KeepEmptyLinesAtTheStartOfBlocks. We used to require an empty
line at the beginning of functions with no local variables, which I
believe is the reason for this setting. Now it is discouraged in new
code.

Tell clang-format to align consecutive macros, since we tend to do that.
clang-format's output isn't quite what we want here. Typically we have
a tab after a #define for some reason, and clang-format doesn't appear
to have an option for that. clang-format will also use a mix of tabs
and spaces to minimize indentation, which is also against our
convention. However, the result looks better with this setting than
without.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj requested review of this revision.Apr 20 2021, 4:27 PM
.clang-format
5

Hrm, this setting only works with LLVM 12 and up. I guess it should be commented out for now.

  • Disable AlignConsecutiveMacros with a comment.
  • Make sure clang-format doesn't insert a space after FOREACH macros.

Now it is discouraged in new code.

We certainly don't require it now, but I'm not sure we went as far as discouraging it (although IMO we should).

Now it is discouraged in new code.

We certainly don't require it now, but I'm not sure we went as far as discouraging it (although IMO we should).

That's true. Now style(9) makes no mention of it, so I'm still fairly sure clang-format shouldn't bother preserving it. Outside of that case, we shouldn't have newlines at the start of blocks anyway.

Now it is discouraged in new code.

We certainly don't require it now, but I'm not sure we went as far as discouraging it (although IMO we should).

That's true. Now style(9) makes no mention of it, so I'm still fairly sure clang-format shouldn't bother preserving it. Outside of that case, we shouldn't have newlines at the start of blocks anyway.

I think we've stopped requiring it and the vast majority of new code where it matters choses the new style.

LLVM 12 adds another option that we should enable for consistency:

# We use "void * const *x" and not "void *const *x"
# Note: requires clang-format 12
SpaceAroundPointerQualifiers: Before

I added this setting upstream (https://reviews.llvm.org/D88227) since I got frustrated by clang-format breaking my CheriBSD diffs (we hit this quite a lot with the __capability qualifier in our kernel sources).

.clang-format
5

12 is in base, so this can be enabled now.

Updated D26340 with this applied and it looks good

Updated D26340 with this applied and it looks good

So should I commit this? I haven't tried to use clang-format in a long time.

emaste added inline comments.
.clang-format
6

Can be uncommented now

This revision is now accepted and ready to land.Apr 30 2024, 2:02 PM
This revision was automatically updated to reflect the committed changes.