Skip to content

Commit 17b287a

Browse files
[SYCL] Add STL wrapper for crtdbg.h and define _CrtDbgReport (#18213)
Wrapping around because want to define `_CrtDbgReport` before `crtdbg.h` header is included. Defining variable templated `_CrtDbgReport` overrides the use of variable argument `_CrtDbgReport` function, that declared in `crtdbg.h`. With variable argument `_CrtDbgReport`, `llvm-spirv` throws the following error: ``` UnsupportedVarArgFunction: Variadic functions other than 'printf' are not supported in SPIR-V. ``` Fixes CMPLRLLVM-66787 --------- Signed-off-by: Agarwal, Udit <[email protected]>
1 parent 68888f6 commit 17b287a

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

sycl/test/regression/std_array_vec_constructor.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
// the constructor.
33
// REQUIRES: windows
44

5-
// RUN: not %clangxx -O0 -fsycl -D_DEBUG -shared %s &> %t.compile.log
6-
// RUN: FileCheck %s -input-file=%t.compile.log
5+
// RUN: %clangxx -O0 -fsycl -D_DEBUG -shared %s -nostdlib -Xclang --dependent-lib=msvcrtd -fms-runtime-lib=dll_dbg
76

87
#include <sycl/sycl.hpp>
98

109
using namespace sycl::ext::oneapi::experimental;
1110

12-
// CHECK: UnsupportedVarArgFunction: Variadic functions other than 'printf' are not supported in SPIR-V.
13-
// CHECK: clang{{.*}} error: llvm-spirv command failed with exit code 23{{.*}}
1411
auto Reproducer(sycl::queue q, sampled_image_handle imgHanlde) {
1512
return q.submit([&](sycl::handler &cg) {
1613
cg.parallel_for(

0 commit comments

Comments
 (0)