Skip to content

Commit afcca05

Browse files
[SYCL] VS2026 fix needs guard in complex (#22994)
test added
1 parent ebbf0d9 commit afcca05

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

sycl/include/sycl/ext/oneapi/experimental/complex/detail/common.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,14 @@ struct is_gencomplex
4949
/// DEFINES
5050
////////////////////////////////////////////////////////////////////////////////
5151

52+
#if defined(_MSC_VER) && !defined(__clang__)
53+
// cl.exe does not understand GCC-style __attribute__((...)); it is only a
54+
// visibility/always-inline hint, so fall back to __forceinline for parity.
55+
#define _SYCL_EXT_CPLX_INLINE_VISIBILITY __forceinline
56+
#else
5257
#define _SYCL_EXT_CPLX_INLINE_VISIBILITY \
5358
inline __attribute__((__visibility__("hidden"), __always_inline__))
59+
#endif
5460

5561
} // namespace experimental
5662
} // namespace oneapi
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Regression test for CMPLRLLVM-77544. The SYCL complex experimental
2+
// extension's inline-visibility macro previously expanded to an unguarded
3+
// __attribute__((visibility(...), always_inline)), which cl.exe cannot parse.
4+
// That surfaced when icx/clang++ drives cl.exe as the SYCL host compiler
5+
// (e.g. torch-xpu-ops builds on Windows). The header now guards the macro
6+
// with _MSC_VER; this test ensures the partial specialization of complex<T>
7+
// keeps parsing under MSVC host compilation.
8+
9+
// RUN: %clangxx -fsycl -fsycl-host-compiler=cl -fsycl-host-compiler-options='/std:c++20 /MD /EHsc /permissive- /DSYCL_DISABLE_FSYCL_SYCLHPP_WARNING' %s -c -o %t.o
10+
// REQUIRES: windows
11+
12+
#define SYCL_EXT_ONEAPI_COMPLEX
13+
#include <sycl/ext/oneapi/experimental/complex/complex.hpp>
14+
#include <sycl/sycl.hpp>
15+
16+
namespace syclex = sycl::ext::oneapi::experimental;
17+
18+
// Force instantiation of the complex<T, enable_if<is_genfloat<T>>> partial
19+
// specialization for each supported floating-point type. Prior to the fix,
20+
// simply parsing the class body under cl.exe hit C2059 on the first member
21+
// decorated with _SYCL_EXT_CPLX_INLINE_VISIBILITY.
22+
void force_instantiate() {
23+
syclex::complex<float> zf(1.0f, 2.0f);
24+
syclex::complex<double> zd(1.0, 2.0);
25+
syclex::complex<sycl::half> zh(sycl::half{1.0f}, sycl::half{2.0f});
26+
(void)syclex::exp(zf).real();
27+
(void)syclex::exp(zd).real();
28+
(void)syclex::exp(zh).real();
29+
}

0 commit comments

Comments
 (0)