|
| 1 | +//==---------------- Wrapper around crtdbg.h ------------------------------==// |
| 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 | +// When std::array is used in device code, MSVC's STL uses _CrtDbgReport |
| 10 | +// function with variable arguments, when compiled in debug mode (-D_DEBUG |
| 11 | +// flag). |
| 12 | + |
| 13 | +// Variable argument functions are not supported in SPIR-V, and the compilation |
| 14 | +// fails with llvm-spirv error: UnsupportedVarArgFunction: Variadic functions |
| 15 | +// other than 'printf' are not supported in SPIR-V. |
| 16 | + |
| 17 | +// As a workaround, in this wrapper, we define our own variable templated |
| 18 | +// _CrtDbgReport which overrides the variable argument _CrtDbgReport function |
| 19 | +// declaration in crtdbg.h. |
| 20 | + |
| 21 | +// The variable templated _CrtDbgReport function has to be declared before the |
| 22 | +// crtdbg.h header is included, and that's why we have this STL wrapper instead |
| 23 | +// of declaring the _CrtDbgReport function in SYCL headers. |
| 24 | + |
| 25 | +#pragma once |
| 26 | + |
| 27 | +#if defined(__SYCL_DEVICE_ONLY__) |
| 28 | +template <typename... Ts> int _CrtDbgReport(Ts...) { return 0; } |
| 29 | +#endif |
| 30 | + |
| 31 | +#if defined(__has_include_next) |
| 32 | +// GCC/clang support go through this path. |
| 33 | +#include_next <crtdbg.h> |
| 34 | +#else |
| 35 | +// MSVC doesn't support "#include_next", so we have to be creative. |
| 36 | +// Our header is located in "stl_wrappers/crtdbg.h" so it won't be picked by the |
| 37 | +// following include. MSVC's installation, on the other hand, has the layout |
| 38 | +// where the following would result in the <crtdbg.h> we want. This is obviously |
| 39 | +// hacky, but the best we can do... |
| 40 | +#include <../ucrt/crtdbg.h> |
| 41 | +#endif |
0 commit comments