Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable clang-tidy readability checks #936

Merged
merged 24 commits into from
Jan 16, 2024
Merged

Conversation

Baltoli
Copy link
Contributor

@Baltoli Baltoli commented Dec 18, 2023

This is another PR in my ongoing series to enable more clang-tidy checks for the codebase. As previously, each commit in this PR fixes the issues flagged by a single check, and can / should be reviewed independently.

As ever, I'm happy to bikeshed any of the specific changes in this PR. Note that for readability-function-cognitive-complexity, I've not actually refactored any existing code in the interest of keeping this diff minimal, but the check will prevent us from introducing new code that exceeds the complexity threshold.

@Baltoli Baltoli marked this pull request as ready for review January 16, 2024 12:38
@@ -40,12 +40,13 @@ void addMatchSuccess(void) {
nullptr});
}

void addMatchFailReason(void *subject, char *pattern, char *sort) {
void addMatchFailReason(void *subject, const char *pattern, const char *sort) {
Copy link
Contributor

@Scott-Guest Scott-Guest Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we use both const char * and char const * in various places.

We should consider setting set QualifierAlignment: Right to clean this up: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#qualifieralignment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there some kind of semantic difference between the two? The document you linked there even gives a warning about incorrect formatting.

Copy link
Contributor

@Scott-Guest Scott-Guest Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gtrepta const char * and char const * are equivalent - both are a pointer to a constant char. I think the common lingo here is "west const" versus "east const".

(Both are distinct from char * const though - a constant pointer to a char.)

The warning is worth bikeshedding about, but IMO it's not a big concern. Looking through clang-format's git blame for the warning, AFAICT the only known issue is that lower-case macros may be mis-identified as types, meaning that it could rewrite

#define intptr int *
const intptr a;

to

intptr const a;

which is a semantic change. This doesn't seem to appear anywhere in our codebase, and if it does, we should just change it to a typedef instead of a macro anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that clang-tidy will actually catch usages of lower-case macros like that anyway, so I think we can make this change safely.

auto *i1_ty = llvm::Type::getInt1Ty(Ctx);

auto *proof_output_flag = Module->getOrInsertGlobal("proof_output", i1_ty);
auto *proof_output = new llvm::LoadInst(
i1_ty, proof_output_flag, "proof_output", insert_at_end);
i1_ty, proof_output_flag, "proof_output", insertAtEnd);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should configure readability-identifier-naming to clean up these mismatched naming conventions: https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall some discussion earlier where lower_case was vouched for, and the reasons sounded compelling. I don't remember the specifics but it does feel easier to read imo than any of the camel case styles.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm pretty strongly in favour of snake_case naming. I'll put together an issue that makes a choice for all the salient options to readability-identifier-naming so that we can see what it looks like in practice.

Copy link
Contributor

@Scott-Guest Scott-Guest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Left a few comments that would be nice to address in a follow-up PR.

I'm also strongly in favor of refactoring all the NOLINTNEXTLINE(*-cognitive-complexity) functions at some point.

@Baltoli
Copy link
Contributor Author

Baltoli commented Jan 16, 2024

Yep, I'll fix those comments in follow-ups. The naming convention in particular needs some bikeshedding first, but I plan to get round to it.

@rv-jenkins rv-jenkins merged commit 0231f18 into master Jan 16, 2024
7 checks passed
@rv-jenkins rv-jenkins deleted the clang-tidy-readability branch January 16, 2024 16:27
rv-jenkins added a commit that referenced this pull request Jan 17, 2024
As suggested in
#936, this PR
sets the appropriate `clang-format` option to right-align qualifiers in
the backend (that is, writing `T const&` rather than `const T&`).

This PR is fully mechanical and introduces no manual changes to the
code.

---------

Co-authored-by: rv-jenkins <admin@runtimeverification.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants