Skip to content

iwyu: Fix warnings in src/test/fuzz and treat them as errors - #36808

Draft
hebasto wants to merge 3 commits into
bitcoin:masterfrom
hebasto:261108-iwyu-fuzz
Draft

hebasto wants to merge 3 commits into
bitcoin:masterfrom
hebasto:261108-iwyu-fuzz

Conversation

@hebasto

@hebasto hebasto commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

This PR continues the ongoing effort to enforce IWYU warnings.

See Developer Notes.

Based on #36844.

@DrahtBot

DrahtBot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

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

External sites

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #37015 (Use O(log n) skiplist construction in CBlockIndex by sipa)
  • #36996 (fuzz: fix timelock range in miniscript_smart by erickcestari)
  • #36946 (scripted-diff: [test] Add util/check.h includes for assertions by maflcko)
  • #36897 (wallet, migration: Contain all legacy wallet and migration related things in its own subdirectory, namespace, and classes by achow101)
  • #36885 (wallet, rpc: Add analyzedescriptor for multisig setups by pablomartin4btc)
  • #36822 (fuzz: torcontrol: drive the control connection over a mocked socket by erickcestari)
  • #36812 (crypto: copy HMAC state instead of rehashing key pads by l0rinc)
  • #36786 (fuzz: report more events, and check more invariants in connman target by darosior)
  • #36635 (fuzz: Add a target that feeds arbitrary bytes to V2Transport by fametrano)
  • #36603 (Improve loadtxoutset performance by ajtowns)
  • #36598 ([Demo] validation: remove AssumeUTXO by l0rinc)
  • #36548 (net: serve MSG_BLOCK by stripping witnesses in place by l0rinc)
  • #36188 (crypto: plug hardware optimized SHA256 into libsecp256k1's context by furszy)
  • #36122 (BIP460: CISA for Taproot key path spends by fjahr)
  • #36114 (wallet: harden external signer psbt processing, revamp mock by Sjors)
  • #36033 ([wip,nomerge,rfc] build: Require C++23 compiler by maflcko)
  • #35888 (net: reject oversized outbound messages by l0rinc)
  • #35229 (refactor: Use CBlockIndex parameters as reference by optout21)
  • #29491 ([EXPERIMENTAL] Schnorr batch verification for blocks by fjahr)
  • #27260 (Enhanced error messages for invalid network prefix during address parsing. by portlandhodl)

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.

@DrahtBot

DrahtBot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task Alpine (musl): https://github.com/bitcoin/bitcoin/actions/runs/42513074263/job/128830134615
LLM reason (✨ experimental): CI failed during compilation: headerssync.cpp has missing declarations/includes, causing incomplete CBlockIndex and undefined symbols.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

Comment thread src/protocol.h Resolved
# Nothing for now.
[
# Standard C library symbols.
{ "include": [ "<bits/types/cookie_io_functions_t.h>", "private", "<cstdio>", "public" ] },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this needed? Has it been upstreamed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Has it been upstreamed?

Working on this.

@hebasto
hebasto force-pushed the 261108-iwyu-fuzz branch 2 times, most recently from 04ce74c to af4fb74 Compare November 10, 2026 14:52
fanquake added a commit that referenced this pull request Nov 10, 2026
ca14da9 lint: Require all code in a header to be inside its include guard (Hennadii Stepanov)
00e1f35 Enclose all header content in include guards (Hennadii Stepanov)

Pull request description:

  From https://gcc.gnu.org/onlinedocs/cpp/Once-Only-Headers.html:
  > If a header file happens to be included twice, the compiler will process its contents twice. This is very likely to cause an error, e.g. when the compiler sees the same structure definition twice. Even if it does not, it will certainly waste time.

  This PR fixes the three headers that have content outside their guards and modifies [`test/lint/lint-include-guards.py`](https://github.com/bitcoin/bitcoin/blob/master/test/lint/lint-include-guards.py) to catch such violations in the future.

  A prerequisite for #36808.

ACKs for top commit:
  maflcko:
    review ACK ca14da9 🖨

Tree-SHA512: 79a3e7591d4393343df9dcd39d48fe637d62b640e4dad71079fdc2bbbbcf2c01db36c3de77e82d26f90bbc0bdd2864f0e289eb45536f9df9f6e797ee7467874d
@hebasto

hebasto commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

Also, I am unsure how to review the non-fuzz header changes? How do I know they are enforced by iwyu?

The changes in non-fuzz headers are enforced by IWYU because, due to the stem name coincidence, it considers them associated headers of the corresponding fuzz sources. For example, src/test/fuzz/protocol.cpp and src/protocol.h. However, they are not, because the fuzz sources contain no definitions for any declarations from those headers.

This, in turn, requires adding includes to some non-fuzz sources for headers that were previously included transitively.

I think it would be easier if the header changes are addition-only for now?

I'm going to split out the non-fuzz changes so that they can be reviewed separately.

This makes the list easier to read and extend, and keeps diffs
minimal when files are added.
Fix IWYU warnings in the following source files and their associated
headers, and add them to `IWYU_SRC_FILES`, so that any new warnings
there fail CI:
- chain.cpp
- headerssync.cpp
- key_io.cpp
- merkleblock.cpp
- pow.cpp

The changes in other files add includes of headers that were previously
included transitively.
@DrahtBot

DrahtBot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

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