brintos

brintos / llvm-project-archived public Read only

0
0
Text · 13.2 KiB · 9aba284 Raw
376 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++17 -fsyntax-only -fsycl-is-device -verify %s2// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++20 -fsyntax-only -fsycl-is-device -verify %s3// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -fsyntax-only -fsycl-is-device -verify %s4 5// These tests validate appertainment for the sycl_kernel_entry_point attribute.6 7#if __cplusplus >= 202002L8// Mock coroutine support.9namespace std {10 11template<typename Promise = void>12struct coroutine_handle {13  template<typename T>14  coroutine_handle(const coroutine_handle<T>&);15  static coroutine_handle from_address(void *addr);16};17 18template<typename R, typename... Args>19struct 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#endif36 37// A unique kernel name type is required for each declared kernel entry point.38template<int, int = 0> struct KN;39 40 41////////////////////////////////////////////////////////////////////////////////42// Valid declarations.43////////////////////////////////////////////////////////////////////////////////44 45// Function declaration with GNU attribute spelling46// expected-warning@+1 {{unknown attribute 'sycl_kernel_entry_point' ignored}}47__attribute__((sycl_kernel_entry_point(KN<1>)))48void ok1();49 50// Function declaration with C++11 attribute spelling.51[[clang::sycl_kernel_entry_point(KN<2>)]]52void ok2();53 54// Function definition.55[[clang::sycl_kernel_entry_point(KN<3>)]]56void ok3() {}57 58// Function template definition.59template<typename KNT, typename T>60[[clang::sycl_kernel_entry_point(KNT)]]61void ok4(T) {}62 63// Function template explicit specialization.64template<>65[[clang::sycl_kernel_entry_point(KN<4,1>)]]66void ok4<KN<4,1>>(int) {}67 68// Function template explicit instantiation.69template void ok4<KN<4,2>, long>(long);70 71namespace NS {72// Function declaration at namespace scope.73[[clang::sycl_kernel_entry_point(KN<5>)]]74void ok5();75}76 77struct 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.84template<typename KNT>85struct S7 {86  [[clang::sycl_kernel_entry_point(KNT)]]87  friend void ok7(S7) {}88};89void test_ok7() {90  ok7(S7<KN<7>>{});91}92 93// Non-dependent hidden friend definition.94struct S8Base {};95template<typename>96struct S8 : S8Base {97  [[clang::sycl_kernel_entry_point(KN<8>)]]98  friend void ok8(const S8Base&) {}99};100void test_ok8() {101  ok8(S8<int>{});102}103 104// The sycl_kernel_entry_point attribute must match across declarations and105// cannot be added for the first time after a definition.106[[clang::sycl_kernel_entry_point(KN<9>)]]107void ok9();108[[clang::sycl_kernel_entry_point(KN<9>)]]109void ok9();110[[clang::sycl_kernel_entry_point(KN<10>)]]111void ok10();112void ok10() {}113void ok11();114[[clang::sycl_kernel_entry_point(KN<11>)]]115void ok11() {}116 117using VOID = void;118[[clang::sycl_kernel_entry_point(KN<12>)]]119VOID ok12();120[[clang::sycl_kernel_entry_point(KN<13>)]]121const void ok13();122 123#if __cplusplus >= 202302L124auto ok14 = [] [[clang::sycl_kernel_entry_point(KN<14>)]] static -> void {};125#endif126 127template<typename KNT, typename T>128struct 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() because140// main() has a non-void return type. However, if the requirement for a void141// return type were to be relaxed or if an allowance was made for main() to142// return void (as gcc allows in some modes and as has been proposed to WG21143// 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.145struct 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)]]148int main();149 150template<int> struct BADKN;151 152struct 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 159struct 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 166struct 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}}174namespace [[clang::sycl_kernel_entry_point(BADKN<4>)]] bad4 {}175 176#if __cplusplus >= 202002L177// expected-error@+2 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}}178template<typename>179concept bad5 [[clang::sycl_kernel_entry_point(BADKN<5>)]] = true;180#endif181 182// Type alias declarations.183// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}}184typedef void bad6 [[clang::sycl_kernel_entry_point(BADKN<6>)]] ();185// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}}186using bad7 [[clang::sycl_kernel_entry_point(BADKN<7>)]] = void();187// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}}188using bad8 [[clang::sycl_kernel_entry_point(BADKN<8>)]] = int;189// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute cannot be applied to types}}190using bad9 = int [[clang::sycl_kernel_entry_point(BADKN<9>)]];191// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute cannot be applied to types}}192using 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>)]]197int bad11;198 199// Class declaration.200// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}}201struct [[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}}205enum [[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}}209enum {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}}216void bad15() {}217[[clang::sycl_kernel_entry_point(BADKN<15>)]]218void 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>)]]223int bad16();224 225// Function parameters.226// expected-error@+1 {{'clang::sycl_kernel_entry_point' attribute only applies to functions}}227void 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 parameters231// FIXME: and the C++ standard is unclear regarding whether such attributes are232// FIXME: permitted. P3324 (Attributes for namespace aliases, template233// 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}}235template<void (fp [[clang::sycl_kernel_entry_point(BADKN<18>)]])()>236void bad18();237 238#if __cplusplus >= 202002L239// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a coroutine}}240[[clang::sycl_kernel_entry_point(BADKN<19>)]]241void bad19() {242  co_return;243}244#endif245 246struct 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 252struct 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>)]]260void 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>)]]264void 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>)]]268constexpr void bad24() {}269 270#if __cplusplus >= 202002L271// 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>)]]273consteval void bad25() {}274#endif275 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 285template<typename KNT>286struct 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 >= 202002L293template<typename KNT, typename T>294struct 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#endif300 301#if __cplusplus >= 202002L302template<typename KNT>303struct 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#endif309 310template<typename KNT>311struct 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 317template<typename KNT>318struct 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 >= 202002L325template<typename KNT>326struct 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#endif332 333template<typename KNT>334struct 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 >= 202302L341// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a non-static member function}}342auto bad35 = [] [[clang::sycl_kernel_entry_point(BADKN<35>)]] -> void {};343#endif344 345#if __cplusplus >= 202302L346// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute only applies to functions with a non-deduced 'void' return type}}347auto bad36 = [] [[clang::sycl_kernel_entry_point(BADKN<36>)]] static {};348#endif349 350#if __cplusplus >= 202302L351// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a coroutine}}352auto bad37 = [] [[clang::sycl_kernel_entry_point(BADKN<37>)]] static -> void { co_return; };353#endif354 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>)]]357void 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}}360template<typename>361[[clang::sycl_kernel_entry_point(BADKN<39>)]]362void 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 367void 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 372struct B42 {373  // expected-warning@+1 {{declaration does not declare anything}}374  [[clang::sycl_kernel_entry_point(BADKN<42>)]];375};376