Skip to content

Commit 1d3074d

Browse files
[SYCL] Add _invoke_watson to corecrt STL wrapper (#19897)
**Problem** `Basic/std_array.cpp` fails to compile with MSVC 19.44.35207.1 with the following error ``` $ ./clang-cl.exe -fsycl -D_DEBUG -fsycl-device-only ./sycl/test-e2e/Basic/std_array.cpp /Od /MDd /Zi /EHsc In file included from ../../sycl/test-e2e/Basic/std_array.cpp:8: In file included from D:\iusers\uagarwal\llvm\build\bin\..\include\sycl/queue.hpp:12: In file included from D:\iusers\uagarwal\llvm\build\bin\..\include\sycl/accessor.hpp:12: In file included from D:\iusers\uagarwal\llvm\build\bin\..\include\sycl/buffer.hpp:14: In file included from D:\iusers\uagarwal\llvm\build\bin\..\include\sycl/detail/common.hpp:17: c:/Program files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.44.35207/include\array(531,9): error: SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute 531 | _STL_VERIFY(_Pos < _Size, "array subscript out of range"); | ^ c:/Program files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.44.35207/include\yvals.h(259,9): note: expanded from macro '_STL_VERIFY' 259 | _STL_REPORT_ERROR(mesg); \ | ^ c:/Program files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.44.35207/include\yvals.h(255,5): note: expanded from macro '_STL_REPORT_ERROR' 255 | _MSVC_STL_DOOM_FUNCTION(mesg) | ^ c:/Program files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.44.35207/include\yvals.h(249,41): note: expanded from macro '_MSVC_STL_DOOM_FUNCTION' 249 | #define _MSVC_STL_DOOM_FUNCTION(mesg) ::_invoke_watson(nullptr, nullptr, nullptr, 0, 0) | ^ c:/Program files (x86)/Windows Kits/10/include/10.0.26100.0/ucrt\corecrt.h(375,23): note: '_invoke_watson' declared here 375 | _ACRTIMP void __cdecl _invoke_watson( | ^ c:/Program files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.44.35207/include\array(529,39): note: called by 'operator[]' 529 | _NODISCARD _CONSTEXPR17 reference operator[](_In_range_(<, _Size) size_type _Pos) noexcept /* strengthened */ { | ^ 1 error generated. ``` **Solution** Similar to what we did for `_invalid_parameter` (#18400), mock `_invoke_watson` in corecrt STL wrapper.
1 parent f6d9a8b commit 1d3074d

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

sycl/include/sycl/stl_wrappers/corecrt.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,16 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// When std::array is used in device code, MSVC's STL uses a _invalid_parameter
10-
// function. This causes issue when _invalid_parameter is invoked from device
11-
// code:
9+
// MSVC's STL emits functions like _invalid_parameter and _invoke_watson
10+
// to validate parameters passed to STL containers, like std::array, when
11+
// compiled in debug mode.
12+
// STL containers when used in device code fails to compile on Windows
13+
// because these functions are not marked with SYCL_EXTERNAL attribute.
1214

13-
// 1. `_invalid_parameter` is provided via ucrtbased.dll at runtime: DLLs are
14-
// not loaded for device code, thus causing undefined symbol errors.
15-
16-
// 2. MSVC's STL never defined the function as SYCL_EXTERNAL, errors are thrown
17-
// when device code tries to invoke `_invalid_parameter`.
18-
19-
// As a workaround, this wrapper wraps around corecrt.h and defines a custom
20-
// _invalid_parameter for device code compilation.
21-
22-
// This new SYCL_EXTERNAL definition of _invalid_parameter has to be declared
23-
// before corecrt.h is included: Thus, we have this STL wrapper instead of
24-
// declaring _invalid_parameter function in SYCL headers.
15+
// As a workaround, this wrapper defines a custom, empty defination of
16+
// _invalid_parameter and _invoke_watson for device code.
17+
// MSVC picks up these definitions instead of the declarations from MSVC's
18+
// <corecrt> header.
2519

2620
#pragma once
2721

@@ -36,6 +30,12 @@ extern "C" inline void __cdecl _invalid_parameter(wchar_t const *,
3630
// Do nothing when called in device code
3731
}
3832

33+
extern "C" __declspec(noreturn) void __cdecl _invoke_watson(
34+
wchar_t const *const expression, wchar_t const *const function_name,
35+
wchar_t const *const file_name, unsigned int const line_number,
36+
uintptr_t const reserved) {
37+
// Do nothing.
38+
}
3939
#endif
4040

4141
#if defined(__has_include_next)

0 commit comments

Comments
 (0)