Page MenuHomeFreeBSD

clang-format: Minor tweaks
ClosedPublic

Authored by markj on Apr 20 2021, 4:27 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Apr 30, 9:34 PM
Unknown Object (File)
Tue, Apr 30, 8:39 PM
Unknown Object (File)
Jan 5 2024, 6:47 PM
Unknown Object (File)
Dec 23 2023, 1:51 AM
Unknown Object (File)
Nov 10 2023, 3:20 PM
Unknown Object (File)
Oct 9 2023, 2:17 PM
Unknown Object (File)
Mar 4 2023, 9:36 PM
Unknown Object (File)
Feb 15 2023, 6:47 AM
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.Tue, Apr 30, 2:02 PM
This revision was automatically updated to reflect the committed changes.