brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 2708325 Raw
62 lines · c
1// libstdc++ uses the non-constexpr function std::__glibcxx_assert_fail()2// to trigger compilation errors when the __glibcxx_assert(cond) macro3// is used in a constexpr context.4// Compilation fails when using code from the libstdc++ (such as std::array) on5// device code, since these assertions invoke a non-constexpr host function from6// device code.7//8// To work around this issue, we declare our own device version of the function9 10#ifndef __CLANG_CUDA_WRAPPERS_BITS_CPP_CONFIG11#define __CLANG_CUDA_WRAPPERS_BITS_CPP_CONFIG12 13#include_next <bits/c++config.h>14 15#ifdef _LIBCPP_BEGIN_NAMESPACE_STD16_LIBCPP_BEGIN_NAMESPACE_STD17#else18namespace std {19#ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION20_GLIBCXX_BEGIN_NAMESPACE_VERSION21#endif22 23#pragma push_macro("CUDA_NOEXCEPT")24#if __cplusplus >= 201103L25#define CUDA_NOEXCEPT noexcept26#else27#define CUDA_NOEXCEPT28#endif29 30__attribute__((device, noreturn)) inline void31__glibcxx_assert_fail(const char *file, int line, const char *function,32                      const char *condition) CUDA_NOEXCEPT {33#ifdef _GLIBCXX_VERBOSE_ASSERT34  if (file && function && condition)35    __builtin_printf("%s:%d: %s: Assertion '%s' failed.\n", file, line,36                     function, condition);37  else if (function)38    __builtin_printf("%s: Undefined behavior detected.\n", function);39#endif40  __builtin_abort();41}42 43#endif44__attribute__((device, noreturn, __always_inline__,45               __visibility__("default"))) inline void46__glibcxx_assert_fail() CUDA_NOEXCEPT {47  __builtin_abort();48}49 50#pragma pop_macro("CUDA_NOEXCEPT")51 52#ifdef _LIBCPP_END_NAMESPACE_STD53_LIBCPP_END_NAMESPACE_STD54#else55#ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION56_GLIBCXX_END_NAMESPACE_VERSION57#endif58} // namespace std59#endif60 61#endif62