[PATCH] D76721: Clarify use of llvm_unreachable in the coding standard

Aaron Ballman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 24 12:22:05 PDT 2020


aaron.ballman created this revision.
aaron.ballman added reviewers: dblaikie, joerg, lhames, craig.topper.

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.


https://reviews.llvm.org/D76721

Files:
  llvm/docs/CodingStandards.rst


Index: llvm/docs/CodingStandards.rst
===================================================================
--- llvm/docs/CodingStandards.rst
+++ llvm/docs/CodingStandards.rst
@@ -1153,6 +1153,12 @@
 code for this branch. If the compiler does not support this, it will fall back
 to the "abort" implementation.
 
+Use ``llvm_unreachable`` to mark a specific point in code that should never be
+reached. This is especially desirable for addressing warnings about unreachable
+branches, etc., but can be used whenever reaching a particular code path is
+unconditionally a bug of some kind. Use of ``assert`` should always include a
+testable predicate (as opposed to ``assert(false)``).
+
 Neither assertions or ``llvm_unreachable`` will abort the program on a release
 build. If the error condition can be triggered by user input then the
 recoverable error mechanism described in :doc:`ProgrammersManual` should be


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76721.252389.patch
Type: text/x-patch
Size: 912 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200324/44558748/attachment.bin>


More information about the llvm-commits mailing list