Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Sep 15, 2021

Incorrect named args are source of bugs, like #22979.

Fix that by correcting them and adjust the format, so that clang-tidy can check it.

@maflcko
Copy link
Member Author

maflcko commented Sep 15, 2021

Setup clang-tidy:

apt install clang-tidy bear clang
./autogen.sh && ./configure --with-incompatible-bdb CC=clang CXX=clang++
make clean && bear make -j $(nproc)     # For bear 2.x
make clean && bear -- make -j $(nproc)  # For bear 3.x

Full test:

( cd ./src/ && run-clang-tidy  -j $(nproc) )

Diff test:

git diff | ( cd ./src/ && clang-tidy-diff -p2 -j $(nproc) )

@laanwj
Copy link
Member

laanwj commented Sep 15, 2021

Concept ACK, being able to check these automatically with a tool is a good idea.

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 15, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #23499 (multiprocess: Add interfaces::Node::broadCastTransaction method by ryanofsky)
  • #23352 (test: Extend stale_tip_peer_management test by MarcoFalke)
  • #22793 (Simplify BaseSignatureChecker virtual functions and GenericTransactionSignatureChecker constructors by achow101)
  • #21878 (Make all networking code mockable by vasild)
  • #18470 (net: Make stale tip check time type-safe, extend test by MarcoFalke)

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.

Copy link
Member

@fanquake fanquake left a comment

Choose a reason for hiding this comment

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

Concept ACK - Tested using the steps below. If we are going to start making more of these changes we should be integrating this into the CI at some point soon.

docker run -it --rm ubuntu:hirsute

apt update && apt upgrade

apt install git build-essential libtool autotools-dev automake pkg-config bsdmainutils python3 clang-12 clang-tidy-12 bear libevent-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-test-dev libdb-dev libdb++-dev

clang-12 --version
Ubuntu clang version 12.0.0-3ubuntu1~21.04.2
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

clang-tidy-12 --version
LLVM (http://llvm.org/):
  LLVM version 12.0.0
  
  Optimized build.
  Default target: x86_64-pc-linux-gnu
  Host CPU: skylake-avx512

bear --version
bear 3.0.8

git clone https://github.com/bitcoin/bitcoin
cd bitcoin
./autogen
./configure --with-incompatible-bdb CC=clang-12 CXX=clang++-12
make clean && bear -- make -j $(nproc)

( cd ./src/ && run-clang-tidy-12  -j $(nproc) )
Enabled checks:
    bugprone-argument-comment

clang-tidy-12 --use-color -p=/bitcoin /bitcoin/src/blockfilter.cpp
clang-tidy-12 --use-color -p=/bitcoin /bitcoin/src/chain.cpp
clang-tidy-12 --use-color -p=/bitcoin /bitcoin/src/banman.cpp
<snipp>

git diff | ( cd ./src/ && clang-tidy-diff-12.py -p2 -j $(nproc) )
No relevant changes found.

@maflcko
Copy link
Member Author

maflcko commented Sep 16, 2021

we should be integrating this into the CI at some point soon.

Happy to review a pull doing this. Though, I think it is also acceptable to run it only once before every major release.

@laanwj
Copy link
Member

laanwj commented Sep 21, 2021

I think we should first make sure our argument names make sense, then do this.

@practicalswift
Copy link
Contributor

Concept ACK

@jnewbery
Copy link
Contributor

jnewbery commented Nov 5, 2021

Concept ACK. Should we document the required comment style somewhere in the developer docs?

@maflcko
Copy link
Member Author

maflcko commented Nov 5, 2021

Happy to document the style in a follow-up. I have one follow-up myself that adjusts the style of existing args. The goal of this pull is to replace wrong names with correct names.

Copy link
Contributor

@lsilva01 lsilva01 left a comment

Choose a reason for hiding this comment

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

tACK fa7efa0

The commands described in #22981 (comment) ran successfully.

And after clang-tidy-10 returned without an error, I changed a commented named argument in a function, reran it, and the error was identified.

Should compile_commands.json be added to .gitignore ?

@maflcko
Copy link
Member Author

maflcko commented Nov 11, 2021

Should compile_commands.json be added to .gitignore ?

Yeah, will do on the next force push or the next follow-up pull, unless someone beats me to it.

@katesalazar
Copy link
Contributor

Concept ACK.

@fanquake
Copy link
Member

/usr/local/opt/llvm/bin/clang-tidy --use-color -p=/Users/michael/github/bitcoin-merge-tree /Users/michael/github/bitcoin-merge-tree/src/psbt.cpp
psbt.cpp:226:53: error: argument name 'input_idx' in comment does not match parameter name 'nInIn' [bugprone-argument-comment,-warnings-as-errors]
    MutableTransactionSignatureCreator creator(&tx, /*input_idx=*/0, out.nValue, SIGHASH_ALL);
                                                    ^
./script/sign.h:48:88: note: 'nInIn' declared here
    MutableTransactionSignatureCreator(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn);
                                                                                       ^
1 warning generated.
1 warning treated as error

@maflcko
Copy link
Member Author

maflcko commented Nov 16, 2021

Good catch. Fixed in #23525

@maflcko
Copy link
Member Author

maflcko commented Nov 17, 2021

Rebased to get rid of already fixed instances. Only 29 left in this pull for now.

Copy link
Member

@fanquake fanquake left a comment

Choose a reason for hiding this comment

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

ACK fac4947 - run-clang-tidy works for me now.

@fanquake fanquake merged commit 606e306 into bitcoin:master Nov 18, 2021
@maflcko maflcko deleted the 2109-docNamedArgs branch November 18, 2021 18:21
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Nov 19, 2021
fac4947 doc: Fix incorrect C++ named args (MarcoFalke)

Pull request description:

  Incorrect named args are source of bugs, like bitcoin#22979.

  Fix that by correcting them and adjust the format, so that clang-tidy can check it.

ACKs for top commit:
  fanquake:
    ACK fac4947 - `run-clang-tidy` works for me now.

Tree-SHA512: 2694e17a1586394baf30bbc479a913e4bad361221e8470b8739caf30aacea736befc73820f3fe56f6207d9f5d969323278d43a647f58c3497e8e44cad79f8934
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Nov 19, 2021
fac4947 doc: Fix incorrect C++ named args (MarcoFalke)

Pull request description:

  Incorrect named args are source of bugs, like bitcoin#22979.

  Fix that by correcting them and adjust the format, so that clang-tidy can check it.

ACKs for top commit:
  fanquake:
    ACK fac4947 - `run-clang-tidy` works for me now.

Tree-SHA512: 2694e17a1586394baf30bbc479a913e4bad361221e8470b8739caf30aacea736befc73820f3fe56f6207d9f5d969323278d43a647f58c3497e8e44cad79f8934
@bitcoin bitcoin locked and limited conversation to collaborators Nov 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants