| 1 |
// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++17 -fsyntax-only -fsycl-is-device -verify %s |
| 2 |
// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++20 -fsyntax-only -fsycl-is-device -verify %s |
| 3 |
// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -fsyntax-only -fsycl-is-device -verify %s |
| 4 |
|
| 5 |
// These tests validate appertainment for the sycl_kernel_entry_point attribute. |
| 6 |
|
| 7 |
#if __cplusplus >= 202002L |
| 8 |
// Mock coroutine support. |
| 9 |
namespace std { |
| 10 |
|
| 11 |
template<typename Promise = void> |
| 12 |
struct coroutine_handle { |
| 13 |
template<typename T> |
| 14 |
coroutine_handle(const coroutine_handle<T>&); |
| 15 |
static coroutine_handle from_address(void *addr); |
| 16 |
}; |
| 17 |
|
| 18 |
template<typename R, typename... Args> |
| 19 |
struct coroutine_traits { |
| 20 |
struct suspend_never { |
| 21 |
bool await_ready() const noexcept; |
| 22 |
void await_suspend(std::coroutine_handle<>) const noexcept; |
| 23 |
void await_resume() const noexcept; |
| 24 |
}; |
| 25 |
struct promise_type { |
| 26 |
void get_return_object() noexcept; |
| 27 |
suspend_never initial_suspend() const noexcept; |
| 28 |
suspend_never final_suspend() const noexcept; |
| 29 |
void return_void() noexcept; |
| 30 |
void unhandled_exception() noexcept; |
| 31 |
}; |
| 32 |
}; |
| 33 |
|
| 34 |
} |
| 35 |
#endif |
| 36 |
|
| 37 |
// A unique kernel name type is required for each declared kernel entry point. |
| 38 |
template<int, int = 0> struct KN; |
| 39 |
|
| 40 |
|
| 41 |
//////////////////////////////////////////////////////////////////////////////// |
| 42 |
// Valid declarations. |
| 43 |
//////////////////////////////////////////////////////////////////////////////// |
| 44 |
|
| 45 |
// Function declaration with GNU attribute spelling |
| 46 |
// expected-warning@+1 {{unknown attribute 'sycl_kernel_entry_point' ignored}} |
| 47 |
__attribute__((sycl_kernel_entry_point(KN<1>))) |
| 48 |
void ok1(); |
| 49 |
|
| 50 |
// Function declaration with C++11 attribute spelling. |
| 51 |
[[clang::sycl_kernel_entry_point(KN<2>)]] |
| 52 |
void ok2(); |
| 53 |
|
| 54 |
// Function definition. |
| 55 |
[[clang::sycl_kernel_entry_point(KN<3>)]] |
| 56 |
void ok3() {} |
| 57 |
|
| 58 |
// Function template definition. |
| 59 |
template<typename KNT, typename T> |
| 60 |
[[clang::sycl_kernel_entry_point(KNT)]] |
| 61 |
void ok4(T) {} |
| 62 |
|
| 63 |
// Function template explicit specialization. |
| 64 |
template<> |
| 65 |
[[clang::sycl_kernel_entry_point(KN<4,1>)]] |
| 66 |
void ok4<KN<4,1>>(int) {} |
| 67 |
|
| 68 |
// Function template explicit instantiation. |
| 69 |
template void ok4<KN<4,2>, long>(long); |
| 70 |
|
| 71 |
namespace NS { |
| 72 |
// Function declaration at namespace scope. |
| 73 |
[[clang::sycl_kernel_entry_point(KN<5>)]] |
| 74 |
void ok5(); |
| 75 |
} |
| 76 |
|
| 77 |
struct S6 { |
| 78 |
// Static member function declaration. |
| 79 |
[[clang::sycl_kernel_entry_point(KN<6>)]] |
| 80 |
static void ok6(); |
| 81 |
}; |
| 82 |
|
| 83 |
// Dependent hidden friend definition. |
| 84 |
template<typename KNT> |
| 85 |
struct S7 { |
| 86 |
[[clang::sycl_kernel_entry_point(KNT)]] |
| 87 |
friend void ok7(S7) {} |
| 88 |
}; |
| 89 |
void test_ok7() { |
| 90 |
ok7(S7<KN<7>>{}); |
| 91 |
} |
| 92 |
|
| 93 |
// Non-dependent hidden friend definition. |
| 94 |
struct S8Base {}; |
| 95 |
template<typename> |
| 96 |
struct S8 : S8Base { |
| 97 |
[[clang::sycl_kernel_entry_point(KN<8>)]] |
| 98 |
friend void ok8(const S8Base&) {} |
| 99 |
}; |
| 100 |
void test_ok8() { |
| 101 |
ok8(S8<int>{}); |
| 102 |
} |
| 103 |
|
| 104 |
// The sycl_kernel_entry_point attribute must match across declarations and |
| 105 |
// cannot be added for the first time after a definition. |
| 106 |
[[clang::sycl_kernel_entry_point(KN<9>)]] |
| 107 |
void ok9(); |
| 108 |
[[clang::sycl_kernel_entry_point(KN<9>)]] |
| 109 |
void ok9(); |
| 110 |
[[clang::sycl_kernel_entry_point(KN<10>)]] |
| 111 |
void ok10(); |
| 112 |
void ok10() {} |
| 113 |
void ok11(); |
| 114 |
[[clang::sycl_kernel_entry_point(KN<11>)]] |
| 115 |
void ok11() {} |
| 116 |
|
| 117 |
using VOID = void; |
| 118 |
[[clang::sycl_kernel_entry_point(KN<12>)]] |
| 119 |
VOID ok12(); |
| 120 |
[[clang::sycl_kernel_entry_point(KN<13>)]] |
| 121 |
const void ok13(); |
| 122 |
|
| 123 |
#if __cplusplus >= 202302L |
| 124 |
auto ok14 = [] [[clang::sycl_kernel_entry_point(KN<14>)]] static -> void {}; |
| 125 |
#endif |
| 126 |
|
| 127 |
template<typename KNT, typename T> |
| 128 |
struct S15 { |
| 129 |
// Don't diagnose a dependent return type as a non-void type. |
| 130 |
[[clang::sycl_kernel_entry_point(KNT)]] |
| 131 |
static T ok15(); |
| 132 |
}; |
| 133 |
|
| 134 |
|
| 135 |
//////////////////////////////////////////////////////////////////////////////// |
| 136 |
// Invalid declarations. |
| 137 |
//////////////////////////////////////////////////////////////////////////////// |
| 138 |
|
| 139 |
// The sycl_kernel_entry_point attribute cannot appertain to main() because |
| 140 |
// main() has a non-void return type. However, if the requirement for a void |
| 141 |
// return type were to be relaxed or if an allowance was made for main() to |
| 142 |
// return void (as gcc allows in some modes and as has been proposed to WG21 |
| 143 |
// on occassion), main() still can't function as a SYCL kernel entry point, |
| 144 |
// so this test ensures such attempted uses of the attribute are rejected. |
| 145 |
struct Smain; |
| 146 |
// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute only applies to functions with a 'void' return type}} |
| 147 |
[[clang::sycl_kernel_entry_point(Smain)]] |
| 148 |
int main(); |
| 149 |
|
| 150 |
template<int> struct BADKN; |
| 151 |
|
| 152 |
struct B1 { |
| 153 |
// Non-static data member declaration. |
| 154 |
// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}} |
| 155 |
[[clang::sycl_kernel_entry_point(BADKN<1>)]] |
| 156 |
int bad1; |
| 157 |
}; |
| 158 |
|
| 159 |
struct B2 { |
| 160 |
// Static data member declaration. |
| 161 |
// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}} |
| 162 |
[[clang::sycl_kernel_entry_point(BADKN<2>)]] |
| 163 |
static int bad2; |
| 164 |
}; |
| 165 |
|
| 166 |
struct B3 { |
| 167 |
// Non-static member function declaration. |
| 168 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a non-static member function}} |
| 169 |
[[clang::sycl_kernel_entry_point(BADKN<3>)]] |
| 170 |
void bad3(); |
| 171 |
}; |
| 172 |
|
| 173 |
// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}} |
| 174 |
namespace [[clang::sycl_kernel_entry_point(BADKN<4>)]] bad4 {} |
| 175 |
|
| 176 |
#if __cplusplus >= 202002L |
| 177 |
// expected-error@+2 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}} |
| 178 |
template<typename> |
| 179 |
concept bad5 [[clang::sycl_kernel_entry_point(BADKN<5>)]] = true; |
| 180 |
#endif |
| 181 |
|
| 182 |
// Type alias declarations. |
| 183 |
// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}} |
| 184 |
typedef void bad6 [[clang::sycl_kernel_entry_point(BADKN<6>)]] (); |
| 185 |
// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}} |
| 186 |
using bad7 [[clang::sycl_kernel_entry_point(BADKN<7>)]] = void(); |
| 187 |
// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}} |
| 188 |
using bad8 [[clang::sycl_kernel_entry_point(BADKN<8>)]] = int; |
| 189 |
// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute cannot be applied to types}} |
| 190 |
using bad9 = int [[clang::sycl_kernel_entry_point(BADKN<9>)]]; |
| 191 |
// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute cannot be applied to types}} |
| 192 |
using bad10 = int() [[clang::sycl_kernel_entry_point(BADKN<10>)]]; |
| 193 |
|
| 194 |
// Variable declaration. |
| 195 |
// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}} |
| 196 |
[[clang::sycl_kernel_entry_point(BADKN<11>)]] |
| 197 |
int bad11; |
| 198 |
|
| 199 |
// Class declaration. |
| 200 |
// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}} |
| 201 |
struct [[clang::sycl_kernel_entry_point(BADKN<12>)]] bad12; |
| 202 |
|
| 203 |
// Enumeration declaration. |
| 204 |
// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}} |
| 205 |
enum [[clang::sycl_kernel_entry_point(BADKN<13>)]] bad13 {}; |
| 206 |
|
| 207 |
// Enumerator. |
| 208 |
// expected-error@+2 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}} |
| 209 |
enum { |
| 210 |
bad14 [[clang::sycl_kernel_entry_point(BADKN<14>)]] |
| 211 |
}; |
| 212 |
|
| 213 |
// Attribute added after the definition. |
| 214 |
// expected-error@+3 {{the 'clang::sycl_kernel_entry_point' attribute cannot be added to a function after the function is defined}} |
| 215 |
// expected-note@+1 {{previous definition is here}} |
| 216 |
void bad15() {} |
| 217 |
[[clang::sycl_kernel_entry_point(BADKN<15>)]] |
| 218 |
void bad15(); |
| 219 |
|
| 220 |
// The function must return void. |
| 221 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute only applies to functions with a 'void' return type}} |
| 222 |
[[clang::sycl_kernel_entry_point(BADKN<16>)]] |
| 223 |
int bad16(); |
| 224 |
|
| 225 |
// Function parameters. |
| 226 |
// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}} |
| 227 |
void bad17(void (fp [[clang::sycl_kernel_entry_point(BADKN<17>)]])()); |
| 228 |
|
| 229 |
// Function template parameters. |
| 230 |
// FIXME: Clang currently ignores attributes that appear in template parameters |
| 231 |
// FIXME: and the C++ standard is unclear regarding whether such attributes are |
| 232 |
// FIXME: permitted. P3324 (Attributes for namespace aliases, template |
| 233 |
// FIXME: parameters, and lambda captures) seeks to clarify the situation. |
| 234 |
// FIXME-expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}} |
| 235 |
template<void (fp [[clang::sycl_kernel_entry_point(BADKN<18>)]])()> |
| 236 |
void bad18(); |
| 237 |
|
| 238 |
#if __cplusplus >= 202002L |
| 239 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a coroutine}} |
| 240 |
[[clang::sycl_kernel_entry_point(BADKN<19>)]] |
| 241 |
void bad19() { |
| 242 |
co_return; |
| 243 |
} |
| 244 |
#endif |
| 245 |
|
| 246 |
struct B20 { |
| 247 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a non-static member function}} |
| 248 |
[[clang::sycl_kernel_entry_point(BADKN<20>)]] |
| 249 |
B20(); |
| 250 |
}; |
| 251 |
|
| 252 |
struct B21 { |
| 253 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a non-static member function}} |
| 254 |
[[clang::sycl_kernel_entry_point(BADKN<21>)]] |
| 255 |
~B21(); |
| 256 |
}; |
| 257 |
|
| 258 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a variadic function}} |
| 259 |
[[clang::sycl_kernel_entry_point(BADKN<22>)]] |
| 260 |
void bad22(...); |
| 261 |
|
| 262 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a deleted function}} |
| 263 |
[[clang::sycl_kernel_entry_point(BADKN<23>)]] |
| 264 |
void bad23() = delete; |
| 265 |
|
| 266 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a constexpr function}} |
| 267 |
[[clang::sycl_kernel_entry_point(BADKN<24>)]] |
| 268 |
constexpr void bad24() {} |
| 269 |
|
| 270 |
#if __cplusplus >= 202002L |
| 271 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a consteval function}} |
| 272 |
[[clang::sycl_kernel_entry_point(BADKN<25>)]] |
| 273 |
consteval void bad25() {} |
| 274 |
#endif |
| 275 |
|
| 276 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a function declared with the 'noreturn' attribute}} |
| 277 |
[[clang::sycl_kernel_entry_point(BADKN<26>)]] |
| 278 |
[[noreturn]] void bad26(); |
| 279 |
|
| 280 |
// expected-error@+3 {{attribute 'target' multiversioning cannot be combined with attribute 'clang::sycl_kernel_entry_point'}} |
| 281 |
__attribute__((target("avx"))) void bad27(); |
| 282 |
[[clang::sycl_kernel_entry_point(BADKN<27>)]] |
| 283 |
__attribute__((target("sse4.2"))) void bad27(); |
| 284 |
|
| 285 |
template<typename KNT> |
| 286 |
struct B28 { |
| 287 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a deleted function}} |
| 288 |
[[clang::sycl_kernel_entry_point(KNT)]] |
| 289 |
friend void bad28() = delete; |
| 290 |
}; |
| 291 |
|
| 292 |
#if __cplusplus >= 202002L |
| 293 |
template<typename KNT, typename T> |
| 294 |
struct B29 { |
| 295 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a defaulted function}} |
| 296 |
[[clang::sycl_kernel_entry_point(KNT)]] |
| 297 |
friend T operator==(B29, B29) = default; |
| 298 |
}; |
| 299 |
#endif |
| 300 |
|
| 301 |
#if __cplusplus >= 202002L |
| 302 |
template<typename KNT> |
| 303 |
struct B30 { |
| 304 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a coroutine}} |
| 305 |
[[clang::sycl_kernel_entry_point(KNT)]] |
| 306 |
friend void bad30() { co_return; } |
| 307 |
}; |
| 308 |
#endif |
| 309 |
|
| 310 |
template<typename KNT> |
| 311 |
struct B31 { |
| 312 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a variadic function}} |
| 313 |
[[clang::sycl_kernel_entry_point(KNT)]] |
| 314 |
friend void bad31(...) {} |
| 315 |
}; |
| 316 |
|
| 317 |
template<typename KNT> |
| 318 |
struct B32 { |
| 319 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a constexpr function}} |
| 320 |
[[clang::sycl_kernel_entry_point(KNT)]] |
| 321 |
friend constexpr void bad32() {} |
| 322 |
}; |
| 323 |
|
| 324 |
#if __cplusplus >= 202002L |
| 325 |
template<typename KNT> |
| 326 |
struct B33 { |
| 327 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a consteval function}} |
| 328 |
[[clang::sycl_kernel_entry_point(KNT)]] |
| 329 |
friend consteval void bad33() {} |
| 330 |
}; |
| 331 |
#endif |
| 332 |
|
| 333 |
template<typename KNT> |
| 334 |
struct B34 { |
| 335 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a function declared with the 'noreturn' attribute}} |
| 336 |
[[clang::sycl_kernel_entry_point(KNT)]] |
| 337 |
[[noreturn]] friend void bad34() {} |
| 338 |
}; |
| 339 |
|
| 340 |
#if __cplusplus >= 202302L |
| 341 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a non-static member function}} |
| 342 |
auto bad35 = [] [[clang::sycl_kernel_entry_point(BADKN<35>)]] -> void {}; |
| 343 |
#endif |
| 344 |
|
| 345 |
#if __cplusplus >= 202302L |
| 346 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute only applies to functions with a non-deduced 'void' return type}} |
| 347 |
auto bad36 = [] [[clang::sycl_kernel_entry_point(BADKN<36>)]] static {}; |
| 348 |
#endif |
| 349 |
|
| 350 |
#if __cplusplus >= 202302L |
| 351 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a coroutine}} |
| 352 |
auto bad37 = [] [[clang::sycl_kernel_entry_point(BADKN<37>)]] static -> void { co_return; }; |
| 353 |
#endif |
| 354 |
|
| 355 |
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a function defined with a function try block}} |
| 356 |
[[clang::sycl_kernel_entry_point(BADKN<38>)]] |
| 357 |
void bad38() try {} catch(...) {} |
| 358 |
|
| 359 |
// expected-error@+2 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a function defined with a function try block}} |
| 360 |
template<typename> |
| 361 |
[[clang::sycl_kernel_entry_point(BADKN<39>)]] |
| 362 |
void bad39() try {} catch(...) {} |
| 363 |
|
| 364 |
// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}} |
| 365 |
[[clang::sycl_kernel_entry_point(BADKN<40>)]]; |
| 366 |
|
| 367 |
void bad41() { |
| 368 |
// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute cannot be applied to a statement}} |
| 369 |
[[clang::sycl_kernel_entry_point(BADKN<41>)]]; |
| 370 |
} |
| 371 |
|
| 372 |
struct B42 { |
| 373 |
// expected-warning@+1 {{declaration does not declare anything}} |
| 374 |
[[clang::sycl_kernel_entry_point(BADKN<42>)]]; |
| 375 |
}; |