Skip to content

Commit 4778e40

Browse files
committed
Clarify use of llvm_unreachable in the coding standard.
There has been some ongoing confusion regarding when to use `llvm_unreachable` which this patch attempts to address. Specifically, the confusion has been around whether `llvm_unreachable` is intended to mark only unreachable code paths that the compiler cannot determine itself or to mark a code path which is unconditionally a bug to reach. Based on email and IRC discussions, it sounds like "unconditional bug to reach" is the consensus.
1 parent 0767732 commit 4778e40

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

llvm/docs/CodingStandards.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,13 @@ builds), ``llvm_unreachable`` becomes a hint to compilers to skip generating
11531153
code for this branch. If the compiler does not support this, it will fall back
11541154
to the "abort" implementation.
11551155

1156+
Use ``llvm_unreachable`` to mark a specific point in code that should never be
1157+
reached. This is especially desirable for addressing warnings about unreachable
1158+
branches, etc., but can be used whenever reaching a particular code path is
1159+
unconditionally a bug (not originating from user input; see below) of some kind.
1160+
Use of ``assert`` should always include a testable predicate (as opposed to
1161+
``assert(false)``).
1162+
11561163
Neither assertions or ``llvm_unreachable`` will abort the program on a release
11571164
build. If the error condition can be triggered by user input then the
11581165
recoverable error mechanism described in :doc:`ProgrammersManual` should be

0 commit comments

Comments
 (0)