Skip to content

Update clang-tidy rules#2814

Merged
guwirth merged 19 commits intoSonarOpenCommunity:masterfrom
cmorve-te:llvm_191
Nov 22, 2024
Merged

Update clang-tidy rules#2814
guwirth merged 19 commits intoSonarOpenCommunity:masterfrom
cmorve-te:llvm_191

Conversation

@cmorve-te
Copy link
Copy Markdown
Contributor

@cmorve-te cmorve-te commented Nov 19, 2024

I did this before #2782, but it got stuck in my employer's review process. Even if it's not adding any new rule any more, I still think the rest is worth merging.

The main thing is that it makes updating easier. After this,

  • The output of python clangtidy_createrules.py rules_fixurls <src_dir>clang-tools-extra/docs/clang-tidy/checks (which now works again) can be basically copy&pasted as it is into clangtidy.xml.
  • The output of python clangtidy_createrules.py diagnostics output.json can be basically copy&pasted as it is into clangtidy.xml.

Doing it this way avoids missing things like the fact the cppcoreguidelines-special-member-functions clang-tidy check gained an "AllowImplicitlyDeletedCopyOrMove" option in llvm 19, which is now included.


This change is Reviewable

Was failing with "TypeError: cannot use a string pattern on a bytes-like
object"
To match the existing clangtidy.xml.
To make it deterministic and match the existing clangtidy.xml.

It's swapping the order of "modernize-use-default" and
"modernize-use-default-member-init", making "modernize-use-default" go
first.
To match the existing clangtidy.xml.
This handles at least the ReportMoreUnsafeFunctions link in
bugprone/unsafe-functions.
…erity/type

To match the existing clangtidy.xml.
To match the existing clangtidy.xml.
To match the existing clangtidy.xml.
To avoid having to check them in the diff when updating.

I suspect clang-analyzer-core.DynamicTypePropagation has never been a
real one, but let's keep it for the time being.

linuxkernel-must-use-errs is not included because it was always
incorrect in the documentation, the code always used
linuxkernel-must-check-errs.
They were already sorted until the 19.1.0 update.
In the order the script generates them. Before the 19.1.0 update that
was already the case.
In the order the script generates them when using the llvmorg-19.1.0
tag.
Using the latest version of clangtidy_createrules.py.
To make it deterministic and make it easier to know where to place old
ones.
To avoid having to check the diff when updating.
@guwirth guwirth added this to the 2.2.0 milestone Nov 19, 2024
@guwirth
Copy link
Copy Markdown
Collaborator

guwirth commented Nov 19, 2024

@cmorve-te CI failed because of timeout. I re-run the job ...

@guwirth guwirth self-requested a review November 19, 2024 13:17
@guwirth
Copy link
Copy Markdown
Collaborator

guwirth commented Nov 20, 2024

@cmorve-te Normally, the sensors support all the rules of the current version and also those of the previous versions. I would not deviate from this in 2.1.x. With 2.2.x we can think about cleaning up and removing outdated rules (this PR is for 2.2). For me, the decisive factor is always which version of the tool is included in larger Linux distributions. These rules should at least be supported.

@cmorve-te
Copy link
Copy Markdown
Contributor Author

Normally, the sensors support all the rules of the current version and also those of the previous versions. I would not deviate from this in 2.1.x. With 2.2.x we can think about cleaning up and removing outdated rules (this PR is for 2.2). For me, the decisive factor is always which version of the tool is included in larger Linux distributions. These rules should at least be supported.

Sorry, not sure I understand what you mean here.

Is this about linuxkernel-must-use-errs? If it was not clear from the commit message, that has never been a real rule. Not in 19.1, not in any previous version.

The "linuxkernel-must-check-errs" warning was added in llvm 10 (llvm/llvm-project@fc8c65b), but wrongly documented as "linuxkernel-must-use-errs". sonar-cxx has had a "linuxkernel-must-use-errs" rule because it was parsing the (wrong) documentation to obtain the list of rules.
In llvm 19 the documentation has been fixed (llvm/llvm-project@a269195), but this has been a purely documentation thing. The check name has always been "linuxkernel-must-check-errs".

Do you want me to modify this PR to keep "linuxkernel-must-use-errs", despite clang-tidy having never generated such a message?

@guwirth
Copy link
Copy Markdown
Collaborator

guwirth commented Nov 20, 2024

To be clear, do you want me to modify this PR?

@cmorve-te No

I like to verify which clang version is part of current CI/CD systems

  • Ubuntu 22.04.5 LTS
  • Debian 11 “Bullseye”

In case it's an older one we should discuss if it makes sense to support also these old rules?
I will investigate if there are pre-installed packages (or maybe you know it).

@cmorve-te
Copy link
Copy Markdown
Contributor Author

Ubuntu 22.04.5 LTS

14.0 -> https://packages.ubuntu.com/jammy/clang

Debian 11 “Bullseye”

11.0 -> https://packages.debian.org/bullseye/clang

In case it's an older one we should discuss if it makes sense to support also these old rules?

I don't have a preference here.
For me, clang is basically an Android thing, so we are always quite up-to-date. I'm aware it's used also in the Apple world, but I'm not too aware of how things work there.

@guwirth
Copy link
Copy Markdown
Collaborator

guwirth commented Nov 20, 2024

@cmorve-te do you know which rules are in clang 11 and no more in clang 14?

  • These are the rules I would add / keep from old XML.?
  • Older rules(<11) I would delete.

What do you think?

@cmorve-te
Copy link
Copy Markdown
Contributor Author

What do you think?

In principle, fine with me. But see below.

do you know which rules are in clang 11 and no more in clang 14?

Kind of. You can mostly see the versions from 7294a24. So you can see https://releases.llvm.org/13.0.0/tools/clang/docs/DiagnosticsReference.html#wrequires-expression was last available in clang 13, the rest were still there in clang 14.

But you will notice I didn't change the links to some "old" warnings. And that's because the -Wauto-import warning, for example, still appears in the documentation of the latest version of clang.
Why is it "old" if it's in the latest version? Well, https://clang.llvm.org/docs/DiagnosticsReference.html#wauto-import only says This diagnostic flag exists for GCC compatibility, and has no effect in Clang.. Which, OK, if it's not a real warning it can just be removed, right?
But if you keep looking back, you will see

There are quite a few of these warnings that, according to the documentation, were real warnings at some point and become "for GCC compatibility" later. I find this quite strange, you can probably treat them as "it was remove in clang 15", but not 100% sure.

@guwirth
Copy link
Copy Markdown
Collaborator

guwirth commented Nov 22, 2024

Hi @cmorve-te, my proposal is to "merge the two PRs as is" and compare the XML afterwards with the old ones. I would add then the missing rules at the beginning of the XML as deprecated. What do you think?

@cmorve-te
Copy link
Copy Markdown
Contributor Author

I find this quite strange, you can probably treat them as "it was remove in clang 15", but not 100% sure.

See llvm/llvm-project#117316

my proposal is to "merge the two PRs as is" and compare the XML afterwards with the old ones. I would add then the missing rules at the beginning of the XML as deprecated. What do you think?

Not sure I got this.
If I didn't make a mistake, these PRs don't remove any rule at all unless explicitly documented, for some specific reason (i.e. they were always "wrong"); so supposedly we don't want them at all.

The main thing from this specific PR is that it makes updating the rules easier, since the script directly generates the existing XML. Part of this is because old rules are already added by the add_old_clangtidy_rules()/add_old_diagnostics_rules() functions. If you prefer to have them only in the XML, but in a specific section at the top, that's also fine with me, yes.

@guwirth
Copy link
Copy Markdown
Collaborator

guwirth commented Nov 22, 2024

@cmorve-te I compared old/new again. My old comparison was wrong (why ever?). There is only one difference: linuxkernel-must-use-errs. I merge it now.

@guwirth guwirth merged commit fb106d1 into SonarOpenCommunity:master Nov 22, 2024
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@cmorve-te in the old file were additional keys which are missing now:

<key>linuxkernel-must-use-errs</key>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, this was done on purpose. I tried to document it in d419293

linuxkernel-must-use-errs is not included because it was always incorrect in the documentation, the code always used linuxkernel-must-check-errs.

You can see the details in llvm/llvm-project@a269195

def create_template_rules(rules):
rule_key = "CustomRuleTemplate"
rule_name = "Template for custom Custom rules"
rule_name = "Rule template for Clang-Tidy custom rules"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CustomRuleTemplate is correct now


RulesDefinition.Repository repo = context.repository(CxxClangTidyRuleRepository.KEY);
assertThat(repo.rules()).hasSize(1573);
assertThat(repo.rules()).hasSize(1572);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@cmorve-te could you add a list with added/removed rules please.

@guwirth
Copy link
Copy Markdown
Collaborator

guwirth commented Nov 22, 2024

@cmorve-te thx for providing this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants