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