[libcxx-commits] [PATCH] D119152: [libc++] Implement P0627R6 (Function to mark unreachable code)
Martin Storsjö via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Feb 7 13:49:51 PST 2022
mstorsjo added inline comments.
================
Comment at: libcxx/include/__utility/unreachable.h:18
+
+[[noreturn]] _LIBCPP_HIDE_FROM_ABI inline void unreachable() { __builtin_unreachable(); }
+
----------------
Quuxplusone wrote:
> @ldionne @mstorsjo perhaps: What's the best way to get this to do `__assume(false)` on MSVC? Should we introduce a `__libcpp_unreachable()`?... Oh wait, we already have one. In `libcxx/include/cstdlib` we have:
> ```
> #ifdef __GNUC__
> #define _LIBCPP_UNREACHABLE() __builtin_unreachable()
> #else
> #define _LIBCPP_UNREACHABLE() _VSTD::abort()
> #endif
> ```
> Let's do something in this PR to normalize the situation. Perhaps involving `__has_builtin`, perhaps involving `defined(_MSC_VER)`, but the end result should be that libc++'s `std::unreachable` is implemented in terms of `_LIBCPP_UNREACHABLE`.
FWIW, in practice, all our cases of "MSVC" in our codebase is clang-cl only, as libcxx isn't usable with MSVC proper - so even in an MSVC/non-GNUC config, it would end up supporting Clang's builtins.
(But a `__has_builtin` check doesn't hurt of course - and might be needed for other non-Clang, non-GCC compilers, if we support any such).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119152/new/
https://reviews.llvm.org/D119152
More information about the libcxx-commits
mailing list