xref: /llvm-project/clang/test/SemaSYCL/kernel-attribute.cpp (revision c165a99a1b8861af87e0509a2e14debf2764804b)
1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl-is-device -verify %s
2 
3 // Only function templates
4 [[clang::sycl_kernel]] int gv2 = 0; // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
5 __attribute__((sycl_kernel)) int gv3 = 0; // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
6 
7 __attribute__((sycl_kernel)) void foo(); // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
8 [[clang::sycl_kernel]] void foo1(); // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
9 
10 // Attribute takes no arguments
11 template <typename T, typename A>
12 __attribute__((sycl_kernel(1))) void foo(T P); // expected-error {{'sycl_kernel' attribute takes no arguments}}
13 template <typename T, typename A, int I>
14 [[clang::sycl_kernel(1)]] void foo1(T P);// expected-error {{'sycl_kernel' attribute takes no arguments}}
15 
16 // At least two template parameters
17 template <typename T>
18 __attribute__((sycl_kernel)) void foo(T P); // expected-warning {{'sycl_kernel' attribute only applies to a function template with at least two template parameters}}
19 template <typename T>
20 [[clang::sycl_kernel]] void foo1(T P); // expected-warning {{'sycl_kernel' attribute only applies to a function template with at least two template parameters}}
21 
22 // First two template parameters cannot be non-type template parameters
23 template <typename T, int A>
24 __attribute__((sycl_kernel)) void foo(T P); // expected-warning {{template parameter of a function template with the 'sycl_kernel' attribute cannot be a non-type template parameter}}
25 template <int A, typename T>
26 [[clang::sycl_kernel]] void foo1(T P); // expected-warning {{template parameter of a function template with the 'sycl_kernel' attribute cannot be a non-type template parameter}}
27 
28 // Must return void
29 template <typename T, typename A>
30 __attribute__((sycl_kernel)) int foo(T P); // expected-warning {{function template with 'sycl_kernel' attribute must have a 'void' return type}}
31 template <typename T, typename A>
32 [[clang::sycl_kernel]] int foo1(T P); // expected-warning {{function template with 'sycl_kernel' attribute must have a 'void' return type}}
33 
34 // Must take at least one argument
35 template <typename T, typename A>
36 __attribute__((sycl_kernel)) void foo(); // expected-warning {{function template with 'sycl_kernel' attribute must have a single parameter}}
37 template <typename T, typename A>
38 [[clang::sycl_kernel]] void foo1(T t, A a); // expected-warning {{function template with 'sycl_kernel' attribute must have a single parameter}}
39 
40 // No diagnostics
41 template <typename T, typename A>
42 __attribute__((sycl_kernel)) void foo(T P);
43 template <typename T, typename A, int I>
44 [[clang::sycl_kernel]] void foo1(T P);
45