From e7467a85803bd6f184e5842fbd1c7770283f2957 Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Thu, 31 Jul 2025 14:59:16 -0700 Subject: [PATCH 1/7] [SYCL][NFCI] Move abs and div to cstdlib header These functions are declared in cmath and use data type defined in cstdlib. Some cmath implementations include cstdlib implicitly, but not all of them. Moving declarations to a standalone header removes dependency on cmath implementation. --- libdevice/cmath_wrapper.cpp | 18 --------- libdevice/device_math.h | 36 ------------------ libdevice/fallback-cmath.cpp | 18 --------- .../__sycl_cmath_wrapper_impl.hpp | 13 ------- sycl/include/sycl/stl_wrappers/cmath | 7 ---- sycl/include/sycl/stl_wrappers/cstdlib | 37 +++++++++++++++++++ sycl/test-e2e/DeviceLib/cmath_test.cpp | 1 + sycl/test/include_deps/sycl_accessor.hpp.cpp | 1 + sycl/test/include_deps/sycl_buffer.hpp.cpp | 1 + .../include_deps/sycl_detail_core.hpp.cpp | 1 + 10 files changed, 41 insertions(+), 92 deletions(-) create mode 100644 sycl/include/sycl/stl_wrappers/cstdlib diff --git a/libdevice/cmath_wrapper.cpp b/libdevice/cmath_wrapper.cpp index a084a86883767..8a2a40b5743dc 100644 --- a/libdevice/cmath_wrapper.cpp +++ b/libdevice/cmath_wrapper.cpp @@ -10,15 +10,6 @@ #if defined(__SPIR__) || defined(__SPIRV__) -DEVICE_EXTERN_C_INLINE -int abs(int x) { return __devicelib_abs(x); } - -DEVICE_EXTERN_C_INLINE -long int labs(long int x) { return __devicelib_labs(x); } - -DEVICE_EXTERN_C_INLINE -long long int llabs(long long int x) { return __devicelib_llabs(x); } - DEVICE_EXTERN_C_INLINE float fabsf(float x) { return __devicelib_fabsf(x); } @@ -51,15 +42,6 @@ float rsqrtf(float x) { return __devicelib_rsqrtf(x); } DEVICE_EXTERN_C_INLINE float exp10f(float x) { return __devicelib_exp10f(x); } -DEVICE_EXTERN_C_INLINE -div_t div(int x, int y) { return __devicelib_div(x, y); } - -DEVICE_EXTERN_C_INLINE -ldiv_t ldiv(long x, long y) { return __devicelib_ldiv(x, y); } - -DEVICE_EXTERN_C_INLINE -lldiv_t lldiv(long long x, long long y) { return __devicelib_lldiv(x, y); } - DEVICE_EXTERN_C_INLINE float roundf(float x) { return __devicelib_roundf(x); } diff --git a/libdevice/device_math.h b/libdevice/device_math.h index f4ee1711060c6..cddfaa3641633 100644 --- a/libdevice/device_math.h +++ b/libdevice/device_math.h @@ -14,33 +14,6 @@ defined(__AMDGCN__) #include -typedef struct { - int32_t quot; - int32_t rem; -} __devicelib_div_t_32; - -typedef struct { - int64_t quot; - int64_t rem; -} __devicelib_div_t_64; - -typedef __devicelib_div_t_32 div_t; -#ifdef _WIN32 -typedef __devicelib_div_t_32 ldiv_t; -#else -typedef __devicelib_div_t_64 ldiv_t; -#endif -typedef __devicelib_div_t_64 lldiv_t; - -DEVICE_EXTERN_C -int __devicelib_abs(int x); - -DEVICE_EXTERN_C -long int __devicelib_labs(long int x); - -DEVICE_EXTERN_C -long long int __devicelib_llabs(long long int x); - DEVICE_EXTERN_C float __devicelib_fabsf(float x); @@ -107,15 +80,6 @@ double __devicelib_exp10(double x); DEVICE_EXTERN_C float __devicelib_exp10f(float x); -DEVICE_EXTERN_C -div_t __devicelib_div(int x, int y); - -DEVICE_EXTERN_C -ldiv_t __devicelib_ldiv(long int x, long int y); - -DEVICE_EXTERN_C -lldiv_t __devicelib_lldiv(long long int x, long long int y); - DEVICE_EXTERN_C double __devicelib_round(double x); diff --git a/libdevice/fallback-cmath.cpp b/libdevice/fallback-cmath.cpp index d930ea014ac24..0159cdb564926 100644 --- a/libdevice/fallback-cmath.cpp +++ b/libdevice/fallback-cmath.cpp @@ -16,15 +16,6 @@ // TODO: generate the DeviceLibFuncMap in sycl-post-link.cpp automatically // during the build based on libdevice to avoid manually sync. -DEVICE_EXTERN_C_INLINE -int __devicelib_abs(int x) { return x < 0 ? -x : x; } - -DEVICE_EXTERN_C_INLINE -long int __devicelib_labs(long int x) { return x < 0 ? -x : x; } - -DEVICE_EXTERN_C_INLINE -long long int __devicelib_llabs(long long int x) { return x < 0 ? -x : x; } - DEVICE_EXTERN_C_INLINE float __devicelib_fabsf(float x) { return x < 0 ? -x : x; } @@ -62,15 +53,6 @@ float __devicelib_rsqrtf(float x) { return __spirv_ocl_rsqrt(x); } DEVICE_EXTERN_C_INLINE float __devicelib_exp10f(float x) { return __spirv_ocl_exp10(x); } -DEVICE_EXTERN_C_INLINE -div_t __devicelib_div(int x, int y) { return {x / y, x % y}; } - -DEVICE_EXTERN_C_INLINE -ldiv_t __devicelib_ldiv(long x, long y) { return {x / y, x % y}; } - -DEVICE_EXTERN_C_INLINE -lldiv_t __devicelib_lldiv(long long x, long long y) { return {x / y, x % y}; } - DEVICE_EXTERN_C_INLINE float __devicelib_scalbnf(float x, int n) { return __spirv_ocl_ldexp(x, n); } diff --git a/sycl/include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp b/sycl/include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp index dc35e16361632..7d28be538a4f6 100644 --- a/sycl/include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp +++ b/sycl/include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp @@ -98,19 +98,6 @@ using __sycl_promote_t = return __spirv_ocl_##NAME((type)x, (type)y); \ } -/// -// FIXME: Move this to a cstdlib fallback header. - -__SYCL_DEVICE div_t div(int x, int y) { return {x / y, x % y}; } -__SYCL_DEVICE ldiv_t ldiv(long x, long y) { return {x / y, x % y}; } -__SYCL_DEVICE lldiv_t ldiv(long long x, long long y) { return {x / y, x % y}; } - -__SYCL_DEVICE long long abs(long long n) { return n < 0 ? -n : n; } -__SYCL_DEVICE_C long long llabs(long long n) { return n < 0 ? -n : n; } -__SYCL_DEVICE long abs(long n) { return n < 0 ? -n : n; } -__SYCL_DEVICE int abs(int n) { return n < 0 ? -n : n; } -__SYCL_DEVICE_C long labs(long n) { return n < 0 ? -n : n; } - /// Basic operations // diff --git a/sycl/include/sycl/stl_wrappers/cmath b/sycl/include/sycl/stl_wrappers/cmath index 143dce0f29d7f..c9d40c4b3aea4 100644 --- a/sycl/include/sycl/stl_wrappers/cmath +++ b/sycl/include/sycl/stl_wrappers/cmath @@ -32,13 +32,6 @@ #ifdef __SYCL_DEVICE_ONLY__ extern "C" { -extern __DPCPP_SYCL_EXTERNAL_LIBC int abs(int x); -extern __DPCPP_SYCL_EXTERNAL_LIBC long int labs(long int x); -extern __DPCPP_SYCL_EXTERNAL_LIBC long long int llabs(long long int x); - -extern __DPCPP_SYCL_EXTERNAL_LIBC div_t div(int x, int y); -extern __DPCPP_SYCL_EXTERNAL_LIBC ldiv_t ldiv(long int x, long int y); -extern __DPCPP_SYCL_EXTERNAL_LIBC lldiv_t lldiv(long long int x, long long int y); extern __DPCPP_SYCL_EXTERNAL_LIBC float scalbnf(float x, int n); extern __DPCPP_SYCL_EXTERNAL_LIBC double scalbn(double x, int n); extern __DPCPP_SYCL_EXTERNAL_LIBC float logf(float x); diff --git a/sycl/include/sycl/stl_wrappers/cstdlib b/sycl/include/sycl/stl_wrappers/cstdlib new file mode 100644 index 0000000000000..804f5b5bd8789 --- /dev/null +++ b/sycl/include/sycl/stl_wrappers/cstdlib @@ -0,0 +1,37 @@ +//==- cstdlib --------------------------------------------------------------==// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#pragma once + +// Include real STL header - the next one from the include search +// directories. +#if defined(__has_include_next) +// GCC/clang support go through this path. +#include_next +#else +// MSVC doesn't support "#include_next", so we have to be creative. +// Our header is located in "stl_wrappers/cstdlib" so it won't be picked by the +// following include. MSVC's installation, on the other hand, has the layout +// where the following would result in the we want. This is obviously +// hacky, but the best we can do... +#include <../include/cstdlib> +#endif + +#ifdef __SYCL_DEVICE_ONLY__ +extern "C" { +__attribute__((sycl_device_only, always_inline)) div_t div(int x, int y) { return {x / y, x % y}; } +__attribute__((sycl_device_only, always_inline)) ldiv_t ldiv(long x, long y) { return {x / y, x % y}; } +__attribute__((sycl_device_only, always_inline)) lldiv_t ldiv(long long x, long long y) { return {x / y, x % y}; } + +__attribute__((sycl_device_only, always_inline)) int abs(int n) { return n < 0 ? -n : n; } +__attribute__((sycl_device_only, always_inline)) long abs(long n) { return n < 0 ? -n : n; } +__attribute__((sycl_device_only, always_inline)) long long abs(long long n) { return n < 0 ? -n : n; } +__attribute__((sycl_device_only, always_inline)) long labs(long n) { return n < 0 ? -n : n; } +__attribute__((sycl_device_only, always_inline)) long long llabs(long long n) { return n < 0 ? -n : n; } +} +#endif // __SYCL_DEVICE_ONLY__ diff --git a/sycl/test-e2e/DeviceLib/cmath_test.cpp b/sycl/test-e2e/DeviceLib/cmath_test.cpp index c5c58f09023d4..1b92463559f30 100644 --- a/sycl/test-e2e/DeviceLib/cmath_test.cpp +++ b/sycl/test-e2e/DeviceLib/cmath_test.cpp @@ -15,6 +15,7 @@ #include "math_utils.hpp" #include #include +#include #include #include #include diff --git a/sycl/test/include_deps/sycl_accessor.hpp.cpp b/sycl/test/include_deps/sycl_accessor.hpp.cpp index 36c74a2fb4969..668cbc647daef 100644 --- a/sycl/test/include_deps/sycl_accessor.hpp.cpp +++ b/sycl/test/include_deps/sycl_accessor.hpp.cpp @@ -9,6 +9,7 @@ // CHECK-NEXT: detail/defines_elementary.hpp // CHECK-NEXT: buffer.hpp // CHECK-NEXT: backend_types.hpp +// CHECK-NEXT: stl_wrappers/cstdlib // CHECK-NEXT: detail/array.hpp // CHECK-NEXT: exception.hpp // CHECK-NEXT: detail/export.hpp diff --git a/sycl/test/include_deps/sycl_buffer.hpp.cpp b/sycl/test/include_deps/sycl_buffer.hpp.cpp index 3799080a01298..ced2f150c320e 100644 --- a/sycl/test/include_deps/sycl_buffer.hpp.cpp +++ b/sycl/test/include_deps/sycl_buffer.hpp.cpp @@ -8,6 +8,7 @@ // CHECK-NEXT: access/access.hpp // CHECK-NEXT: detail/defines_elementary.hpp // CHECK-NEXT: backend_types.hpp +// CHECK-NEXT: stl_wrappers/cstdlib // CHECK-NEXT: detail/array.hpp // CHECK-NEXT: exception.hpp // CHECK-NEXT: detail/export.hpp diff --git a/sycl/test/include_deps/sycl_detail_core.hpp.cpp b/sycl/test/include_deps/sycl_detail_core.hpp.cpp index d7050767b62e2..3087928f17c3f 100644 --- a/sycl/test/include_deps/sycl_detail_core.hpp.cpp +++ b/sycl/test/include_deps/sycl_detail_core.hpp.cpp @@ -10,6 +10,7 @@ // CHECK-NEXT: detail/defines_elementary.hpp // CHECK-NEXT: buffer.hpp // CHECK-NEXT: backend_types.hpp +// CHECK-NEXT: stl_wrappers/cstdlib // CHECK-NEXT: detail/array.hpp // CHECK-NEXT: exception.hpp // CHECK-NEXT: detail/export.hpp From ed3ba14223ca187a18898e64e010286fc72cef4c Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Thu, 31 Jul 2025 15:39:31 -0700 Subject: [PATCH 2/7] Change attribute style from GNU to C++11. --- sycl/include/sycl/stl_wrappers/cstdlib | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sycl/include/sycl/stl_wrappers/cstdlib b/sycl/include/sycl/stl_wrappers/cstdlib index 804f5b5bd8789..38f62a2553003 100644 --- a/sycl/include/sycl/stl_wrappers/cstdlib +++ b/sycl/include/sycl/stl_wrappers/cstdlib @@ -24,14 +24,14 @@ #ifdef __SYCL_DEVICE_ONLY__ extern "C" { -__attribute__((sycl_device_only, always_inline)) div_t div(int x, int y) { return {x / y, x % y}; } -__attribute__((sycl_device_only, always_inline)) ldiv_t ldiv(long x, long y) { return {x / y, x % y}; } -__attribute__((sycl_device_only, always_inline)) lldiv_t ldiv(long long x, long long y) { return {x / y, x % y}; } +[[clang::sycl_device_only, clang::always_inline]] div_t div(int x, int y) { return {x / y, x % y}; } +[[clang::sycl_device_only, clang::always_inline]] ldiv_t ldiv(long x, long y) { return {x / y, x % y}; } +[[clang::sycl_device_only, clang::always_inline]] lldiv_t ldiv(long long x, long long y) { return {x / y, x % y}; } -__attribute__((sycl_device_only, always_inline)) int abs(int n) { return n < 0 ? -n : n; } -__attribute__((sycl_device_only, always_inline)) long abs(long n) { return n < 0 ? -n : n; } -__attribute__((sycl_device_only, always_inline)) long long abs(long long n) { return n < 0 ? -n : n; } -__attribute__((sycl_device_only, always_inline)) long labs(long n) { return n < 0 ? -n : n; } -__attribute__((sycl_device_only, always_inline)) long long llabs(long long n) { return n < 0 ? -n : n; } +[[clang::sycl_device_only, clang::always_inline]] int abs(int n) { return n < 0 ? -n : n; } +[[clang::sycl_device_only, clang::always_inline]] long abs(long n) { return n < 0 ? -n : n; } +[[clang::sycl_device_only, clang::always_inline]] long long abs(long long n) { return n < 0 ? -n : n; } +[[clang::sycl_device_only, clang::always_inline]] long labs(long n) { return n < 0 ? -n : n; } +[[clang::sycl_device_only, clang::always_inline]] long long llabs(long long n) { return n < 0 ? -n : n; } } #endif // __SYCL_DEVICE_ONLY__ From 352cf9b53fa25609dd1235463c66c7717b2f5bda Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Thu, 31 Jul 2025 16:05:38 -0700 Subject: [PATCH 3/7] Make __sycl_cmath_wrapper_impl.hpp self-contained Remove std::div and std::abs overloads and remove xfail mark for the test. Align cstdlib declaration with cppreference: 1. Make all declarations overloadable. 2. Fix function name for div(long long, long long) overload and add missing overload. 3. Add std::* variants. --- .../__sycl_cmath_wrapper_impl.hpp | 7 ---- sycl/include/sycl/stl_wrappers/cstdlib | 32 +++++++++++++++++-- .../test/self-contained-headers/lit.local.cfg | 4 --- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/sycl/include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp b/sycl/include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp index 7d28be538a4f6..27f613ec6b5c5 100644 --- a/sycl/include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp +++ b/sycl/include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp @@ -335,13 +335,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif #endif -// -using ::div; -using ::labs; -using ::ldiv; -using ::llabs; -using ::lldiv; - // Basic operations using ::abs; using ::fabs; diff --git a/sycl/include/sycl/stl_wrappers/cstdlib b/sycl/include/sycl/stl_wrappers/cstdlib index 38f62a2553003..57846de8c18cb 100644 --- a/sycl/include/sycl/stl_wrappers/cstdlib +++ b/sycl/include/sycl/stl_wrappers/cstdlib @@ -23,15 +23,41 @@ #endif #ifdef __SYCL_DEVICE_ONLY__ -extern "C" { [[clang::sycl_device_only, clang::always_inline]] div_t div(int x, int y) { return {x / y, x % y}; } +[[clang::sycl_device_only, clang::always_inline]] ldiv_t div(long x, long y) { return {x / y, x % y}; } +[[clang::sycl_device_only, clang::always_inline]] lldiv_t div(long long x, long long y) { return {x / y, x % y}; } [[clang::sycl_device_only, clang::always_inline]] ldiv_t ldiv(long x, long y) { return {x / y, x % y}; } -[[clang::sycl_device_only, clang::always_inline]] lldiv_t ldiv(long long x, long long y) { return {x / y, x % y}; } +[[clang::sycl_device_only, clang::always_inline]] lldiv_t lldiv(long long x, long long y) { return {x / y, x % y}; } [[clang::sycl_device_only, clang::always_inline]] int abs(int n) { return n < 0 ? -n : n; } [[clang::sycl_device_only, clang::always_inline]] long abs(long n) { return n < 0 ? -n : n; } [[clang::sycl_device_only, clang::always_inline]] long long abs(long long n) { return n < 0 ? -n : n; } [[clang::sycl_device_only, clang::always_inline]] long labs(long n) { return n < 0 ? -n : n; } [[clang::sycl_device_only, clang::always_inline]] long long llabs(long long n) { return n < 0 ? -n : n; } -} + +#ifdef _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_NAMESPACE_STD +#else +namespace std { +#ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION +_GLIBCXX_BEGIN_NAMESPACE_VERSION +#endif +#endif + +using ::div; +using ::ldiv; +using ::lldiv; + +using ::labs; +using ::llabs; +using ::lldiv; + +#ifdef _LIBCPP_END_NAMESPACE_STD +_LIBCPP_END_NAMESPACE_STD +#else +#ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION +_GLIBCXX_END_NAMESPACE_VERSION +#endif +} // namespace std +#endif #endif // __SYCL_DEVICE_ONLY__ diff --git a/sycl/test/self-contained-headers/lit.local.cfg b/sycl/test/self-contained-headers/lit.local.cfg index 767afc0f1b74e..30a1d3e1a195c 100644 --- a/sycl/test/self-contained-headers/lit.local.cfg +++ b/sycl/test/self-contained-headers/lit.local.cfg @@ -7,8 +7,4 @@ config.test_format = SYCLHeadersTest() # standalone. `os.path.join` is required here so the filtering works # cross-platform config.sycl_headers_xfail = [ - # FIXME: remove this rule when the header is moved to the clang project - os.path.join( - "sycl", "stl_wrappers", "__sycl_cmath_wrapper_impl.hpp" - ), ] From b21a882d95886ee8560f328399eabe800f754849 Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Thu, 31 Jul 2025 16:25:19 -0700 Subject: [PATCH 4/7] Fix typo. --- sycl/include/sycl/stl_wrappers/cstdlib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/include/sycl/stl_wrappers/cstdlib b/sycl/include/sycl/stl_wrappers/cstdlib index 57846de8c18cb..f91a5dcb28e57 100644 --- a/sycl/include/sycl/stl_wrappers/cstdlib +++ b/sycl/include/sycl/stl_wrappers/cstdlib @@ -48,9 +48,9 @@ using ::div; using ::ldiv; using ::lldiv; +using ::abs; using ::labs; using ::llabs; -using ::lldiv; #ifdef _LIBCPP_END_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD From 0b26f2b7d5770c72c9b4e9a812430e73f76d0b31 Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Fri, 1 Aug 2025 10:28:57 -0700 Subject: [PATCH 5/7] Apply code review. --- sycl/include/sycl/stl_wrappers/cstdlib | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sycl/include/sycl/stl_wrappers/cstdlib b/sycl/include/sycl/stl_wrappers/cstdlib index f91a5dcb28e57..8ed35a5a0754e 100644 --- a/sycl/include/sycl/stl_wrappers/cstdlib +++ b/sycl/include/sycl/stl_wrappers/cstdlib @@ -23,17 +23,15 @@ #endif #ifdef __SYCL_DEVICE_ONLY__ +extern "C" { [[clang::sycl_device_only, clang::always_inline]] div_t div(int x, int y) { return {x / y, x % y}; } -[[clang::sycl_device_only, clang::always_inline]] ldiv_t div(long x, long y) { return {x / y, x % y}; } -[[clang::sycl_device_only, clang::always_inline]] lldiv_t div(long long x, long long y) { return {x / y, x % y}; } [[clang::sycl_device_only, clang::always_inline]] ldiv_t ldiv(long x, long y) { return {x / y, x % y}; } [[clang::sycl_device_only, clang::always_inline]] lldiv_t lldiv(long long x, long long y) { return {x / y, x % y}; } [[clang::sycl_device_only, clang::always_inline]] int abs(int n) { return n < 0 ? -n : n; } -[[clang::sycl_device_only, clang::always_inline]] long abs(long n) { return n < 0 ? -n : n; } -[[clang::sycl_device_only, clang::always_inline]] long long abs(long long n) { return n < 0 ? -n : n; } [[clang::sycl_device_only, clang::always_inline]] long labs(long n) { return n < 0 ? -n : n; } [[clang::sycl_device_only, clang::always_inline]] long long llabs(long long n) { return n < 0 ? -n : n; } +} #ifdef _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD @@ -45,10 +43,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif using ::div; +[[clang::sycl_device_only, clang::always_inline]] ldiv_t div(long x, long y) { return {x / y, x % y}; } +[[clang::sycl_device_only, clang::always_inline]] lldiv_t div(long long x, long long y) { return {x / y, x % y}; } using ::ldiv; using ::lldiv; using ::abs; +[[clang::sycl_device_only, clang::always_inline]] long abs(long n) { return n < 0 ? -n : n; } +[[clang::sycl_device_only, clang::always_inline]] long long abs(long long n) { return n < 0 ? -n : n; } using ::labs; using ::llabs; From 74c4e9515218567675796dbe7f6fccf8c84973e7 Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Fri, 1 Aug 2025 12:44:28 -0700 Subject: [PATCH 6/7] Add one more test. --- .../check_device_code/math-builtins/cstdlib.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 sycl/test/check_device_code/math-builtins/cstdlib.cpp diff --git a/sycl/test/check_device_code/math-builtins/cstdlib.cpp b/sycl/test/check_device_code/math-builtins/cstdlib.cpp new file mode 100644 index 0000000000000..75c06b168ebb0 --- /dev/null +++ b/sycl/test/check_device_code/math-builtins/cstdlib.cpp @@ -0,0 +1,13 @@ +// RUN: %clangxx -fsycl -fsyntax-only %s + +#include + +#include + +// Unqualified calls should resolve to the `int` overloads +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); From de7845124c3cdb80c2ef85b46bc5d00e53cd160a Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Fri, 1 Aug 2025 19:01:19 -0700 Subject: [PATCH 7/7] Extend the test and disable checks for global name space overloads on Windows. --- .../math-builtins/cstdlib.cpp | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/sycl/test/check_device_code/math-builtins/cstdlib.cpp b/sycl/test/check_device_code/math-builtins/cstdlib.cpp index 75c06b168ebb0..20ee81a59d2d2 100644 --- a/sycl/test/check_device_code/math-builtins/cstdlib.cpp +++ b/sycl/test/check_device_code/math-builtins/cstdlib.cpp @@ -4,10 +4,25 @@ #include +int i = 1; +long l = 1; +long long ll = 1; + // Unqualified calls should resolve to the `int` overloads -static_assert(std::is_same_v); -static_assert(std::is_same_v); -static_assert(std::is_same_v); -static_assert(std::is_same_v); -static_assert(std::is_same_v); -static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); +// NOTE: Windows Universal C Runtime defines C++ overloads for `long` and +// `long long` types in global name space. See +// https://github.com/huangqinjin/ucrt/blob/d6e817a4cc90f6f1fe54f8a0aa4af4fff0bb647d/include/stdlib.h#L360-L383. +#ifndef _WIN32 +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); +#endif // _WIN32