Skip to content

Commit a6f5b4e

Browse files
committed
[SYCL] Move __buildin_unique_stable_name dependent funcs to a separate header
This patch moves functions which use `__builtin_unique_stable_name` to a separate header which should only be included to integration footer. This was made to get rid of UB when the compiler sees defenition of the template specialization before seeing a declaration.
1 parent ae87657 commit a6f5b4e

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

sycl/include/CL/sycl/detail/kernel_desc.hpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ namespace detail {
2121
// while the code requires C++17. This code is not supposed to be used by the
2222
// libsycl.so so it should not be a problem.
2323
#if __cplusplus > 201402L
24-
template <auto &S> struct specialization_id_name_generator {};
24+
// Definition is in spec_const_integration.hpp
25+
template <auto &S> struct specialization_id_name_generator;
2526
#endif
2627

2728
#ifndef __SYCL_DEVICE_ONLY__
@@ -58,14 +59,8 @@ template <class Name> struct SpecConstantInfo {
5859

5960
#if __cplusplus >= 201703L
6061
// Translates SYCL 2020 specialization constant type to its name.
61-
template <auto &SpecName> const char *get_spec_constant_symbolic_ID() {
62-
#ifdef SYCL_LANGUAGE_VERSION
63-
return __builtin_unique_stable_name(
64-
specialization_id_name_generator<SpecName>);
65-
#else
66-
return "";
67-
#endif
68-
}
62+
// Definition is in spec_const_integration.hpp
63+
template <auto &SpecName> const char *get_spec_constant_symbolic_ID();
6964
#endif
7065

7166
#ifndef __SYCL_UNNAMED_LAMBDA__
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//==---------------------- spec_const_integration.hpp ----------------------==//
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+
#pragma once
10+
11+
// This header file must not be included to any DPC++ headers.
12+
// This header file should only be included to integration footer.
13+
14+
__SYCL_INLINE_NAMESPACE(cl) {
15+
namespace sycl {
16+
namespace detail {
17+
18+
#if __cplusplus >= 201703L
19+
template <auto &S> struct specialization_id_name_generator {};
20+
#endif
21+
22+
// Translates SYCL 2020 specialization constant type to its name.
23+
template <auto &SpecName> const char *get_spec_constant_symbolic_ID() {
24+
#ifdef SYCL_LANGUAGE_VERSION
25+
return __builtin_unique_stable_name(
26+
specialization_id_name_generator<SpecName>);
27+
#else
28+
return "";
29+
#endif
30+
}
31+
#endif
32+
33+
} // namespace detail
34+
} // namespace sycl
35+
} // __SYCL_INLINE_NAMESPACE(cl)

0 commit comments

Comments
 (0)