Skip to content

Commit 2cefad1

Browse files
[SYCL] Fix deprecation warning for headers (intel#6808)
Using pragmas to emit warnings didn't work because SYCL headers are considered to be system headers and any warnings in them are suppressed. Use "#warning" instead. Unfortunately, MSVC doesn't support it (although it's part of C23/C++23 and they'll have to add support eventually), so we need some #if guards. Also, #warning cannot be put inside a macro definition, thus we have to have some code duplication. Luckily, entire headers deprecations aren't as often and we can be a little bit verbose.
1 parent f7fd9a1 commit 2cefad1

File tree

6 files changed

+29
-20
lines changed

6 files changed

+29
-20
lines changed

sycl/include/sycl/backend/cuda.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@
1111

1212
#include <sycl/detail/defines_elementary.hpp>
1313

14-
__SYCL_WARNING("sycl/backend/cuda.hpp is deprecated and no required anymore")
14+
#if !defined(_MSC_VER) || defined(__clang__)
15+
// MSVC doesn't support #warning and we cannot use other methods to report a
16+
// warning from inside a system header (which SYCL is considered to be).
17+
#warning sycl/backend/cuda.hpp is deprecated and not required anymore
18+
#endif

sycl/include/sycl/backend/level_zero.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
#include <sycl/detail/defines_elementary.hpp>
1212

13-
__SYCL_WARNING("sycl/backend/level_zero.hpp usage is deprecated, include "
14-
"sycl/ext/oneapi/backend/level_zero.hpp instead")
13+
#if !defined(_MSC_VER) || defined(__clang__)
14+
// MSVC doesn't support #warning and we cannot use other methods to report a
15+
// warning from inside a system header (which SYCL is considered to be).
16+
#warning sycl/backend/level_zero.hpp usage is deprecated, include \
17+
sycl/ext/oneapi/backend/level_zero.hpp instead
18+
#endif
1519

1620
#include <sycl/ext/oneapi/backend/level_zero.hpp>

sycl/include/sycl/detail/defines_elementary.hpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,5 @@
9292
#define __SYCL_STRINGIFY(x) #x
9393
#endif // __SYCL_STRINGIFY
9494

95-
// define __SYCL_WARNING convenience macro to report compiler warnings
96-
#if defined(__GNUC__)
97-
#define __SYCL_WARNING(msg) _Pragma(__SYCL_STRINGIFY(GCC warning msg))
98-
#elif defined(_MSC_VER) && !defined(__clang__)
99-
#define __SYCL_QUOTE1(x) #x
100-
#define __SYCL_QUOTE(x) __SYCL_QUOTE1(x)
101-
#define __SYCL_SRC_LOC __FILE__ ":" __SYCL_QUOTE(__LINE__)
102-
#define __SYCL_WARNING(msg) __pragma(message(__SYCL_SRC_LOC " warning: " msg))
103-
#else // clang et. al.
104-
// clang emits "warning:" in the message pragma output
105-
#define __SYCL_WARNING(msg) __pragma(message(msg))
106-
#endif // __GNUC__
107-
10895
static_assert(__cplusplus >= 201703L,
10996
"DPCPP does not support C++ version earlier than C++17.");

sycl/include/sycl/ext/intel/online_compiler.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010

1111
#include <sycl/detail/defines_elementary.hpp>
1212

13-
__SYCL_WARNING(
14-
"sycl/ext/intel/online_compiler.hpp usage is deprecated, include "
15-
"sycl/ext/intel/experimental/online_compiler.hpp instead")
13+
#if !defined(_MSC_VER) || defined(__clang__)
14+
// MSVC doesn't support #warning and we cannot use other methods to report a
15+
// warning from inside a system header (which SYCL is considered to be).
16+
#warning sycl/ext/intel/online_compiler.hpp usage is deprecated, \
17+
include sycl/ext/intel/experimental/online_compiler.hpp instead
18+
#endif
1619

1720
#include <sycl/ext/intel/experimental/online_compiler.hpp>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note %s
2+
#include <sycl/sycl.hpp>
3+
4+
// expected-warning@sycl/backend/cuda.hpp:17 {{sycl/backend/cuda.hpp is deprecated and not required anymore}}
5+
#include <sycl/backend/cuda.hpp>
6+
7+
// expected-warning@sycl/backend/level_zero.hpp:16 {{sycl/backend/level_zero.hpp usage is deprecated, include sycl/ext/oneapi/backend/level_zero.hpp instead}}
8+
#include <sycl/backend/level_zero.hpp>
9+
10+
// expected-warning@sycl/ext/intel/online_compiler.hpp:16 {{sycl/ext/intel/online_compiler.hpp usage is deprecated, include sycl/ext/intel/experimental/online_compiler.hpp instead}}
11+
#include <sycl/ext/intel/online_compiler.hpp>

sycl/test/warnings/sycl_2020_deprecations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clangxx %fsycl-host-only -fsyntax-only -ferror-limit=100 -sycl-std=2020 -Xclang -verify -Xclang -verify-ignore-unexpected=note %s -o %t.out
22

33
#include <CL/sycl.hpp>
4-
#include <sycl/ext/intel/online_compiler.hpp>
4+
#include <sycl/ext/intel/experimental/online_compiler.hpp>
55

66
int main() {
77
cl_context ClCtx;

0 commit comments

Comments
 (0)