[update_cc_test_checks] Add test for missing handling of mangled names
[llvm-project.git] / clang / test / SemaSYCL / sycl-kernel-entry-point-attr-grammar.cpp
blobc63d241163e618359109b656d7dddef0955d8d55
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
4 // These tests validate parsing of the sycl_kernel_entry_point argument list
5 // and that the single argument names a type.
7 // Templates used to exercise class template specializations.
8 template<int> struct ST; // #ST-decl
9 template<int N> using TTA = ST<N>; // #TTA-decl
12 ////////////////////////////////////////////////////////////////////////////////
13 // Valid declarations.
14 ////////////////////////////////////////////////////////////////////////////////
16 struct S1;
17 [[clang::sycl_kernel_entry_point(S1)]] void ok1();
19 typedef struct {} TA2;
20 [[clang::sycl_kernel_entry_point(TA2)]] void ok2();
22 using TA3 = struct {};
23 [[clang::sycl_kernel_entry_point(TA3)]] void ok3();
25 [[clang::sycl_kernel_entry_point(ST<4>)]] void ok4();
27 [[clang::sycl_kernel_entry_point(TTA<5>)]] void ok5();
29 namespace NS6 {
30 struct NSS;
32 [[clang::sycl_kernel_entry_point(NS6::NSS)]] void ok6();
34 namespace {
35 struct UNSS7;
37 [[clang::sycl_kernel_entry_point(UNSS7)]] void ok7();
39 struct {} s;
40 [[clang::sycl_kernel_entry_point(decltype(s))]] void ok8();
42 template<typename KN>
43 [[clang::sycl_kernel_entry_point(KN)]] void ok9();
44 void test_ok9() {
45 ok9<struct LS1>();
48 template<int, typename KN>
49 [[clang::sycl_kernel_entry_point(KN)]] void ok10();
50 void test_ok10() {
51 ok10<1, struct LS2>();
54 namespace NS11 {
55 struct NSS;
57 template<typename T>
58 [[clang::sycl_kernel_entry_point(T)]] void ok11() {}
59 template<>
60 [[clang::sycl_kernel_entry_point(NS11::NSS)]] void ok11<NS11::NSS>() {}
62 struct S12;
63 [[clang::sycl_kernel_entry_point(S12)]] void ok12();
64 [[clang::sycl_kernel_entry_point(S12)]] void ok12() {}
66 template<typename T>
67 [[clang::sycl_kernel_entry_point(T)]] void ok13(T k);
68 void test_ok13() {
69 ok13([]{});
73 ////////////////////////////////////////////////////////////////////////////////
74 // Invalid declarations.
75 ////////////////////////////////////////////////////////////////////////////////
77 // expected-error@+1 {{'sycl_kernel_entry_point' attribute takes one argument}}
78 [[clang::sycl_kernel_entry_point]] void bad1();
80 // expected-error@+1 {{'sycl_kernel_entry_point' attribute takes one argument}}
81 [[clang::sycl_kernel_entry_point()]] void bad2();
83 struct B3;
84 // expected-error@+2 {{expected ')'}}
85 // expected-error@+1 {{expected ']'}}
86 [[clang::sycl_kernel_entry_point(B3,)]] void bad3();
88 struct B4;
89 // expected-error@+3 {{expected ')'}}
90 // expected-error@+2 {{expected ','}}
91 // expected-warning@+1 {{unknown attribute 'X' ignored}}
92 [[clang::sycl_kernel_entry_point(B4, X)]] void bad4();
94 // expected-error@+1 {{expected a type}}
95 [[clang::sycl_kernel_entry_point(1)]] void bad5();
97 void f6();
98 // expected-error@+1 {{unknown type name 'f6'}}
99 [[clang::sycl_kernel_entry_point(f6)]] void bad6();
101 // expected-error@+2 {{use of class template 'ST' requires template arguments; argument deduction not allowed here}}
102 // expected-note@#ST-decl {{template is declared here}}
103 [[clang::sycl_kernel_entry_point(ST)]] void bad7();
105 // expected-error@+2 {{use of alias template 'TTA' requires template arguments; argument deduction not allowed here}}
106 // expected-note@#TTA-decl {{template is declared here}}
107 [[clang::sycl_kernel_entry_point(TTA)]] void bad8();
109 enum {
112 // expected-error@+1 {{unknown type name 'e9'}}
113 [[clang::sycl_kernel_entry_point(e9)]] void bad9();
115 #if __cplusplus >= 202002L
116 template<typename> concept C = true;
117 // expected-error@+1 {{expected a type}}
118 [[clang::sycl_kernel_entry_point(C)]] void bad10();
120 // expected-error@+1 {{expected a type}}
121 [[clang::sycl_kernel_entry_point(C<int>)]] void bad11();
122 #endif
124 struct B12; // #B12-decl
125 // FIXME: C++23 [temp.expl.spec]p12 states:
126 // FIXME: ... Similarly, attributes appearing in the declaration of a template
127 // FIXME: have no effect on an explicit specialization of that template.
128 // FIXME: Clang currently instantiates and propagates attributes from a function
129 // FIXME: template to its explicit specializations resulting in the following
130 // FIXME: spurious error.
131 // expected-error@+4 {{incomplete type 'B12' named in nested name specifier}}
132 // expected-note@+5 {{in instantiation of function template specialization 'bad12<B12>' requested here}}
133 // expected-note@#B12-decl {{forward declaration of 'B12'}}
134 template<typename T>
135 [[clang::sycl_kernel_entry_point(typename T::not_found)]] void bad12() {}
136 template<>
137 void bad12<B12>() {}