From db24484e47ce0d226300c189146c62600ccb8f2f Mon Sep 17 00:00:00 2001 From: "Larsen, Steffen" Date: Thu, 26 Jun 2025 22:40:23 -0700 Subject: [PATCH] [SYCL] Add workaround for undeterminable constexpr lambda return 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 --- .../sycl/ext/oneapi/properties/properties.hpp | 4 ++-- .../sycl/ext/oneapi/properties/property.hpp | 2 +- sycl/test/regression/grf_properties_wa.cpp | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 sycl/test/regression/grf_properties_wa.cpp diff --git a/sycl/include/sycl/ext/oneapi/properties/properties.hpp b/sycl/include/sycl/ext/oneapi/properties/properties.hpp index 354975b857d13..4d3e11ec8b143 100644 --- a/sycl/include/sycl/ext/oneapi/properties/properties.hpp +++ b/sycl/include/sycl/ext/oneapi/properties/properties.hpp @@ -48,7 +48,7 @@ using properties_t = properties>; template -inline constexpr bool properties_are_unique = []() constexpr { +inline constexpr bool properties_are_unique = []() constexpr -> bool { if constexpr (sizeof...(property_tys) == 0) { return true; } else { @@ -64,7 +64,7 @@ inline constexpr bool properties_are_unique = []() constexpr { }(); template -inline constexpr bool properties_are_sorted = []() constexpr { +inline constexpr bool properties_are_sorted = []() constexpr -> bool { if constexpr (sizeof...(property_tys) == 0) { return true; } else { diff --git a/sycl/include/sycl/ext/oneapi/properties/property.hpp b/sycl/include/sycl/ext/oneapi/properties/property.hpp index 37e1777e21235..d68ec8884d93b 100644 --- a/sycl/include/sycl/ext/oneapi/properties/property.hpp +++ b/sycl/include/sycl/ext/oneapi/properties/property.hpp @@ -258,7 +258,7 @@ struct property_base : property_key_tag { // Temporary, to ensure new code matches previous behavior and to catch any // silly copy-paste mistakes. MSVC can't compile it, but linux-only is // enough for this temporary check. - static_assert([]() constexpr { + static_assert([]() constexpr -> bool { if constexpr (std::is_same_v) // key_t is incomplete at this point for runtime properties. return true; diff --git a/sycl/test/regression/grf_properties_wa.cpp b/sycl/test/regression/grf_properties_wa.cpp new file mode 100644 index 0000000000000..5bce42a25734a --- /dev/null +++ b/sycl/test/regression/grf_properties_wa.cpp @@ -0,0 +1,15 @@ +// RUN: %clangxx -fsycl -fsyntax-only %s + +// Test for a workaround to a bug in clang causing some constexpr lambda +// expressions to not be identified as returning a bool. + +#include +#include +#include + +int main() { + if constexpr (false) { + sycl::ext::oneapi::experimental::properties prop{ + sycl::ext::intel::experimental::grf_size<256>}; + } +}