-
Notifications
You must be signed in to change notification settings - Fork 36.4k
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
ci: Integrate bitcoin-tidy
clang-tidy plugin
#26296
Conversation
e41de98
to
c4671b0
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
If this requires clang-15, I'd prefer to wait until that is backported to Ubuntu Jammy instead of hopping the short-term releases. |
c4671b0
to
579e46f
Compare
This doesn't actually require LLVM 15, it's just that the I've dropped the Kinetic / LLVM 15 bump, in favour of a different approach; patching |
579e46f
to
495eac0
Compare
Concept ACK (obviously). Thought dump below. A few things worth considering when it comes to these plugins:
Elaborating: c++ is complicated, so defining compiler rules is also complicated. Taking this code for a trivial example: struct A{};
void func()
{
A foo;
const A bar;
} In testing, one may find that the following query works to find all declarations of type A: Instead, we'd want something more like: I'm mentioning this to try to demonstrate what I meant by "they do exactly what you tell them to". It's quite common (especially when just getting started) to end up with an overly-broad or unnecessarily specific query. The first query would appear to be fine if a So I think we'll likely want some pretty thorough documentation that states exactly what the check is intended to do. Additionally, we'll want tests that verify those intentions. In the case of the plugin here, I have added some loose checks here but nothing automated: https://github.com/theuni/bitcoin-tidy/blob/main/test_desig_init.cpp . An example of a corner-case that wasn't caught at first with this check is included here: nested structs with uninitialized members. tl;dr: before merge, I think we'll want to add a mini test suite to the plugin repo that allows us to verify that checks are working as defined/intended. Additionally, there will need to be some understanding that checks will likely require refinement over time as new corner cases are exposed.
This isn't important for now, but I suspect that the infrastructure for this will end up being more complicated eventually. The obvious outlier (imo) is libbitcoinkernel, where we may want to add more strict checks that other parts of the code (bitcoin-qt for ex) aren't required to abide by. |
495eac0
to
92c6ea2
Compare
Concept ACK |
92c6ea2
to
e10519c
Compare
Would be good to explain how this is different from https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/pro-type-member-init.html . Edit: I guess one is for constructors, the other is for aggregates, so they are orthogonal, and go hand-in-hand. See also #26762 (comment) |
Last I checked, turning that on was essentially unusable, due to false-positives. Will take another look. |
It should only hit on classes that have a |
|
Enable `bitcoin-unterminated-logprintf`. Co-authored-by: Cory Fields <cory-nospam-@coryfields.com>
888977f
to
1c976c6
Compare
Dropped the test commit back out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 1c976c6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK 1c976c6 👠
Show signature
Signature:
untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: re-ACK 1c976c691cc4b20f43071aabf36c7afed1571057 👠
AUAtgJBmTgwGLADs8IgqfpOQg2nQfQ2+D/7P8lwnKkrIGJwTNAjXOYnonfN9oAT1L5+CTeUJzKaPpGHVi5t7Cw==
ACK 1c976c6 |
rfm or is anything left to be done here for this test-only pull? |
I missed that Cory had already ACK'd, and was waiting for him to re-ACK. Given that's already happened, I don't think there's anything left here, and docs can be fixed in the followup. |
Example Usage: | ||
|
||
```bash | ||
cmake -S . -B build -DLLVM_DIR=/path/to/lib/cmake/llvm -DCMAKE_BUILD_TYPE=Release |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also add an example for common systems, Ubuntu/Debian-based ones, and Fedora/CentOS-based ones, what DLLVM_DIR
should be for them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #28245.
cxxMemberCallExpr( | ||
thisPointerType(qualType(hasDeclaration(cxxRecordDecl(hasName("CWallet"))))), | ||
callee(cxxMethodDecl(hasName("WalletLogPrintf"))), | ||
hasArgument(0, stringLiteral(unterminated()).bind("logstring"))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong. The argument of WalletLogPrintf
is never a string literal (the parameter is).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in #28237
*/ | ||
finder->addMatcher( | ||
cxxMemberCallExpr( | ||
thisPointerType(qualType(hasDeclaration(cxxRecordDecl(hasName("CWallet"))))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong, too. ScriptPubKeyMan
has a log statement, too.
My recommendation would be to just remove this line completely, unless there is a reason to have it. The other lines should be exact enough to match everything that is needed, without under- or over-matching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, I was inclined to argue with you because I think the tests should be as tight as possible. But realistically, it's more likely for a class to be forgotten in the checks (as has happened here) than a false-positive in some future class. So I begrudgingly agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind creating a pull with the outstanding feedback? :)
If not, I'll try to do it next week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in #28237
Yep, will do. I was just waiting for the others to settle. |
…alletLogPrintf() fa60fa3 bitcoin-tidy: Apply bitcoin-unterminated-logprintf to spkm as well (MarcoFalke) faa1143 refactor: Enable all clang-tidy plugin bitcoin tests (MarcoFalke) fa6dc57 refactor: Enforce C-str fmt strings in WalletLogPrintf() (MarcoFalke) fa244f3 doc: Fix bitcoin-unterminated-logprintf tidy comments (MarcoFalke) Pull request description: All fmt functions only accept a raw C-string as argument. There should never be a need to pass a format string that is not a compile-time string literal, so disallow it in `WalletLogPrintf()` to avoid accidentally introducing it. Apart from consistency, this also fixes the clang-tidy plugin bug bitcoin/bitcoin#26296 (comment). ACKs for top commit: theuni: ACK fa60fa3 Tree-SHA512: fa6f4984c50f9b34e850bdfee7236706af586e512d866cc869cf0cdfaf9aa707029c210ca72d91f85e75fcbd8efe0d77084701de8c3d2004abfd7e46b6fa9072
fa67b81 Refactor: Remove unused FlatFilePos::SetNull (MarcoFalke) Pull request description: This is unused outside of tests and the default constructor. With C++11, it can be replaced by C++11 member initializers in the default constructor. Beside removing unused code, this also makes it less fragile in light of uninitialized memory. (See also bitcoin#26296 (comment)) If new code needs to set this to null, it can use `std::optional`, or in the worst case re-introduce this method. ACKs for top commit: dergoegge: Code review ACK fa67b81 TheCharlatan: ACK fa67b81 john-moffett: ACK fa67b81 Tree-SHA512: 465c5e3eb4625405c445695d33e09a1fc5185c7dd1e766ba06034fb093880bfc65441d5334f7d9b20e2e417c2075557d86059f59d9648ca0e62a54c699c029b9
fa67b81 Refactor: Remove unused FlatFilePos::SetNull (MarcoFalke) Pull request description: This is unused outside of tests and the default constructor. With C++11, it can be replaced by C++11 member initializers in the default constructor. Beside removing unused code, this also makes it less fragile in light of uninitialized memory. (See also bitcoin#26296 (comment)) If new code needs to set this to null, it can use `std::optional`, or in the worst case re-introduce this method. ACKs for top commit: dergoegge: Code review ACK fa67b81 TheCharlatan: ACK fa67b81 john-moffett: ACK fa67b81 Tree-SHA512: 465c5e3eb4625405c445695d33e09a1fc5185c7dd1e766ba06034fb093880bfc65441d5334f7d9b20e2e417c2075557d86059f59d9648ca0e62a54c699c029b9
fa67b81 Refactor: Remove unused FlatFilePos::SetNull (MarcoFalke) Pull request description: This is unused outside of tests and the default constructor. With C++11, it can be replaced by C++11 member initializers in the default constructor. Beside removing unused code, this also makes it less fragile in light of uninitialized memory. (See also bitcoin#26296 (comment)) If new code needs to set this to null, it can use `std::optional`, or in the worst case re-introduce this method. ACKs for top commit: dergoegge: Code review ACK fa67b81 TheCharlatan: ACK fa67b81 john-moffett: ACK fa67b81 Tree-SHA512: 465c5e3eb4625405c445695d33e09a1fc5185c7dd1e766ba06034fb093880bfc65441d5334f7d9b20e2e417c2075557d86059f59d9648ca0e62a54c699c029b9
fa67b81 Refactor: Remove unused FlatFilePos::SetNull (MarcoFalke) Pull request description: This is unused outside of tests and the default constructor. With C++11, it can be replaced by C++11 member initializers in the default constructor. Beside removing unused code, this also makes it less fragile in light of uninitialized memory. (See also bitcoin#26296 (comment)) If new code needs to set this to null, it can use `std::optional`, or in the worst case re-introduce this method. ACKs for top commit: dergoegge: Code review ACK fa67b81 TheCharlatan: ACK fa67b81 john-moffett: ACK fa67b81 Tree-SHA512: 465c5e3eb4625405c445695d33e09a1fc5185c7dd1e766ba06034fb093880bfc65441d5334f7d9b20e2e417c2075557d86059f59d9648ca0e62a54c699c029b9
fa67b81 Refactor: Remove unused FlatFilePos::SetNull (MarcoFalke) Pull request description: This is unused outside of tests and the default constructor. With C++11, it can be replaced by C++11 member initializers in the default constructor. Beside removing unused code, this also makes it less fragile in light of uninitialized memory. (See also bitcoin#26296 (comment)) If new code needs to set this to null, it can use `std::optional`, or in the worst case re-introduce this method. ACKs for top commit: dergoegge: Code review ACK fa67b81 TheCharlatan: ACK fa67b81 john-moffett: ACK fa67b81 Tree-SHA512: 465c5e3eb4625405c445695d33e09a1fc5185c7dd1e766ba06034fb093880bfc65441d5334f7d9b20e2e417c2075557d86059f59d9648ca0e62a54c699c029b9
fa67b81 Refactor: Remove unused FlatFilePos::SetNull (MarcoFalke) Pull request description: This is unused outside of tests and the default constructor. With C++11, it can be replaced by C++11 member initializers in the default constructor. Beside removing unused code, this also makes it less fragile in light of uninitialized memory. (See also bitcoin#26296 (comment)) If new code needs to set this to null, it can use `std::optional`, or in the worst case re-introduce this method. ACKs for top commit: dergoegge: Code review ACK fa67b81 TheCharlatan: ACK fa67b81 john-moffett: ACK fa67b81 Tree-SHA512: 465c5e3eb4625405c445695d33e09a1fc5185c7dd1e766ba06034fb093880bfc65441d5334f7d9b20e2e417c2075557d86059f59d9648ca0e62a54c699c029b9
Demo of integrating the bitcoin-tidy, clang-tidy plugin written by theuni into our tidy CI job.
The plugin currently has a single check,
bitcoin-unterminated-logprintf
. This would replace our current Python driven,git-grep
-based,.cpp
file only, lint-logs linter.