Skip to content

Commit 7e2272f

Browse files
committed
Add more tests, clean SemaSYCL
1 parent 4f091c0 commit 7e2272f

File tree

2 files changed

+52
-14
lines changed

2 files changed

+52
-14
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6464,14 +6464,14 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
64646464

64656465
O << "\n";
64666466
O << "// Forward declarations of kernel and its argument types:\n";
6467-
Policy.SuppressDefaultTemplateArgs = false;
64686467
FwdDeclEmitter.Visit(K.SyclKernel->getType());
64696468
O << "\n";
64706469

64716470
if (K.SyclKernel->getLanguageLinkage() == CLanguageLinkage)
64726471
O << "extern \"C\" ";
64736472
std::string ParmList;
64746473
bool FirstParam = true;
6474+
Policy.SuppressDefaultTemplateArgs = false;
64756475
for (ParmVarDecl *Param : K.SyclKernel->parameters()) {
64766476
if (FirstParam)
64776477
FirstParam = false;
@@ -6482,9 +6482,21 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
64826482
FunctionTemplateDecl *FTD = K.SyclKernel->getPrimaryTemplate();
64836483
Policy.SuppressDefinition = true;
64846484
Policy.PolishForDeclaration = true;
6485-
Policy.EnforceDefaultTemplateArgs = true;
64866485
Policy.FullyQualifiedName = true;
64876486
Policy.EnforceScopeForElaboratedTypes = true;
6487+
6488+
// SuppressDefaultTemplateArguments is a downstream addition that suppresses
6489+
// default template arguments in function declarations. It should be set to
6490+
// true to emit function declaration that won't cause any compilation errors
6491+
// when present in the integration header.
6492+
// SuppressDefaultTemplateArgs is a flag from community code which adds
6493+
// suppression of template arguments that match default template arguments
6494+
// in template-ids printing.
6495+
Policy.SuppressDefaultTemplateArguments = true;
6496+
// EnforceDefaultTemplateArgs is a downstream addition that forces printing
6497+
// template arguments that match default template arguments while printing
6498+
// template-ids, even if the source code doesn't referece them.
6499+
Policy.EnforceDefaultTemplateArgs = true;
64886500
if (FTD) {
64896501
FTD->print(O, Policy);
64906502
} else {
@@ -6513,10 +6525,6 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
65136525
}
65146526
O << ";\n";
65156527
O << "}\n";
6516-
Policy.SuppressDefaultTemplateArgs = true;
6517-
Policy.EnforceDefaultTemplateArgs = false;
6518-
Policy.FullyQualifiedName = false;
6519-
Policy.EnforceScopeForElaboratedTypes = false;
65206528

65216529
// Generate is_kernel, is_single_task_kernel and nd_range_kernel functions.
65226530
O << "namespace sycl {\n";

clang/test/CodeGenSYCL/free_function_default_template_arguments.cpp

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -triple spir64-unknown-unknown -sycl-std=2020 -fsycl-int-header=%t.h %s
22
// RUN: FileCheck -input-file=%t.h %s
33

4-
// This test checks integration header contents free functions kernels in
5-
// presense of template arguments.
4+
// This test checks integration header contents for free functions kernels with
5+
// parameter types that have default template arguments.
66

77
#include "mock_properties.hpp"
88
#include "sycl.hpp"
@@ -13,6 +13,13 @@ struct notatuple {
1313
int a;
1414
};
1515

16+
namespace ns1 {
17+
template <typename A = notatuple>
18+
class hasDefaultArg {
19+
20+
};
21+
}
22+
1623
template <typename T, typename = int, int a = 12, typename = notatuple, typename ...TS> struct Arg {
1724
T val;
1825
};
@@ -24,6 +31,11 @@ simple(Arg<char>){
2431

2532
}
2633

34+
[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel",
35+
2)]] void
36+
simple1(ns::Arg<ns::ns1::hasDefaultArg<>>){
37+
}
38+
2739

2840
template <typename T>
2941
[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]] void
@@ -41,7 +53,12 @@ templated2(Arg<T, notatuple>, T end) {
4153

4254
template void templated2(Arg<int, notatuple>, int);
4355

44-
// CHECK: Definition of _ZN16__sycl_kernel_ns6simpleENS_3ArgIciLi12ENS_9notatupleEJEEE as a free function kernel
56+
template <typename T, int a = 3>
57+
[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]] void
58+
templated3(Arg<T, notatuple, a, ns1::hasDefaultArg<>, int, int>, T end) {
59+
}
60+
61+
template void templated3(Arg<int, notatuple, 3, ns1::hasDefaultArg<>, int, int>, int);
4562

4663
// CHECK: Forward declarations of kernel and its argument types:
4764
// CHECK-NEXT: namespace ns {
@@ -56,15 +73,28 @@ template void templated2(Arg<int, notatuple>, int);
5673
// CHECK-NEXT: return (void (*)(struct ns::Arg<char, int, 12, struct ns::notatuple>))simple;
5774
// CHECK-NEXT: }
5875

59-
// CHECK: Definition of _Z23__sycl_kernel_templatedIiEvN2ns3ArgIT_fLi3ENS0_9notatupleEJEEES2_ as a free function kernel
60-
// CHECK: template <typename T> void templated(ns::Arg<T, float, 3, ns::notatuple>, T end);
76+
// CHECK: Forward declarations of kernel and its argument types:
77+
// CHECK: namespace ns {
78+
// CHECK: namespace ns1 {
79+
// CHECK-NEXT: template <typename A> class hasDefaultArg;
80+
// CHECK-NEXT: }
81+
82+
// CHECK: void simple1(ns::Arg<ns::ns1::hasDefaultArg<ns::notatuple>, int, 12, ns::notatuple>);
6183
// CHECK-NEXT: static constexpr auto __sycl_shim2() {
84+
// CHECK-NEXT: return (void (*)(struct ns::Arg<class ns::ns1::hasDefaultArg<struct ns::notatuple>, int, 12, struct ns::notatuple>))simple1;
85+
// CHECK-NEXT: }
86+
87+
// CHECK: template <typename T> void templated(ns::Arg<T, float, 3, ns::notatuple>, T end);
88+
// CHECK-NEXT: static constexpr auto __sycl_shim3() {
6289
// CHECK-NEXT: return (void (*)(struct ns::Arg<int, float, 3, struct ns::notatuple>, int))templated<int>;
6390
// CHECK-NEXT: }
6491

65-
// CHECK: Definition of _Z24__sycl_kernel_templated2IiEvN2ns3ArgIT_NS0_9notatupleELi12ES3_JEEES2_ as a free function kernel
66-
// CHECK: Forward declarations of kernel and its argument types:
6792
// CHECK: template <typename T> void templated2(ns::Arg<T, ns::notatuple, 12, ns::notatuple>, T end);
68-
// CHECK-NEXT: static constexpr auto __sycl_shim3() {
93+
// CHECK-NEXT: static constexpr auto __sycl_shim4() {
6994
// CHECK-NEXT: return (void (*)(struct ns::Arg<int, struct ns::notatuple, 12, struct ns::notatuple>, int))templated2<int>;
7095
// CHECK-NEXT: }
96+
97+
// CHECK: template <typename T, int a> void templated3(ns::Arg<T, ns::notatuple, a, ns::ns1::hasDefaultArg<ns::notatuple>, int, int>, T end);
98+
// CHECK-NEXT: static constexpr auto __sycl_shim5() {
99+
// CHECK-NEXT: return (void (*)(struct ns::Arg<int, struct ns::notatuple, 3, class ns::ns1::hasDefaultArg<struct ns::notatuple>, int, int>, int))templated3<int, 3>;
100+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)