1 major finding · 3 minor findings · 2 suggestions
Findings
[major] · The new check makes tidy CI fail on an unconverted test file
With bitcoin-* enabled and WarningsAsErrors: '*', the untouched MakeRandomTx assignments in mempool_fee_estimator_tests.cpp should make the tidy job fail; this is inferred from the code, not a CI run.
Location: contrib/devtools/bitcoin-tidy/bitcoin-tidy.cpp:15 (head).
Details and suggested fix
Registering the check as bitcoin-combine-assignments enables it through the bitcoin-* glob in src/.clang-tidy, which also treats all warnings as errors. The native tidy CI job runs run-clang-tidy with that configuration on a dev-mode build that includes unit tests.
The untouched MakeRandomTx assigns tx.vin[0].prevout.hash and tx.vin[0].prevout.n consecutively, then assigns tx.vout[0].scriptPubKey and tx.vout[0].nValue consecutively. Each pair completes an annotated group, so the check should emit two diagnostics, both treated as errors. This conclusion comes from source inspection; the CI job was not run.
Registering the check this way also makes it a required rule for future code, including code affected by the fix-it issues in the other findings. The description instead presents it as a one-off refactoring aid. Either convert the remaining sites and state that the rule is intended to be enforced, or exclude it from src/.clang-tidy and invoke it explicitly with -checks= while it serves as a refactoring aid. The bitcoin-tidy-tests target also lacks an example file for this check.
[minor] · BuildSpendingTransaction drops the supplied script witness
The helper returns an input without the caller's witness, although current tests still pass because DoTest supplies that witness directly to VerifyScript.
Location: src/test/util/transaction_utils.cpp:33 (head).
Details and suggested fix
The helper assigns scriptWitness to txSpend.vin[0], then replaces the entire input with a CTxIn constructed from the outpoint, scriptSig, and sequence. That constructor does not set the witness, so it is reset to empty. Previously, the helper assigned the other fields individually and preserved the witness. The returned transaction's HasWitness(), wtxid, weight, and witness serialization therefore do not match the caller's request.
The only caller passing a non-empty witness is ScriptTest::DoTest, which supplies it separately to VerifyScript, so no current test changes outcome. The regression is nevertheless silent. Assign scriptWitness after constructing the CTxIn. The check should also skip whole-object fix-its for records with unannotated non-static data members.
[minor] · The fix-it can change side effects, dependencies, and repeated assignments
The rewrite is not always equivalent; in this change it also makes the order of RNG draws in sighash_tests.cpp unspecified.
Location: contrib/devtools/bitcoin-tidy/combine-assignments.cpp:169 (head).
Details and suggested fix
The fix-it replaces a run of statements with base = T(rhs...) without checking side effects or dependencies. Constructor arguments are emitted in annotation order, but C++ does not specify their evaluation order. Repeated assignments can also lose earlier side effects: for example, out.nValue = counter++; out.nValue = 2; out.scriptPubKey = s; loses the increment. Matching the base by source text can merge different expressions, so points[i++].hash = h; points[i++].n = 0; becomes an assignment to one element with one increment. An RHS that reads a member assigned earlier in the run can also read its old value after rewriting.
In sighash_tests.cpp, two RNG calls that were previously sequenced are now constructor arguments without a specified evaluation order. With the same RANDOM_CTX_SEED, compilers that evaluate arguments in different orders can generate different random transactions, although the test assertions still hold. No other rewritten site with this pattern was found. Emit a fix-it only when the base and RHS expressions have no side effects, no RHS refers to the base, and no argument index repeats. In sighash_tests.cpp, draw the random values into locals in their original order.
[minor] · Compound assignments are rewritten as plain assignments
A compound update followed by another annotated-field assignment can be rewritten to a constructor that drops the existing value and the compound operation; no current in-tree site with this shape was identified.
Location: contrib/devtools/bitcoin-tidy/combine-assignments.cpp:72 (head).
Details and suggested fix
GetAssignment accepts any BinaryOperator for which isAssignmentOp() is true, including compound operators such as +=, -=, and |=. ExtractAssignment retains only the right-hand side. A compound update to nValue, n, or nSequence followed by an assignment to another annotated field is therefore treated as a complete group, and the fix-it replaces the update with the bare right-hand side.
No current in-tree site with this shape was identified, so in-tree impact is unconfirmed. With the check enabled under bitcoin-*, correct code of this form would raise a hard tidy error with an incorrect fix-it. Require BO->getOpcode() == BO_Assign and add a negative case to bitcoin-tidy-tests, which currently compiles only example_nontrivial-threadlocal.cpp.
Optional improvements
[suggestion] · Annotations reach ordinary Clang builds of hot transaction fields
Clang lowers accesses to annotated fields through llvm.ptr.annotation, which can inhibit optimization; the impact on Bitcoin Core has not been measured.
Location: src/attributes.h:29 (head).
Details and suggested fix
CONSTRUCTOR_ARGUMENT expands to [[clang::annotate(...)]] in every Clang build, not only when running clang-tidy. It annotates fields of COutPoint, CTxIn, and CTxOut. Clang lowers accesses to annotated fields through an llvm.ptr.annotation intrinsic, which LLVM has documented as pessimizing ordinary optimizations (https://github.com/llvm/llvm-project/issues/55190). These fields are used on hot paths, including outpoint hashing and comparison in the coins cache and nValue sums. The impact on Bitcoin Core has not been measured.
Define the annotation only under __clang_analyzer__ and leave it empty otherwise, so clang-tidy can use it without changing generated code. Alternatively, provide IR or benchmark evidence that the effect is neutral. clang-tidy defines __clang_analyzer__ (https://reviews.llvm.org/D46325).
[suggestion] · The fix-it deletes comments between combined statements
The mechanical rewrite silently removed explanatory comments from several tests in this change.
Location: contrib/devtools/bitcoin-tidy/combine-assignments.cpp:174 (head).
Details and suggested fix
The replacement range extends from the first statement to the last, deleting any comments between them. This change removed the miniminer test note explaining that output values do not matter because accounting uses cached fees; the per-output labels in script_p2sh_tests.cpp; and the // extra output and // only 1 transaction comments in the wallet creation benchmark and miner tests. Restore these comments next to the combined assignments. The check should decline to provide a fix-it, or emit only a diagnostic, when the replaced source range contains a comment.