Skip to content

Commit 16d6af3

Browse files
committed
Emit NDEBUG case to integration header
1 parent 14124ff commit 16d6af3

File tree

2 files changed

+253
-81
lines changed

2 files changed

+253
-81
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4711,36 +4711,43 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
47114711
O << " __SYCL_DLL_LOCAL\n";
47124712
O << " static constexpr bool isESIMD() { return " << K.IsESIMDKernel
47134713
<< "; }\n";
4714-
O << " __SYCL_DLL_LOCAL\n";
4715-
O << " static constexpr const char* getFileName() { return \""
4716-
#ifndef NDEBUG
4714+
O << " static constexpr const char* getFileName() {\n";
4715+
O << "#ifndef NDEBUG\n";
4716+
O << " return \""
47174717
<< std::string(PLoc.getFilename())
4718-
.substr(std::string(PLoc.getFilename()).find_last_of("/\\") + 1)
4719-
#endif
4720-
<< "\"; }\n";
4718+
.substr(std::string(PLoc.getFilename()).find_last_of("/\\") + 1);
4719+
O << "\";\n";
4720+
O << "#else\n";
4721+
O << " return \"\";\n";
4722+
O << "#endif\n";
4723+
O << " }\n";
47214724
O << " __SYCL_DLL_LOCAL\n";
4722-
O << " static constexpr const char* getFunctionName() { return \"";
4723-
#ifndef NDEBUG
4725+
O << " static constexpr const char* getFunctionName() {\n";
4726+
O << "#ifndef NDEBUG\n";
4727+
O << " return \"";
47244728
SYCLKernelNameTypePrinter Printer(O, Policy);
47254729
Printer.Visit(K.NameType);
4726-
#endif
4727-
O << "\"; }\n";
4730+
O << "\";\n";
4731+
O << "#else\n";
4732+
O << " return \"\";\n";
4733+
O << "#endif\n";
4734+
O << " }\n";
47284735
O << " __SYCL_DLL_LOCAL\n";
4729-
O << " static constexpr unsigned getLineNumber() { return "
4730-
#ifndef NDEBUG
4731-
<< PLoc.getLine()
4732-
#else
4733-
<< 0
4734-
#endif
4735-
<< "; }\n";
4736+
O << " static constexpr unsigned getLineNumber() {\n";
4737+
O << "#ifndef NDEBUG\n";
4738+
O << " return " << PLoc.getLine() << ";\n";
4739+
O << "#else\n";
4740+
O << " return 0;\n";
4741+
O << "#endif\n";
4742+
O << " }\n";
47364743
O << " __SYCL_DLL_LOCAL\n";
4737-
O << " static constexpr unsigned getColumnNumber() { return "
4738-
#ifndef NDEBUG
4739-
<< PLoc.getColumn()
4740-
#else
4741-
<< 0
4742-
#endif
4743-
<< "; }\n";
4744+
O << " static constexpr unsigned getColumnNumber() {\n";
4745+
O << "#ifndef NDEBUG\n";
4746+
O << " return " << PLoc.getColumn() << ";\n";
4747+
O << "#else\n";
4748+
O << " return 0;\n";
4749+
O << "#endif\n";
4750+
O << " }\n";
47444751
O << "};\n";
47454752
CurStart += N;
47464753
}
Lines changed: 222 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,266 @@
11
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem -sycl-std=2020 -fsycl-int-header=%t.h %s -o %t.out
22
// RUN: FileCheck -input-file=%t.h %s
33
// RUN: %clang_cc1 -fsycl-is-host -sycl-std=2020 %s | FileCheck -input-file=%t.h %s
4-
// : %clang_cc1 -fsycl-is-device -internal-isystem -sycl-std=2020 -DNDEBUG -fsycl-int-header=%t2.h %s -o %t2.out
5-
// : FileCheck -input-file=%t2.h %s
4+
65
#include "Inputs/sycl.hpp"
7-
#ifndef NDEBUG
6+
7+
// Check that meaningful information is returned when NDEBUG is not defined
8+
// and empty strings and 0s are emitted when it is.
89
int test1() {
910
cl::sycl::queue q;
1011
q.submit([&](cl::sycl::handler &h) { h.single_task([] {}); });
1112
q.submit([&](cl::sycl::handler &h) { h.single_task<class KernelName>([]() {}); });
1213
return 0;
1314
}
14-
// Specializations of KernelInfo for kernel function types:
1515
// CHECK: template <> struct KernelInfoData<'_', 'Z', 'T', 'S', 'Z', 'Z', '5', 't', 'e', 's', 't', '1', 'v', 'E', 'N', 'K', 'U', 'l', 'R', 'N', '2', 'c', 'l', '4', 's', 'y', 'c', 'l', '7', 'h', 'a', 'n', 'd', 'l', 'e', 'r', 'E', 'E', '_', 'c', 'l', 'E', 'S', '2', '_', 'E', 'U', 'l', 'v', 'E', '_'> {
16-
// CHECK: static constexpr const char* getFileName() { return "code_location.cpp"; }
17-
// CHECK: static constexpr const char* getFunctionName() { return ""; }
18-
// CHECK: static constexpr unsigned getLineNumber() { return 10; }
19-
// CHECK: static constexpr unsigned getColumnNumber() { return 54; }
20-
//};
16+
// CHECK: static constexpr const char* getFileName() {
17+
// CHECK: #ifndef NDEBUG
18+
// CHECK: return "code_location.cpp";
19+
// CHECK: #else
20+
// CHECK: return "";
21+
// CHECK: #endif
22+
// CHECK: }
23+
// CHECK: static constexpr const char* getFunctionName() {
24+
// CHECK: #ifndef NDEBUG
25+
// CHECK: return "";
26+
// CHECK: #else
27+
// CHECK: return "";
28+
// CHECK: #endif
29+
// CHECK: }
30+
// CHECK: static constexpr unsigned getLineNumber() {
31+
// CHECK: #ifndef NDEBUG
32+
// CHECK: return 11;
33+
// CHECK: #else
34+
// CHECK: return 0;
35+
// CHECK: #endif
36+
// CHECK: }
37+
// CHECK: static constexpr unsigned getColumnNumber() {
38+
// CHECK: #ifndef NDEBUG
39+
// CHECK: return 54;
40+
// CHECK: #else
41+
// CHECK: return 0;
42+
// CHECK: #endif
43+
// CHECK: }
44+
// CHECK: };
2145

2246
// CHECK: template <> struct KernelInfo<KernelName> {
23-
// CHECK: static constexpr const char* getFileName() { return "code_location.cpp"; }
24-
// CHECK: static constexpr const char* getFunctionName() { return "KernelName"; }
25-
// CHECK: static constexpr unsigned getLineNumber() { return 11; }
26-
// CHECK: static constexpr unsigned getColumnNumber() { return 72; }
27-
//};
47+
// CHECK: static constexpr const char* getFileName() {
48+
// CHECK: #ifndef NDEBUG
49+
// CHECK: return "code_location.cpp";
50+
// CHECK: #else
51+
// CHECK: return "";
52+
// CHECK: #endif
53+
// CHECK: }
54+
// CHECK: __SYCL_DLL_LOCAL
55+
// CHECK: static constexpr const char* getFunctionName() {
56+
// CHECK: #ifndef NDEBUG
57+
// CHECK: return "KernelName";
58+
// CHECK: #else
59+
// CHECK: return "";
60+
// CHECK: #endif
61+
// CHECK: }
62+
// CHECK: __SYCL_DLL_LOCAL
63+
// CHECK: static constexpr unsigned getLineNumber() {
64+
// CHECK: #ifndef NDEBUG
65+
// CHECK: return 12;
66+
// CHECK: #else
67+
// CHECK: return 0;
68+
// CHECK: #endif
69+
// CHECK: }
70+
// CHECK: __SYCL_DLL_LOCAL
71+
// CHECK: static constexpr unsigned getColumnNumber() {
72+
// CHECK: #ifndef NDEBUG
73+
// CHECK: return 72;
74+
// CHECK: #else
75+
// CHECK: return 0;
76+
// CHECK: #endif
77+
// CHECK: }
78+
// CHECK: };
2879

80+
// Check that the right name and location is returned when
81+
// lambda and kernel name are defined on different lines
2982
class KernelName2;
3083
int test2() {
3184
cl::sycl::queue q;
32-
q.submit([&](cl::sycl::handler &h) { h.single_task(
33-
[] { int i = 2; }); });
3485
q.submit([&](cl::sycl::handler &h) { h.single_task<KernelName2>(
3586
[] { int i = 2; }); });
3687
return 0;
3788
}
38-
39-
// CHECK: template <> struct KernelInfoData<'_', 'Z', 'T', 'S', 'Z', 'Z', '5', 't', 'e', 's', 't', '2', 'v', 'E', 'N', 'K', 'U', 'l', 'R', 'N', '2', 'c', 'l', '4', 's', 'y', 'c', 'l', '7', 'h', 'a', 'n', 'd', 'l', 'e', 'r', 'E', 'E', '_', 'c', 'l', 'E', 'S', '2', '_', 'E', 'U', 'l', 'v', 'E', '_'> {
40-
// CHECK: static constexpr const char* getFileName() { return "code_location.cpp"; }
41-
// CHECK: static constexpr const char* getFunctionName() { return ""; }
42-
// CHECK: static constexpr unsigned getLineNumber() { return 33; }
43-
// CHECK: static constexpr unsigned getColumnNumber() { return 44; }
44-
//};
4589
// CHECK: template <> struct KernelInfo<::KernelName2> {
46-
// CHECK: static constexpr const char* getFileName() { return "code_location.cpp"; }
47-
// CHECK: static constexpr const char* getFunctionName() { return "::KernelName2"; }
48-
// CHECK: static constexpr unsigned getLineNumber() { return 35; }
49-
// CHECK: static constexpr unsigned getColumnNumber() { return 44; }
50-
//};
90+
// CHECK: static constexpr const char* getFileName() {
91+
// CHECK: #ifndef NDEBUG
92+
// CHECK: return "code_location.cpp";
93+
// CHECK: #else
94+
// CHECK: return "";
95+
// CHECK: #endif
96+
// CHECK: }
97+
// CHECK: static constexpr const char* getFunctionName() {
98+
// CHECK: #ifndef NDEBUG
99+
// CHECK: return "::KernelName2";
100+
// CHECK: #else
101+
// CHECK: return "";
102+
// CHECK: #endif
103+
// CHECK: }
104+
// CHECK: static constexpr unsigned getLineNumber() {
105+
// CHECK: #ifndef NDEBUG
106+
// CHECK: return 86;
107+
// CHECK: #else
108+
// CHECK: return 0;
109+
// CHECK: #endif
110+
// CHECK: }
111+
// CHECK: static constexpr unsigned getColumnNumber() {
112+
// CHECK: #ifndef NDEBUG
113+
// CHECK: return 44;
114+
// CHECK: #else
115+
// CHECK: return 0;
116+
// CHECK: #endif
117+
// CHECK: }
118+
// CHECK: };
51119

120+
// Check that fully qualified name is returned
52121
template <typename T> class KernelName3;
53122
int test3() {
54123
cl::sycl::queue q;
55124
q.submit([&](cl::sycl::handler &h) { h.single_task<KernelName3<KernelName2>>(
56125
[] { int i = 3; }); });
57126
return 0;
58127
}
59-
60128
// CHECK: template <> struct KernelInfo<::KernelName3<::KernelName2>> {
61-
// CHECK: static constexpr const char* getFileName() { return "code_location.cpp"; }
62-
// CHECK: static constexpr const char* getFunctionName() { return "::KernelName3<::KernelName2>"; }
63-
// CHECK: static constexpr unsigned getLineNumber() { return 56; }
64-
// CHECK: static constexpr unsigned getColumnNumber() { return 44; }
65-
//};
129+
// CHECK: static constexpr const char* getFileName() {
130+
// CHECK: #ifndef NDEBUG
131+
// CHECK: return "code_location.cpp";
132+
// CHECK: #else
133+
// CHECK: return "";
134+
// CHECK: #endif
135+
// CHECK: }
136+
// CHECK: static constexpr const char* getFunctionName() {
137+
// CHECK: #ifndef NDEBUG
138+
// CHECK: return "::KernelName3<::KernelName2>";
139+
// CHECK: #else
140+
// CHECK: return "";
141+
// CHECK: #endif
142+
// CHECK: }
143+
// CHECK: static constexpr unsigned getLineNumber() {
144+
// CHECK: #ifndef NDEBUG
145+
// CHECK: return 125;
146+
// CHECK: #else
147+
// CHECK: return 0;
148+
// CHECK: #endif
149+
// CHECK: }
150+
// CHECK: static constexpr unsigned getColumnNumber() {
151+
// CHECK: #ifndef NDEBUG
152+
// CHECK: return 44;
153+
// CHECK: #else
154+
// CHECK: return 0;
155+
// CHECK: #endif
156+
// CHECK: }
157+
// CHECK: };
66158

159+
// Check that the location information returned is that of l4
67160
auto l4 = []() { return 4; };
68161
int test4() {
69162
cl::sycl::queue q;
70163
q.submit([=](cl::sycl::handler &h) { h.single_task<class KernelName4>(l4); });
71164
return 0;
72165
}
73-
74166
// CHECK: template <> struct KernelInfo<KernelName4> {
75-
// CHECK: static constexpr const char* getFileName() { return "code_location.cpp"; }
76-
// CHECK: static constexpr const char* getFunctionName() { return "KernelName4"; }
77-
// CHECK: static constexpr unsigned getLineNumber() { return 67; }
78-
// CHECK: static constexpr unsigned getColumnNumber() { return 11; }
79-
//};
167+
// CHECK: static constexpr const char* getFileName() {
168+
// CHECK: #ifndef NDEBUG
169+
// CHECK: return "code_location.cpp";
170+
// CHECK: #else
171+
// CHECK: return "";
172+
// CHECK: #endif
173+
// CHECK: }
174+
// CHECK: static constexpr const char* getFunctionName() {
175+
// CHECK: #ifndef NDEBUG
176+
// CHECK: return "KernelName4";
177+
// CHECK: #else
178+
// CHECK: return "";
179+
// CHECK: #endif
180+
// CHECK: }
181+
// CHECK: static constexpr unsigned getLineNumber() {
182+
// CHECK: #ifndef NDEBUG
183+
// CHECK: return 160;
184+
// CHECK: #else
185+
// CHECK: return 0;
186+
// CHECK: #endif
187+
// CHECK: }
188+
// CHECK: static constexpr unsigned getColumnNumber() {
189+
// CHECK: #ifndef NDEBUG
190+
// CHECK: return 11;
191+
// CHECK: #else
192+
// CHECK: return 0;
193+
// CHECK: #endif
194+
// CHECK: }
195+
// CHECK: };
80196

81-
#else
197+
// Check that fully qualified name is returned when unnamed lambda
198+
// kernel is enclosed in a namespace
199+
namespace NS {
82200
int test5() {
83201
cl::sycl::queue q;
84-
q.submit([&](cl::sycl::handler &h) { h.single_task([] {}); });
85-
q.submit([&](cl::sycl::handler &h) { h.single_task<class KernelName5>([]() {}); });
202+
q.submit([=](cl::sycl::handler &h) { h.single_task([] {}); });
203+
q.submit([=](cl::sycl::handler &h) { h.single_task<class KernelName5>([] {}); });
86204
return 0;
87205
}
88-
89-
// HECK: template <> struct KernelInfoData<'_', 'Z', 'T', 'S', 'Z', 'Z', '5', 't', 'e', 's', 't', '5', 'v', 'E', 'N', 'K', 'U', 'l', 'R', 'N', '2', 'c', 'l', '4', 's', 'y', 'c', 'l', '7', 'h', 'a', 'n', 'd', 'l', 'e', 'r', 'E', 'E', '_', 'c', 'l', 'E', 'S', '2', '_', 'E', 'U', 'l', 'v', 'E', '_'> {
90-
// HECK: static constexpr const char* getFileName() { return ; }
91-
// HECK: static constexpr const char* getFunctionName() { return ; }
92-
// HECK: static constexpr unsigned getLineNumber() { return 0; }
93-
// HECK: static constexpr unsigned getColumnNumber() { return 0; }
94-
//};
95-
// HECK: template <> struct KernelInfo<KernelName5> {
96-
// HECK: static constexpr const char* getFileName() { return ; }
97-
// HECK: static constexpr const char* getFunctionName() { return ; }
98-
// HECK: static constexpr unsigned getLineNumber() { return 0; }
99-
// HECK: static constexpr unsigned getColumnNumber() { return 0; }
100-
//};
101-
#endif
206+
} // namespace NS
207+
// CHECK: template <> struct KernelInfoData<'_', 'Z', 'T', 'S', 'Z', 'Z', 'N', '2', 'N', 'S', '5', 't', 'e', 's', 't', '5', 'E', 'v', 'E', 'N', 'K', 'U', 'l', 'R', 'N', '2', 'c', 'l', '4', 's', 'y', 'c', 'l', '7', 'h', 'a', 'n', 'd', 'l', 'e', 'r', 'E', 'E', '_', 'c', 'l', 'E', 'S', '3', '_', 'E', 'U', 'l', 'v', 'E', '_'> {
208+
// CHECK: static constexpr const char* getFileName() {
209+
// CHECK: #ifndef NDEBUG
210+
// CHECK: return "code_location.cpp";
211+
// CHECK: #else
212+
// CHECK: return "";
213+
// CHECK: #endif
214+
// CHECK: }
215+
// CHECK: static constexpr const char* getFunctionName() {
216+
// CHECK: #ifndef NDEBUG
217+
// CHECK: return "NS::";
218+
// CHECK: #else
219+
// CHECK: return "";
220+
// CHECK: #endif
221+
// CHECK: }
222+
// CHECK: static constexpr unsigned getLineNumber() {
223+
// CHECK: #ifndef NDEBUG
224+
// CHECK: return 202;
225+
// CHECK: #else
226+
// CHECK: return 0;
227+
// CHECK: #endif
228+
// CHECK: }
229+
// CHECK: static constexpr unsigned getColumnNumber() {
230+
// CHECK: #ifndef NDEBUG
231+
// CHECK: return 54;
232+
// CHECK: #else
233+
// CHECK: return 0;
234+
// CHECK: #endif
235+
// CHECK: }
236+
// CHECK: };
237+
// CHECK: template <> struct KernelInfo<NS::KernelName5> {
238+
// CHECK: static constexpr const char* getFileName() {
239+
// CHECK: #ifndef NDEBUG
240+
// CHECK: return "code_location.cpp";
241+
// CHECK: #else
242+
// CHECK: return "";
243+
// CHECK: #endif
244+
// CHECK: }
245+
// CHECK: static constexpr const char* getFunctionName() {
246+
// CHECK: #ifndef NDEBUG
247+
// CHECK: return "NS::KernelName5";
248+
// CHECK: #else
249+
// CHECK: return "";
250+
// CHECK: #endif
251+
// CHECK: }
252+
// CHECK: static constexpr unsigned getLineNumber() {
253+
// CHECK: #ifndef NDEBUG
254+
// CHECK: return 203;
255+
// CHECK: #else
256+
// CHECK: return 0;
257+
// CHECK: #endif
258+
// CHECK: }
259+
// CHECK: static constexpr unsigned getColumnNumber() {
260+
// CHECK: #ifndef NDEBUG
261+
// CHECK: return 73;
262+
// CHECK: #else
263+
// CHECK: return 0;
264+
// CHECK: #endif
265+
// CHECK: }
266+
// CHECK: };

0 commit comments

Comments
 (0)