Skip to content

Commit 6a77944

Browse files
s-kanaevbader
authored andcommitted
[SYCL][NFC] Eliminate struct/class definition/declaration and static/static-inlined function warnings (#1027)
* Align TryToGetNumElements and is_same_vector_size_impl definition and declaration to avoid compiler warnings Compiling user code with -Wall provides compilation warnings from SYCL headers. In some cases (-Werror or smth like that is enabled) it may not allow to compile user code. ``` CL/sycl/detail/generic_type_traits.hpp:468:1: warning: 'TryToGetNumElements' defined as a struct template here but previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI [-Wmismatched-tags] struct TryToGetNumElements< ``` * Enable all warnings while building SYCL runtime * Add a test to see if build succeeds with -Wall -Werror Signed-off-by: Sergey Kanaev <[email protected]>
1 parent c2c416a commit 6a77944

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

sycl/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,21 @@ set(CMAKE_CXX_EXTENSIONS OFF)
88
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
99
option(SYCL_ENABLE_WERROR "Treat all warnings as errors in SYCL project" OFF)
1010

11+
# enable all warnings by default
12+
if (MSVC)
13+
set(CMAKE_CXX_FLAGS "/W4 ${CMAKE_CXX_FLAGS}")
14+
else ()
15+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-deprecated-declarations")
16+
endif()
17+
1118
if(SYCL_ENABLE_WERROR)
1219
if(MSVC)
13-
set(CMAKE_CXX_FLAGS "/W4 /WX ${CMAKE_CXX_FLAGS}")
20+
set(CMAKE_CXX_FLAGS "/WX ${CMAKE_CXX_FLAGS}")
1421
add_definitions(
1522
-wd4996 # Suppress 'function': was declared deprecated'
1623
)
1724
else()
18-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -Wno-deprecated-declarations")
25+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
1926
endif()
2027
endif()
2128

sycl/include/CL/__spirv/spirv_vars.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern "C" const __attribute__((opencl_constant)) size_t_vec __spirv_BuiltInWork
2020
extern "C" const __attribute__((opencl_constant)) size_t_vec __spirv_BuiltInGlobalOffset;
2121

2222
#define DEFINE_INT_ID_TO_XYZ_CONVERTER(POSTFIX) \
23-
template <int ID> static size_t get##POSTFIX(); \
23+
template <int ID> static inline size_t get##POSTFIX(); \
2424
template <> size_t get##POSTFIX<0>() { return __spirv_BuiltIn##POSTFIX.x; } \
2525
template <> size_t get##POSTFIX<1>() { return __spirv_BuiltIn##POSTFIX.y; } \
2626
template <> size_t get##POSTFIX<2>() { return __spirv_BuiltIn##POSTFIX.z; }

sycl/include/CL/sycl/detail/generic_type_traits.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ using common_rel_ret_t =
462462
template <int N> struct Boolean;
463463

464464
// Try to get vector element count or 1 otherwise
465-
template <typename T, typename Enable = void> class TryToGetNumElements;
465+
template <typename T, typename Enable = void> struct TryToGetNumElements;
466466

467467
template <typename T>
468468
struct TryToGetNumElements<
@@ -558,7 +558,7 @@ template <typename T> static constexpr T quiet_NaN() {
558558
}
559559

560560
// is_same_vector_size
561-
template <int FirstSize, typename... Args> struct is_same_vector_size_impl;
561+
template <int FirstSize, typename... Args> class is_same_vector_size_impl;
562562

563563
template <int FirstSize, typename T, typename... Args>
564564
class is_same_vector_size_impl<FirstSize, T, Args...> {
@@ -573,7 +573,7 @@ class is_same_vector_size_impl<FirstSize, T, Args...> {
573573
};
574574

575575
template <int FirstSize>
576-
struct is_same_vector_size_impl<FirstSize> : std::true_type {};
576+
class is_same_vector_size_impl<FirstSize> : public std::true_type {};
577577

578578
template <typename T, typename... Args> class is_same_vector_size {
579579
using CurrentT = remove_pointer_t<T>;

sycl/test/warnings/warnings.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %clangxx -Wall -Wpessimizing-move -Wunused-variable -Wmismatched-tags -Wunneeded-internal-declaration -Werror -fsycl %s -o %t.out
2+
3+
#include <CL/sycl.hpp>
4+
5+
using namespace cl::sycl;
6+
7+
int main(void) {
8+
// add a very simple kernel to see if compilation succeeds with -Werror
9+
int data1[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
10+
11+
buffer<int, 1> B(data1, range<1>(10), {property::buffer::use_host_ptr()});
12+
queue Q;
13+
Q.submit([&](handler &CGH) {
14+
auto Accessor = B.get_access<access::mode::read_write>(CGH);
15+
CGH.parallel_for<class TheSimpleKernel>(range<1>{10}, [=](id<1> Item) {
16+
Accessor[Item] = 0;
17+
});
18+
});
19+
20+
return 0;
21+
}

0 commit comments

Comments
 (0)