Skip to content

Commit ac3954a

Browse files
committed
[SYCL][NFC] Throw warning when sycl.hpp is included without -fsycl flag.
1 parent 94b20ff commit ac3954a

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

sycl/include/sycl/sycl.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@
88

99
#pragma once
1010

11+
// Throw warning when including sycl.hpp without using -fsycl flag.
12+
// Warning can be disabled by defining SYCL_DISABLE_FSYCL_SYCLHPP_WARNING macro.
13+
#define STRINGIFY(x) #x
14+
#define TOSTRING(x) STRINGIFY(x)
15+
16+
#ifdef _MSC_VER
17+
#define WARNING(msg) __pragma(message(__FILE__ "(" TOSTRING(__LINE__) "): warning: " msg))
18+
#elif defined(__GNUC__) || defined(__clang__)
19+
#define WARNING(msg) _Pragma(TOSTRING(GCC warning msg))
20+
#else
21+
#define WARNING(msg) // Unsupported compiler
22+
#endif
23+
24+
#if !defined(SYCL_LANGUAGE_VERSION) && !defined(SYCL_DISABLE_FSYCL_SYCLHPP_WARNING)
25+
WARNING("You are including <sycl/sycl.hpp> without -fsycl flag, \
26+
which is errorenous for device code compilation. This warning \
27+
can be disabled by setting SYCL_DISABLE_FSYCL_SYCLHPP_WARNING macro.")
28+
#endif
29+
#undef WARNING
30+
#undef TOSTRING
31+
#undef STRINGIFY
32+
1133
#include <sycl/detail/core.hpp>
1234

1335
#include <sycl/accessor_image.hpp>

sycl/test/warnings/no_fsycl_flag.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Test to verify that a warning is thrown when the -fsycl flag is not used and
2+
// <sycl/sycl.hpp> file is included.
3+
// RUN: %clangxx -I %sycl_include -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix=CHECK-WARNING
4+
// RUN: %clangxx -I %sycl_include -fsyntax-only -DSYCL_DISABLE_FSYCL_SYCLHPP_WARNING %s 2>&1 | FileCheck %s --implicit-check-not=CHECK-WARNING
5+
6+
// CHECK-WARNING: You are including <sycl/sycl.hpp> without -fsycl flag, which is errorenous for device code compilation.
7+
#include <sycl/sycl.hpp>

sycl/tools/sycl-ls/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if (WIN32 AND "${build_type_lower}" MATCHES "debug")
99
endif()
1010

1111
# Disable aspect::image & deprecation warnings.
12-
target_compile_definitions(sycl-ls PRIVATE SYCL_DISABLE_IMAGE_ASPECT_WARNING SYCL2020_DISABLE_DEPRECATION_WARNINGS)
12+
target_compile_definitions(sycl-ls PRIVATE SYCL_DISABLE_IMAGE_ASPECT_WARNING SYCL2020_DISABLE_DEPRECATION_WARNINGS SYCL_DISABLE_FSYCL_SYCLHPP_WARNING)
1313

1414
target_link_libraries(sycl-ls
1515
PRIVATE

0 commit comments

Comments
 (0)