From 9689a4f58a09cf8c3f9094085a8243b8db4b0ded Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 31 Oct 2024 21:29:13 -0400 Subject: [PATCH] Internals: Support VL_UNREACHABLE in C++23/MSVC. No functional change intended. --- include/verilatedos.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/include/verilatedos.h b/include/verilatedos.h index 6cb83732f..f633a0f32 100644 --- a/include/verilatedos.h +++ b/include/verilatedos.h @@ -67,11 +67,21 @@ # endif # define VL_LIKELY(x) __builtin_expect(!!(x), 1) // Prefer over C++20 [[likely]] # define VL_UNLIKELY(x) __builtin_expect(!!(x), 0) // Prefer over C++20 [[unlikely]] -# define VL_UNREACHABLE __builtin_unreachable() // C++23 std::unreachable() # define VL_PREFETCH_RD(p) __builtin_prefetch((p), 0) # define VL_PREFETCH_RW(p) __builtin_prefetch((p), 1) #endif +#ifdef __cpp_lib_unreachable +/// Statement that may never be reached (for coverage etc) +# define VL_UNREACHABLE std::unreachable() // C++23 +#elif defined(__GNUC__) +# define VL_UNREACHABLE __builtin_unreachable() +#elif defined(_MSC_VER) // MSVC +# define VL_UNREACHABLE __assume(false) +#else +# define VL_UNREACHABLE +#endif + // Function acquires a capability/lock (-fthread-safety) #define VL_ACQUIRE(...) \ VL_CLANG_ATTR(annotate("ACQUIRE")) \ @@ -179,9 +189,6 @@ #endif /// Boolean expression never hit by users (branch coverage disabled) # define VL_UNCOVERABLE(x) VL_UNLIKELY(x) -#ifndef VL_UNREACHABLE -# define VL_UNREACHABLE ///< Statement that may never be reached (for coverage etc) -#endif #ifndef VL_PREFETCH_RD # define VL_PREFETCH_RD(p) ///< Prefetch pointer argument with read intent #endif