AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Informational 21 Bitcoin

Merge bitcoin/bitcoin#36087: util: Add and use AssertUnreachable

Public commit record

What the developer wrote

Authored by Ryan Ofsky

100/100 · Strong
Merge bitcoin/bitcoin#36087: util: Add and use AssertUnreachable

fa9a4ddbaf16d7fc8f8c336600674b3c7facca16 test: Add assert_falsy linter, And use AssertUnreachable (MarcoFalke)
fa20a5c7059c0d1cfd84a24e101d399f57771092 scripted-diff: Replace falsy assertions with AssertUnreachable (MarcoFalke)
fa6b4604e8c0cb48a13f8daa1ac61630114f35c2 test: Remove unused includes in util_tests.cpp (MarcoFalke)
fa1574cdaaeb8b0fad2eeb394a594a3534ee650c refactor: Use AssertUnreachable() and remove dead code (MarcoFalke)
fa81e4700a9495b7216580da151f36674b5affde util: Add AssertUnreachable (MarcoFalke)
fa1c93477e6ac332219af3eb4c6a5fcc9434105d refactor: Replace unreachable run-time assert with compile time assert (MarcoFalke)

Pull request description:

The current code uses assertions with falsy literal values in a few places. This is perfectly fine, but this comes with a bit of confusion sometimes:

* `assert(false)` may cause confusion when it is unclear if `NDEBUG` can disable it. (The intention is to disallow `NDEBUG` compilation). Also, it can lead to warnings when used with clang-cl.exe (GCC seems to understand it)
* `Assert(false)` hides the noreturn attribute behind a function call, which may cause GCC return-type warnings. (Clang seems to understand it)

See https://godbolt.org/z/h7PT3jh3Y for the clang-cl/GCC warning reproducer.

* When C++23 will be allowed, devs may prefer `std::unreachable`. However, this is unsafe and will invoke UB.
* There is confusion why a `CHECK_NONFATAL` macro exists, but no fatal equivalent.

Fix all those issues by:

* Adding a new `AssertUnreachable`, which directly calls the noreturn `internal_abort_helper` helper.
* Adding an `assert_falsy` linter to enforce code to use this macro.

ACKs for top commit:
jeanpablojp:
tACK fa9a4ddbaf16d7fc8f8c336600674b3c7facca16
l0rinc:
ACK fa9a4ddbaf16d7fc8f8c336600674b3c7facca16
hodlinator:
re-ACK fa9a4ddbaf16d7fc8f8c336600674b3c7facca16
ryanofsky:
Code review ACK fa9a4ddbaf16d7fc8f8c336600674b3c7facca16. Nice cleanup making code more consistent, and I like the clever approach to updating includes in the scripted-diff

Tree-SHA512: c9c1fda9458d0fea0d9828dd48a1d58cf2000fc79d4141e004d8b15fc0ceab3835fdd7cb1ac422858739dc8cc974e40e7e2aa085d21d39a34ccbf7c91042a2dd
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This is a code-cleanup change in Bitcoin Core. It replaces many uses of `assert(false)` and similar 'this should never happen' markers with a new macro called `AssertUnreachable()`. The goal is to make the code clearer for developers and avoid compiler warnings, not to fix a security bug that an attacker could exploit. The change does not alter what the program does when it reaches one of these unreachable points: it still aborts immediately.

Recommended action

No security action required. Treat as normal code-quality/maintenance refactor. Reviewers may verify that `AssertUnreachable()` is defined as noreturn and that no reachable code paths were accidentally converted.

Security signals we found

01

No security-relevant functional change: process still aborts on unreachable paths

02

Refactor only: replaces one abort mechanism with another equivalent one

03

Adds a new lint rule to enforce the preferred macro going forward

04

No input validation, memory safety, or consensus logic changes observed

Risk score

Why this scored 21/100

Our methodology →
Potential impact 2/30
Exploitability 0/25
Stealth signal 0/15
Affected reach 5/15
Confidence 9/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.