[PATCH] D121750: Add a cmake flag to turn `llvm_unreachable()` into builtin_trap() when assertions are disabled

Duncan P. N. Exon Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 16 20:03:10 PDT 2022


dexonsmith accepted this revision.
dexonsmith added a comment.
This revision is now accepted and ready to land.

It feels to me like this is worth documenting in llvm/docs/CMake.rst, maybe next to `LLVM_ABI_BREAKING_CHECKS` since they both seem assertion related, so that it's more easily discovered.

Otherwise, LGTM, with more wording suggestion inline.



================
Comment at: llvm/CMakeLists.txt:468
 option(LLVM_ENABLE_DUMP "Enable dump functions even when assertions are disabled" OFF)
+option(LLVM_UNREACHABLE_OPTIMIZE "Whether llvm_unreachable() should be considered undefined behavior (default) or instead trap when assertions are disabled" ON)
 
----------------
I wonder if the wording should be tied to the word "optimize". Also, note that trapping is a legit implementation of undefined behaviour; so another interpretation is that `llvm_unreachable()` is being treated as UB either way.

E.g.:

> A "reached" llvm_unreachable() is undefined behaviour; ON optimizes the unreachable control flow (default), while OFF triggers a guaranteed trap

WDYT?
(I'm okay with landing the wording as you had it if you prefer it; can always update it later)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121750/new/

https://reviews.llvm.org/D121750



More information about the llvm-commits mailing list