Shane Lontis
Mon 9 Jun 2025 5:55AM
I think we still some form of linter as well as a formatter.

Paul Yang
Mon 9 Jun 2025 5:55AM
There's no need to re-invest on tools whose functionality is mainly covered by other tools.

Tim Hudson
Mon 9 Jun 2025 5:55AM
I think changing to a more widely used tool and adjusting our coding guidelines to fit what the tool can handle makes sense. We still have some "quirky" things in place and some flexibility where we should just pick a single approach. Right now we have too many exceptions and too many code format nits that come up during reviews which should be able to be eliminated by automation of formatting and an adjustment of the coding guidelines.
I would perform a general reformat once we settle on what precisely that format should be and apply it to earlier branches to allow for continued easy backfit of code. My view is the benefit comes from consistency and that means automation as we have seen from the last 10 years of not having an automated format approach.

Neil Horman Tue 10 Jun 2025 10:19AM
FWIW, if you look at https://github.com/nhorman/openssl/tree/sample-clang-format It appears that clang-format actually handles our un-terminated macros fairly gracefully. I'm looking at commit 315301e96385c3208b7e35c63beb9759b79b56cc, specifially instances of our use of DEFINE_STACK_OF and IMPLEMENT_ASN1_FUNCTIONS as an example.

Richard Levitte Tue 10 Jun 2025 9:58AM
Most of all, check-format.pl sometimes contradicts our coding style.
When that happens, I have zero regrets waiving the C style checks.
Also, we have macros invocations all over the place that look like a function call, but aren't terminated with ';'. That will confuse any source format checker, including clang-format, to the point that their reports are utter rubbish.
When that happens, I have zero regrets waiving the C style checks.

Tomas Mraz Tue 10 Jun 2025 8:16AM
In my opinion is a completely strict code format checking just breaks readability and usability of the code base. Also due to inevitable weaknesses of the code format tool (it cannot really fully understand the code especially due to our heavy use of macros), it is making our source being dictated by our tools and not by the developers who actually write the code. So I beg to disagree.
Sasha Nedvedicky Tue 10 Jun 2025 7:47AM
@Tomas Mraz I agree this is going to be a significant bump and I fully understand your concerns here. In my opinion the goal here is to have a style/format consistency in the whole source code base. Not running check-format.pl and then deciding wether code should be fixed to make check-format.pl happy or just press c-style waived button. In my opinion, the rigid c-style with no exceptions is a good thing. Think of a C-style/format as a conductor for a coding orchestra. There is no good performance without a conductor.
All this is heading to `Big Source Code Reformat effort 2.0` IMO it should happen in master branch only.
Sasha Nedvedicky Tue 10 Jun 2025 7:12AM
IMO we should not be waving c-style. perhaps the only reason to wave c--style is the case when we adopt 3rd-party code which comes from different project. This should be only exception. c-style waiver as being used now makes c-style policy useless/ineffective.

Tomas Mraz Mon 9 Jun 2025 6:33PM
Please understand than any tool we choose will be imperfect and we will always need exceptions to otherwise fairly strict rules. IMO the current CI job with check-format.pl is good enough for checking. Of course being able to format things would be a nice functionality so I am not opposed to moving to something else eventually although I am not sure this is the most pressing thing we should invest our time in right now. What I would not like to see is committing formatting changes on completely unrelated lines just because the editing/formatting tool forces you to do it. This would make a nightmare when backporting patches, etc.

Neil Horman Mon 9 Jun 2025 5:39PM
Agreed, while writing this I recalled this issue:
https://github.com/openssl/openssl/issues/24901
in which you documented several issues that you had run acrossin check-format.pl. If memory serves @Viktor Dukhovni triaged several of the issues, fixed some of them, and determined that the investment of time to fix the remainder likely wasn't worth the effort for the time available ( @Viktor Dukhovni , please correct me here if my recollection is flawed). Assuming my memory is accurate though, if we don't have the time to invest in fixing the tool we have, it seems to me, switching to a tool that is more widely maintained makes sense.

Richard Levitte Mon 9 Jun 2025 3:36PM
@Neil Horman
check-format.pl is quite buggy... I've to waive the style check more often than not.

Neil Horman Mon 9 Jun 2025 1:58PM
I think maintaining both is asking to serve two masters, for which the costs outweigh the benefits. A style should be definitive, and if we need to stray from it, we should document why in the code (clang-format has this feature, which works similarly to how indent does it). As for availability, I agree that check-format.pl is more available than clang-format might be, but I feel like thats the workaround point (i.e. a CI job that checks formatting can easily upload the diff to fix the format errors as an artifact of that job, which developers can just apply if they don't want the tool installed locally).

Todd Short
Mon 9 Jun 2025 5:55AM
Why not both? clang-format may not be available to everyone, and there's no reason to get rid of a tool that works for everybody. Is it twice the maintenance burden? Unikely. Will there be conflicts? Probably, but they can be resolved/worked-around. It does sound as though clang-format might be more limited in it's functionality.
Frederik Wedel-Heinen
Mon 9 Jun 2025 5:55AM
I vote for adopting clang-format for the checks in check-format.pl that can be implemented using that. Please refer to my comment in the thread.

Matt Caswell
Mon 9 Jun 2025 5:55AM
I'd really like to see such things start as a discussion before going straight to a vote. Votes don't allow you to just post comments without having to make a choice. I believe there are reasons why check-format.pl exists, and why that was chosen over existing formatting tools (I think because it was too difficult to get other tools to do the checks we wanted). I don't know if those reasons still apply. It is the wrong way around to decide to go to some other tool first before evaluating it. If we think check-format.pl no longer meets our needs we should write down what our needs are and evaluate the alternative(s) to determine which one best achieves those needs.
BTW "there is an opportunity to replace it with a more recent tool."...check-format is not even really that old (it was first added in 2020)

Richard Levitte Tue 10 Jun 2025 10:02AM
If we're going for absolute consistency, I'd rather force a line break after the function return type.

Tim Hudson Tue 10 Jun 2025 8:24AM
@Sasha Nedvedicky I strongly prefer to see consistency here too. Pick one approach and stick to it. We have a lot of the code where the coding style is such that we get personal preferences for approaches that differ which are throughout the code. Picking on consistent style does lead to cleaning looking code.
Sasha Nedvedicky Tue 10 Jun 2025 7:08AM
@Richard Levitte I prefer consistency here. I believe we should choose one and stick to it. I prefer the variant for function `sub()` as it is make navigation in source code easier (finding function definition is easy just /^sub). However consistency takes precedence at least for me.

Richard Levitte Mon 9 Jun 2025 3:34PM
@Sasha Nedvedicky
I see nothing wrong with accepting both, mind you... sometimes, our function signatures are really very long, and breaking after the return type has precedents (it's standard in GNU coding recommendations, for example).
Sasha Nedvedicky Mon 9 Jun 2025 8:38AM
No I'm not sure at all however the check-format.pl we use is quite liberal. for example both those two quite different styles below are accepted with no issues:
int add(int a, int b)
{
return a + b;
}
int
sub(int a, int b)
{
return a - b;
}

Tomas Mraz
Mon 9 Jun 2025 5:55AM
Are you absolutely sure all the existing rules (or at least the important ones) enforced by check-format.pl are doable with clang-format?

Richard Levitte
Mon 9 Jun 2025 5:55AM
A technical note: clang-format, like any formatter, is limited to exactly that, formatting. They are usually not designed to enforce code ordering rules, or to reorder code (such as moving all variable declarations to the start of a block). That's simply out of their scope. To enforce such things, we'd need some sort of linter with that sort of capability, in addition to a formatter.
Sasha Nedvedicky
Mon 9 Jun 2025 5:55AM
I'm for clang-format although there does not seem to be way to ask clang-format to restrict variable declaration. I could not figure out a way to tell clang-format not to allow variable declaration in the middle of the code block.
Poll Created Mon 9 Jun 2025 5:55AM
Replacing check-format.pl with clang-format You have until Mon 23 Jun 2025 9:00PM to participate.
Moving from ANSI-C to C-99 requires us to update C-style. For example, we are already aware that we need to impose some restrictions on where variables can be declared. The C-99 standard is too liberal because it allows variable declaration anywhere. For OpenSSL we might want to restrict the C-99 freedom here and allow variable declarations at the start of the block or inside of conditionally compiled sections (see discussion here). There might be more C-99 constructs that we will need to ban/restrict. Let's leave those for a separate poll/discussion. This decision is about replacing util/check-format.pl with clang-format.
My reasoning about using a clang-format instead of perl script goes as follows:
Adoption of C-99 requires an update to C-style, which will require updating check-format.pl. instead of fixing Perl code, there is an opportunity to replace it with a more recent tool.
Unlike check-format.pl, the clang-format can also format the code to match C-style
clang-format seems to play nicely with git
clang-format comes with plugins for various editors (emacs, vim, VS-code, ...)
Neil and Andrew gave a clang-format try already and the tool can get confused (see details here), but I still think it is a way to go.
In this poll, I'd like to select the tool that will check and format C-style the follow-up polls will be taking decisions on updating the C-style.
Current results
Current results | Option | % of points | Voters | |
---|---|---|---|---|
|
let's go for clang-format | 66.7% | 8 |
![]() ![]() ![]() ![]() ![]() ![]() |
keep using check-format.pl | 8.3% | 1 |
![]() |
|
What other tool to check (and format) sources you suggest? | 25.0% | 3 |
![]() ![]() |
|
Undecided | 0% | 7 |
![]() ![]() ![]() |
12 of 19 people have participated (63%)
Paul Yang · Wed 11 Jun 2025 7:00AM
At least we can have a 'caller' script that calls both clang-format and current check-format.pl for different checks. And the final goal is to reduce the effort we need to maintain check-format.pl