[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / ASTSYCL / ast-dump-sycl-kernel-entry-point.cpp
blobc351f3b7d03eab1c34ffdad35e622fb652b074f3
1 // Tests without serialization:
2 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -fsycl-is-device \
3 // RUN: -ast-dump %s \
4 // RUN: | FileCheck --match-full-lines %s
5 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -fsycl-is-host \
6 // RUN: -ast-dump %s \
7 // RUN: | FileCheck --match-full-lines %s
8 //
9 // Tests with serialization:
10 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -fsycl-is-device \
11 // RUN: -emit-pch -o %t %s
12 // RUN: %clang_cc1 -x c++ -std=c++17 -triple x86_64-unknown-unknown -fsycl-is-device \
13 // RUN: -include-pch %t -ast-dump-all /dev/null \
14 // RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
15 // RUN: | FileCheck --match-full-lines %s
16 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -fsycl-is-host \
17 // RUN: -emit-pch -o %t %s
18 // RUN: %clang_cc1 -x c++ -std=c++17 -triple x86_64-unknown-unknown -fsycl-is-host \
19 // RUN: -include-pch %t -ast-dump-all /dev/null \
20 // RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
21 // RUN: | FileCheck --match-full-lines %s
23 // These tests validate the AST produced for functions declared with the
24 // sycl_kernel_entry_point attribute.
26 // CHECK: TranslationUnitDecl {{.*}}
28 // A unique kernel name type is required for each declared kernel entry point.
29 template<int, int=0> struct KN;
31 __attribute__((sycl_kernel_entry_point(KN<1>)))
32 void skep1() {
34 // CHECK: |-FunctionDecl {{.*}} skep1 'void ()'
35 // CHECK: | `-SYCLKernelEntryPointAttr {{.*}} KN<1>
37 using KN2 = KN<2>;
38 __attribute__((sycl_kernel_entry_point(KN2)))
39 void skep2() {
41 // CHECK: |-FunctionDecl {{.*}} skep2 'void ()'
42 // CHECK: | `-SYCLKernelEntryPointAttr {{.*}} KN2
44 template<int I> using KNT = KN<I>;
45 __attribute__((sycl_kernel_entry_point(KNT<3>)))
46 void skep3() {
48 // CHECK: |-FunctionDecl {{.*}} skep3 'void ()'
49 // CHECK: | `-SYCLKernelEntryPointAttr {{.*}} KNT<3>
51 template<typename KNT, typename F>
52 [[clang::sycl_kernel_entry_point(KNT)]]
53 void skep4(F f) {
54 f();
56 // CHECK: |-FunctionTemplateDecl {{.*}} skep4
57 // CHECK-NEXT: | |-TemplateTypeParmDecl {{.*}} KNT
58 // CHECK-NEXT: | |-TemplateTypeParmDecl {{.*}} F
59 // CHECK-NEXT: | |-FunctionDecl {{.*}} skep4 'void (F)'
60 // CHECK: | | `-SYCLKernelEntryPointAttr {{.*}} KNT
62 void test_skep4() {
63 skep4<KNT<4>>([]{});
65 // CHECK: | `-FunctionDecl {{.*}} used skep4 'void ((lambda at {{.*}}))' implicit_instantiation
66 // CHECK-NEXT: | |-TemplateArgument type 'KN<4>'
67 // CHECK: | |-TemplateArgument type '(lambda at {{.*}})'
68 // CHECK: | `-SYCLKernelEntryPointAttr {{.*}} struct KN<4>
69 // CHECK-NEXT: |-FunctionDecl {{.*}} test_skep4 'void ()'
71 template<typename KNT, typename T>
72 [[clang::sycl_kernel_entry_point(KNT)]]
73 void skep5(T) {
75 // CHECK: |-FunctionTemplateDecl {{.*}} skep5
76 // CHECK-NEXT: | |-TemplateTypeParmDecl {{.*}} KNT
77 // CHECK-NEXT: | |-TemplateTypeParmDecl {{.*}} T
78 // CHECK-NEXT: | |-FunctionDecl {{.*}} skep5 'void (T)'
79 // CHECK: | | `-SYCLKernelEntryPointAttr {{.*}} KNT
81 // Checks for the explicit template instantiation declaration below.
82 // CHECK: | `-FunctionDecl {{.*}} skep5 'void (int)' explicit_instantiation_definition
83 // CHECK-NEXT: | |-TemplateArgument type 'KN<5, 4>'
84 // CHECK: | |-TemplateArgument type 'int'
85 // CHECK: | `-SYCLKernelEntryPointAttr {{.*}} KN<5, 4>
87 // FIXME: C++23 [temp.expl.spec]p12 states:
88 // FIXME: ... Similarly, attributes appearing in the declaration of a template
89 // FIXME: have no effect on an explicit specialization of that template.
90 // FIXME: Clang currently instantiates and propagates attributes from a function
91 // FIXME: template to its explicit specializations resulting in the following
92 // FIXME: explicit specialization having an attribute incorrectly attached.
93 template<>
94 void skep5<KN<5,1>>(short) {
96 // CHECK: |-FunctionDecl {{.*}} prev {{.*}} skep5 'void (short)' explicit_specialization
97 // CHECK-NEXT: | |-TemplateArgument type 'KN<5, 1>'
98 // CHECK: | |-TemplateArgument type 'short'
99 // CHECK: | `-SYCLKernelEntryPointAttr {{.*}} Inherited struct KN<5, 1>
101 template<>
102 [[clang::sycl_kernel_entry_point(KN<5,2>)]]
103 void skep5<KN<5,2>>(long) {
105 // CHECK: |-FunctionDecl {{.*}} prev {{.*}} skep5 'void (long)' explicit_specialization
106 // CHECK-NEXT: | |-TemplateArgument type 'KN<5, 2>'
107 // CHECK: | |-TemplateArgument type 'long'
108 // CHECK: | `-SYCLKernelEntryPointAttr {{.*}} KN<5, 2>
110 template<>
111 [[clang::sycl_kernel_entry_point(KN<5,3>)]]
112 void skep5<KN<5,-1>>(long long) {
114 // CHECK: |-FunctionDecl {{.*}} prev {{.*}} skep5 'void (long long)' explicit_specialization
115 // CHECK-NEXT: | |-TemplateArgument type 'KN<5, -1>'
116 // CHECK: | |-TemplateArgument type 'long long'
117 // CHECK: | `-SYCLKernelEntryPointAttr {{.*}} KN<5, 3>
119 template void skep5<KN<5,4>>(int);
120 // Checks are located with the primary template declaration above.
122 // Ensure that matching attributes from multiple declarations are ok.
123 [[clang::sycl_kernel_entry_point(KN<6>)]]
124 void skep6();
125 [[clang::sycl_kernel_entry_point(KN<6>)]]
126 void skep6() {
128 // CHECK: |-FunctionDecl {{.*}} skep6 'void ()'
129 // CHECK-NEXT: | `-SYCLKernelEntryPointAttr {{.*}} KN<6>
130 // CHECK-NEXT: |-FunctionDecl {{.*}} prev {{.*}} skep6 'void ()'
131 // CHECK-NEXT: | |-CompoundStmt {{.*}}
132 // CHECK-NEXT: | `-SYCLKernelEntryPointAttr {{.*}} KN<6>
134 // Ensure that matching attributes from the same declaration are ok.
135 [[clang::sycl_kernel_entry_point(KN<7>), clang::sycl_kernel_entry_point(KN<7>)]]
136 void skep7() {
138 // CHECK: |-FunctionDecl {{.*}} skep7 'void ()'
139 // CHECK-NEXT: | |-CompoundStmt {{.*}}
140 // CHECK-NEXT: | |-SYCLKernelEntryPointAttr {{.*}} KN<7>
141 // CHECK-NEXT: | `-SYCLKernelEntryPointAttr {{.*}} KN<7>
143 void the_end() {}
144 // CHECK: `-FunctionDecl {{.*}} the_end 'void ()'