From 8ddab7b70b396c3cc92a23004aa5e2c40888c935 Mon Sep 17 00:00:00 2001 From: Georgij Tsarin Date: Mon, 10 Aug 2026 16:25:49 +0300 Subject: [PATCH 1/2] [SYCL] Align item with SYCL 2020 --- sycl/include/sycl/item.hpp | 31 ++++++++++------- sycl/test/basic_tests/item_api.cpp | 56 ++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 12 deletions(-) create mode 100644 sycl/test/basic_tests/item_api.cpp diff --git a/sycl/include/sycl/item.hpp b/sycl/include/sycl/item.hpp index bf9482cfdb110..022955287a0fb 100644 --- a/sycl/include/sycl/item.hpp +++ b/sycl/include/sycl/item.hpp @@ -50,51 +50,54 @@ template class item { public: item() = delete; - id get_id() const { return MImpl.MIndex; } + id get_id() const noexcept { return MImpl.MIndex; } - size_t __SYCL_ALWAYS_INLINE get_id(int Dimension) const { + size_t __SYCL_ALWAYS_INLINE get_id(int Dimension) const noexcept { size_t Id = MImpl.MIndex[Dimension]; __SYCL_ASSUME_ID_RANGE(Id); return Id; } - size_t __SYCL_ALWAYS_INLINE operator[](int Dimension) const { + size_t __SYCL_ALWAYS_INLINE operator[](int Dimension) const noexcept { size_t Id = MImpl.MIndex[Dimension]; __SYCL_ASSUME_ID_RANGE(Id); return Id; } - range get_range() const { return MImpl.MExtent; } + range get_range() const noexcept { return MImpl.MExtent; } - size_t __SYCL_ALWAYS_INLINE get_range(int Dimension) const { + size_t __SYCL_ALWAYS_INLINE get_range(int Dimension) const noexcept { size_t Id = MImpl.MExtent[Dimension]; __SYCL_ASSUME_ID_RANGE(Id); return Id; } #ifndef __SYCL_DISABLE_ITEM_TO_INT_CONV__ - operator EnableIfT() const { return get_id(0); } + operator EnableIfT() const noexcept { + return get_id(0); + } #endif // __SYCL_DISABLE_ITEM_TO_INT_CONV__ template __SYCL2020_DEPRECATED("offsets are deprecated in SYCL2020") - std::enable_if_t> get_offset() const { + std::enable_if_t> get_offset() const noexcept { return MImpl.MOffset; } template __SYCL2020_DEPRECATED("offsets are deprecated in SYCL2020") std::enable_if_t __SYCL_ALWAYS_INLINE - get_offset(int Dimension) const { + get_offset(int Dimension) const noexcept { size_t Id = MImpl.MOffset[Dimension]; __SYCL_ASSUME_ID_RANGE(Id); return Id; } template - operator std::enable_if_t>() const { + operator std::enable_if_t>() + const noexcept { return item{MImpl.MExtent, MImpl.MIndex, /*Offset*/ {}}; } - size_t __SYCL_ALWAYS_INLINE get_linear_id() const { + size_t __SYCL_ALWAYS_INLINE get_linear_id() const noexcept { size_t Id = MImpl.get_linear_id(); __SYCL_ASSUME_ID_RANGE(Id); return Id; @@ -108,9 +111,13 @@ template class item { item &operator=(item &&rhs) = default; - bool operator==(const item &rhs) const { return rhs.MImpl == MImpl; } + friend bool operator==(const item &lhs, const item &rhs) noexcept { + return lhs.MImpl == rhs.MImpl; + } - bool operator!=(const item &rhs) const { return rhs.MImpl != MImpl; } + friend bool operator!=(const item &lhs, const item &rhs) noexcept { + return !(lhs == rhs); + } protected: template diff --git a/sycl/test/basic_tests/item_api.cpp b/sycl/test/basic_tests/item_api.cpp new file mode 100644 index 0000000000000..9b1273b903ec4 --- /dev/null +++ b/sycl/test/basic_tests/item_api.cpp @@ -0,0 +1,56 @@ +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -Wno-deprecated-declarations -fsyntax-only %s +//==----------- item_api.cpp - SYCL item API test --------------------------==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include + +#include +#include +#include + +template +struct HasMemberEquality : std::false_type {}; + +template +struct HasMemberEquality> + : std::true_type {}; + +template +struct HasMemberInequality : std::false_type {}; + +template +struct HasMemberInequality> + : std::true_type {}; + +using ItemWithOffset = sycl::item<2, true>; +using ItemWithoutOffset = sycl::item<2, false>; +using OneDimItem = sycl::item<1, false>; + +static_assert(noexcept(std::declval().get_id())); +static_assert(noexcept(std::declval().get_id(0))); +static_assert(noexcept(std::declval()[0])); +static_assert(noexcept(std::declval().get_range())); +static_assert(noexcept(std::declval().get_range(0))); +static_assert(noexcept(std::declval().get_offset())); +static_assert(noexcept(std::declval().get_offset(0))); +static_assert(noexcept(std::declval().get_linear_id())); +static_assert( + noexcept(static_cast(std::declval()))); +static_assert(noexcept(static_cast>( + std::declval()))); +static_assert(noexcept(std::declval() == + std::declval())); +static_assert(noexcept(std::declval() != + std::declval())); + +static_assert(!HasMemberEquality::value); +static_assert(!HasMemberInequality::value); +static_assert(noexcept(operator==(std::declval(), + std::declval()))); +static_assert(noexcept(operator!=(std::declval(), + std::declval()))); From 93d7372f1e0cd1eb347c71c862232e2ed8ade838 Mon Sep 17 00:00:00 2001 From: Georgij Tsarin Date: Mon, 10 Aug 2026 17:18:00 +0300 Subject: [PATCH 2/2] [SYCL] Drop noexcept from item equality operators --- sycl/include/sycl/item.hpp | 4 ++-- sycl/test/basic_tests/item_api.cpp | 32 +++++++++++++++++++----------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/sycl/include/sycl/item.hpp b/sycl/include/sycl/item.hpp index 022955287a0fb..4246940913872 100644 --- a/sycl/include/sycl/item.hpp +++ b/sycl/include/sycl/item.hpp @@ -111,11 +111,11 @@ template class item { item &operator=(item &&rhs) = default; - friend bool operator==(const item &lhs, const item &rhs) noexcept { + friend bool operator==(const item &lhs, const item &rhs) { return lhs.MImpl == rhs.MImpl; } - friend bool operator!=(const item &lhs, const item &rhs) noexcept { + friend bool operator!=(const item &lhs, const item &rhs) { return !(lhs == rhs); } diff --git a/sycl/test/basic_tests/item_api.cpp b/sycl/test/basic_tests/item_api.cpp index 9b1273b903ec4..75213776248bf 100644 --- a/sycl/test/basic_tests/item_api.cpp +++ b/sycl/test/basic_tests/item_api.cpp @@ -17,15 +17,17 @@ template struct HasMemberEquality : std::false_type {}; template -struct HasMemberEquality> - : std::true_type {}; +struct HasMemberEquality< + T, std::void_t().operator==( + std::declval()))>> : std::true_type {}; template struct HasMemberInequality : std::false_type {}; template -struct HasMemberInequality> - : std::true_type {}; +struct HasMemberInequality< + T, std::void_t().operator!=( + std::declval()))>> : std::true_type {}; using ItemWithOffset = sycl::item<2, true>; using ItemWithoutOffset = sycl::item<2, false>; @@ -43,14 +45,20 @@ static_assert( noexcept(static_cast(std::declval()))); static_assert(noexcept(static_cast>( std::declval()))); -static_assert(noexcept(std::declval() == - std::declval())); -static_assert(noexcept(std::declval() != - std::declval())); +static_assert(std::is_same_v() == + std::declval()), + bool>); +static_assert(std::is_same_v() != + std::declval()), + bool>); static_assert(!HasMemberEquality::value); static_assert(!HasMemberInequality::value); -static_assert(noexcept(operator==(std::declval(), - std::declval()))); -static_assert(noexcept(operator!=(std::declval(), - std::declval()))); +static_assert( + std::is_same_v(), + std::declval())), + bool>); +static_assert( + std::is_same_v(), + std::declval())), + bool>);