build: enable -Wunreachable-code-aggressive #36623

Manually merged
fanquake merged 2 commits from unreachable_aggressive into master 2026-11-06 13:12:41 +00:00 AGit
fanquake commented 2026-10-23 14:12:03 +00:00 (Migrated from github.com)

Swap -Wunreachable-code for -Wunreachable-code-aggressive, which also enables -Wunreachable-code-return and -Wunreachable-code-break.

Swap `-Wunreachable-code` for `-Wunreachable-code-aggressive`, which also enables `-Wunreachable-code-return` and `-Wunreachable-code-break`.
DrahtBot commented 2026-10-23 14:12:15 +00:00 (Migrated from github.com)

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.

Type Reviewers
ACK willcl-ark, sedited, hodlinator, maflcko

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #31507 (build: Use clang-cl to build on Windows natively by hebasto)

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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36623 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36623.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36623#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [willcl-ark](https://github.com/bitcoin/bitcoin/pull/36623#pullrequestreview-5800040696), [sedited](https://github.com/bitcoin/bitcoin/pull/36623#pullrequestreview-5800232653), [hodlinator](https://github.com/bitcoin/bitcoin/pull/36623#pullrequestreview-5800243583), [maflcko](https://github.com/bitcoin/bitcoin/pull/36623#issuecomment-6685473069) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#31507](https://github.com/bitcoin/bitcoin/pull/31507) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/31507.svg"></sub> (build: Use clang-cl to build on Windows natively by hebasto) 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. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

No verified findings are available from this review.

Review coverage was incomplete.


Reviewed: 1f69c5cfdd9a · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:daf186ee011f67c6e091cbd963c278787a81add1d217f5e6cd9a897f597908a5:b3906d5974a831cf25d9d4076421aeb88934ca1265895f22224d53119372abb5 --> <!-- ralph-base:f12cc4aed14d4e96178c361d6846217eca993e59 --> <!-- ralph-head:1f69c5cfdd9a21e03bedcb4edd14c4fb13954b7c --> <!-- ralph-case:57a90b7318b7e4e073f75e85939a05260fff8175f43e6c2a3153dc9ec36653a2 --> No verified findings are available from this review. Review coverage was incomplete. <!-- Review tier: standard --> --- Reviewed: [`1f69c5cfdd9a`](<https://git.fish.foo/bitcoin/bitcoin/commit/1f69c5cfdd9a21e03bedcb4edd14c4fb13954b7c>) · [Full review report](<https://review.fish.foo/traces/36623-1f69c5cfdd9a21e03bedcb4edd14c4fb13954b7c-2299-6.html>) · [Previous reports](<https://review.fish.foo/traces/36623/>) [permalink](<https://review.fish.foo/traces/36623-1f69c5cfdd9a21e03bedcb4edd14c4fb13954b7c-2299-6.html>)
willcl-ark (Migrated from github.com) reviewed 2026-10-23 14:57:25 +00:00
willcl-ark (Migrated from github.com) commented 2026-10-23 14:57:25 +00:00

It does appear that this is likely removable too.

It does appear that this is likely removable too.
DrahtBot commented 2026-10-23 15:20:12 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/actions/runs/39967612158/job/120461497226
LLM reason (✨ experimental): CI failed the subtree lint check because the LevelDB and minisketch subtrees were modified without a subtree merge.

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.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `lint`: https://github.com/bitcoin/bitcoin/actions/runs/39967612158/job/120461497226</sub> <sub>LLM reason (✨ experimental): CI failed the subtree lint check because the LevelDB and minisketch subtrees were modified without a subtree merge.</sub> <details><summary>Hints</summary> 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. </details>
fanquake (Migrated from github.com) reviewed 2026-10-30 15:36:25 +00:00
fanquake (Migrated from github.com) commented 2026-10-30 15:36:25 +00:00

Happy to do what reviewers prefer here.

Happy to do what reviewers prefer here.
hodlinator (Migrated from github.com) reviewed 2026-10-31 09:08:58 +00:00
hodlinator (Migrated from github.com) commented 2026-10-31 09:08:58 +00:00

FWIW the least worst solution to me seems to be removing the break together with the braces, so this case gets formatting like the default at the end:
github.com/bitcoin/bitcoin@15ba42294e/src/script/interpreter.cpp (L1227-L1228)

--- a/src/script/interpreter.cpp
+++ b/src/script/interpreter.cpp
@@ -675,18 +675,7 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
                 break;
 
                 case OP_RETURN:
-                {
                     return set_error(serror, SCRIPT_ERR_OP_RETURN);
-                }
-#if defined(__clang__)
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunreachable-code-break"
-#endif
-                break;
-#if defined(__clang__)
-#pragma clang diagnostic pop
-#endif
-
 
                 //
                 // Stack ops
FWIW the least worst solution to me seems to be removing the break together with the braces, so this `case` gets formatting like the `default` at the end: https://github.com/bitcoin/bitcoin/blob/15ba42294eb57bd4850da0a830741c35aa8b46cc/src/script/interpreter.cpp#L1227-L1228 ```diff --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -675,18 +675,7 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& break; case OP_RETURN: - { return set_error(serror, SCRIPT_ERR_OP_RETURN); - } -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code-break" -#endif - break; -#if defined(__clang__) -#pragma clang diagnostic pop -#endif - // // Stack ops ```
DrahtBot commented 2026-11-04 12:55:46 +00:00 (Migrated from github.com)

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

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
willcl-ark (Migrated from github.com) reviewed 2026-11-06 10:04:27 +00:00
willcl-ark (Migrated from github.com) commented 2026-11-06 10:04:27 +00:00

OK I pointed Astra at this to try and get more guarantees around removal...

It compiled the interpreter translation unit before and after removing this break, using GCC 15.3.0 and Clang 19.1.7 at both -O0 and -O2 (as we use in Guix builds), with assertions enabled.

All four pairs produced byte-identical object files when preserving the newline. Deleting the whole line changed only assertion diagnostic line numbers.

Clanker's full report.

This further supports removing the unreachable break IMO.

OK I pointed Astra at this to try and get more guarantees around removal... It compiled the interpreter translation unit before and after removing this `break`, using GCC 15.3.0 and Clang 19.1.7 at both `-O0` and `-O2` (as we use in Guix builds), with assertions enabled. **All four pairs produced byte-identical object files when preserving the newline.** Deleting the whole line changed only assertion diagnostic line numbers. [Clanker's full report](https://gist.github.com/willcl-ark/4643419ce01108779d587a7e7ecced35). This further supports removing the unreachable `break` IMO.
fanquake (Migrated from github.com) reviewed 2026-11-06 10:18:41 +00:00
fanquake (Migrated from github.com) commented 2026-11-06 10:18:41 +00:00

I might swap to that once rebased for #36783.

I might swap to that once rebased for #36783.
fanquake commented 2026-11-06 11:27:18 +00:00 (Migrated from github.com)

Rebased past #36783 and took @hodlinator's diff.

Rebased past #36783 and took @hodlinator's diff.
fanquake (Migrated from github.com) reviewed 2026-11-06 11:28:02 +00:00
fanquake (Migrated from github.com) commented 2026-11-06 11:28:02 +00:00

Now that I've taken the diff, I'm going to mark this as resolved, so review can restart in a clean thread.

Now that I've taken the diff, I'm going to mark this as resolved, so review can restart in a clean thread.
willcl-ark (Migrated from github.com) approved these changes 2026-11-06 12:25:23 +00:00
willcl-ark (Migrated from github.com) left a comment

ACK 1f69c5cfdd

Reviewed the updated diff and had me clanker rerun GCC/Clang object comparisons at -O0 and -O2. The interpreter changes only assertion diagnostic line numbers, and preserving those gives byte-identical objects.

Also prefer hodlinator’s formatting in interpreter.cpp as the braces serve no scoping purpose and removing them makes the unconditional return clearer IMO.

ACK 1f69c5cfdd9a21e03bedcb4edd14c4fb13954b7c Reviewed the updated diff and had me clanker rerun GCC/Clang object comparisons at -O0 and -O2. The interpreter changes only assertion diagnostic line numbers, and preserving those gives byte-identical objects. Also prefer hodlinator’s formatting in interpreter.cpp as the braces serve no scoping purpose and removing them makes the unconditional return clearer IMO.
sedited (Migrated from github.com) approved these changes 2026-11-06 12:44:10 +00:00
sedited (Migrated from github.com) left a comment
ACK 1f69c5cfdd9a21e03bedcb4edd14c4fb13954b7c
hodlinator (Migrated from github.com) approved these changes 2026-11-06 12:45:15 +00:00
hodlinator (Migrated from github.com) left a comment

crACK 1f69c5cfdd

crACK 1f69c5cfdd9a21e03bedcb4edd14c4fb13954b7c
maflcko commented 2026-11-06 13:04:40 +00:00 (Migrated from github.com)

lgtm. Should be fine for this codebase, as we already require "unreachable" code to be marked with an abort instead of UB.

review ACK 1f69c5cfdd 🐟

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: review ACK 1f69c5cfdd9a21e03bedcb4edd14c4fb13954b7c 🐟
RfKjLyaCfQSFPVwu0TlGLLPf3EMPNdZy51M+nj4gPNvoeybfInb/vw1Hu6UbbM7kWvcAbc8ERY2+j1y1TsCwAQ==
lgtm. Should be fine for this codebase, as we already require "unreachable" code to be marked with an abort instead of UB. review ACK 1f69c5cfdd9a21e03bedcb4edd14c4fb13954b7c 🐟 <details><summary>Show signature</summary> 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: review ACK 1f69c5cfdd9a21e03bedcb4edd14c4fb13954b7c 🐟 RfKjLyaCfQSFPVwu0TlGLLPf3EMPNdZy51M+nj4gPNvoeybfInb/vw1Hu6UbbM7kWvcAbc8ERY2+j1y1TsCwAQ== ``` </details>
l0rinc commented 2026-11-06 17:09:16 +00:00 (Migrated from github.com)

Post-merge ACK 1f69c5cfdd

Trivial change: applying the following whitespace-only patch gives byte-identical assembly with GCC/Clang - can't be simpler than this.

Patch
diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp
--- a/src/script/interpreter.cpp
+++ b/src/script/interpreter.cpp
@@ -675,7 +675,11 @@
                 break;
 
                 case OP_RETURN:
+
                     return set_error(serror, SCRIPT_ERR_OP_RETURN);
+
+
+
 
                 //
                 // Stack ops
Post-merge ACK 1f69c5cfdd9a21e03bedcb4edd14c4fb13954b7c Trivial change: applying the following whitespace-only patch gives byte-identical assembly with GCC/Clang - can't be simpler than this. <details><summary>Patch</summary> ```diff diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -675,7 +675,11 @@ break; case OP_RETURN: + return set_error(serror, SCRIPT_ERR_OP_RETURN); + + + // // Stack ops ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36623
No description provided.