Skip to content

Commit ec60ea6

Browse files
[SYCL] Add workaround for undeterminable constexpr lambda return (#19191)
Due to a bug in the compiler, certain conditions give false compiler errors for return types of constexpr lambdas. This commit implements workarounds for cases that affect the SYCL headers when using properties. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 858fd15 commit ec60ea6

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

sycl/include/sycl/ext/oneapi/properties/properties.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ using properties_t =
4848
properties<detail::properties_type_list<PropertyValueTs...>>;
4949

5050
template <typename... property_tys>
51-
inline constexpr bool properties_are_unique = []() constexpr {
51+
inline constexpr bool properties_are_unique = []() constexpr -> bool {
5252
if constexpr (sizeof...(property_tys) == 0) {
5353
return true;
5454
} else {
@@ -64,7 +64,7 @@ inline constexpr bool properties_are_unique = []() constexpr {
6464
}();
6565

6666
template <typename... property_tys>
67-
inline constexpr bool properties_are_sorted = []() constexpr {
67+
inline constexpr bool properties_are_sorted = []() constexpr -> bool {
6868
if constexpr (sizeof...(property_tys) == 0) {
6969
return true;
7070
} else {

sycl/include/sycl/ext/oneapi/properties/property.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ struct property_base : property_key_tag<property_key_t> {
258258
// Temporary, to ensure new code matches previous behavior and to catch any
259259
// silly copy-paste mistakes. MSVC can't compile it, but linux-only is
260260
// enough for this temporary check.
261-
static_assert([]() constexpr {
261+
static_assert([]() constexpr -> bool {
262262
if constexpr (std::is_same_v<property_t, key_t>)
263263
// key_t is incomplete at this point for runtime properties.
264264
return true;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clangxx -fsycl -fsyntax-only %s
2+
3+
// Test for a workaround to a bug in clang causing some constexpr lambda
4+
// expressions to not be identified as returning a bool.
5+
6+
#include <sycl/detail/kernel_properties.hpp>
7+
#include <sycl/ext/intel/experimental/grf_size_properties.hpp>
8+
#include <sycl/sycl.hpp>
9+
10+
int main() {
11+
if constexpr (false) {
12+
sycl::ext::oneapi::experimental::properties prop{
13+
sycl::ext::intel::experimental::grf_size<256>};
14+
}
15+
}

0 commit comments

Comments
 (0)