Skip to content

Commit

Permalink
Fix _LIBCUDACXX_UNREACHABLE for old MSVC (#1114) (#1143)
Browse files Browse the repository at this point in the history
MSVC2017 / 2019 have issues properly determining that `__assume(0)` is indeed meant to mean unreachable code and complains about missing return statement sometimes.

We can work around this by wrapping it into a `__declspec(noreturn)` function 🤷

Addresses nvbug4359466
  • Loading branch information
miscco authored Nov 29, 2023
1 parent 87ff155 commit 3dd0c5b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions libcudacxx/include/cuda/std/detail/libcxx/include/cstdlib
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ void *aligned_alloc(size_t alignment, size_t size); // C11
# define _LIBCUDACXX_UNREACHABLE() __builtin_unreachable()
#endif // CUDACC above 11.4
#else // ^^^ __CUDA_ARCH__ ^^^ / vvv !__CUDA_ARCH__ vvv
#if defined(_LIBCUDACXX_COMPILER_MSVC)
# define _LIBCUDACXX_UNREACHABLE() __assume(false)
#if defined(_LIBCUDACXX_COMPILER_MSVC_2017)
template<class = void>
_LIBCUDACXX_INLINE_VISIBILITY __declspec(noreturn) void __unreachable_fallback() { __assume(0); }
# define _LIBCUDACXX_UNREACHABLE() __unreachable_fallback()
#elif defined(_LIBCUDACXX_COMPILER_MSVC)
# define _LIBCUDACXX_UNREACHABLE() __assume(0)
#elif defined(_LIBCUDACXX_COMPILER_GCC) || __has_builtin(__builtin_unreachable)
# define _LIBCUDACXX_UNREACHABLE() __builtin_unreachable()
#else // Other compilers
Expand Down

0 comments on commit 3dd0c5b

Please sign in to comment.