|
| 1 | +//== ----------------<assert.h> wrapper around STL--------------------------==// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +// Must not be guarded. C++ standard says the macro assert is redefined |
| 10 | +// according to the current state of NDEBUG each time that <cassert> is |
| 11 | +// included. |
| 12 | + |
| 13 | +#if defined(__has_include_next) |
| 14 | +#include_next <assert.h> |
| 15 | +#else |
| 16 | +#include <../ucrt/assert.h> |
| 17 | +#endif |
| 18 | + |
| 19 | +#ifdef __SYCL_DEVICE_ONLY__ |
| 20 | +#include <CL/__spirv/spirv_vars.hpp> |
| 21 | + |
| 22 | +// Device assertions on Windows do not work properly so we define these wrappers |
| 23 | +// around the STL assertion headers cassert and assert.h where we redefine |
| 24 | +// the assert macro to call __devicelib_assert_fail directly and bypass |
| 25 | +// _wassert. |
| 26 | +#if defined(_WIN32) && defined(assert) |
| 27 | +extern "C" __DPCPP_SYCL_EXTERNAL void |
| 28 | +__devicelib_assert_fail(const char *, const char *, int32_t, const char *, |
| 29 | + uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, |
| 30 | + uint64_t); |
| 31 | +#undef assert |
| 32 | +#if defined(NDEBUG) |
| 33 | +#define assert(e) ((void)0) |
| 34 | +#else |
| 35 | +#define assert(e) \ |
| 36 | + ((e) ? void(0) \ |
| 37 | + : __devicelib_assert_fail( \ |
| 38 | + #e, __FILE__, __LINE__, nullptr, __spirv_GlobalInvocationId_x(), \ |
| 39 | + __spirv_GlobalInvocationId_y(), __spirv_GlobalInvocationId_z(), \ |
| 40 | + __spirv_LocalInvocationId_x(), __spirv_LocalInvocationId_y(), \ |
| 41 | + __spirv_LocalInvocationId_z())) |
| 42 | +#endif |
| 43 | +#endif |
| 44 | +#endif |
0 commit comments