Skip to content

Commit eb9b823

Browse files
authored
[clang][SYCL] Print canonical types in free function shim functions (#16119)
Somehow even if the outer type was canonical, TypePrinter manages to skip nns printing in case of nested default template arguments. See added test case for the example.
1 parent b7607f0 commit eb9b823

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6510,6 +6510,7 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
65106510
std::string ParmList;
65116511
bool FirstParam = true;
65126512
Policy.SuppressDefaultTemplateArgs = false;
6513+
Policy.PrintCanonicalTypes = true;
65136514
for (ParmVarDecl *Param : K.SyclKernel->parameters()) {
65146515
if (FirstParam)
65156516
FirstParam = false;
@@ -6518,6 +6519,7 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
65186519
ParmList += Param->getType().getCanonicalType().getAsString(Policy);
65196520
}
65206521
FunctionTemplateDecl *FTD = K.SyclKernel->getPrimaryTemplate();
6522+
Policy.PrintCanonicalTypes = false;
65216523
Policy.SuppressDefinition = true;
65226524
Policy.PolishForDeclaration = true;
65236525
Policy.FullyQualifiedName = true;

clang/test/CodeGenSYCL/free_function_default_template_arguments.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,24 @@ templated3(Arg<T, notatuple, a, ns1::hasDefaultArg<>, int, int>, T end) {
6060

6161
template void templated3(Arg<int, notatuple, 3, ns1::hasDefaultArg<>, int, int>, int);
6262

63+
64+
namespace sycl {
65+
template <typename T> struct X {};
66+
template <> struct X<int> {};
67+
namespace detail {
68+
struct Y {};
69+
} // namespace detail
70+
template <> struct X<detail::Y> {};
71+
} // namespace sycl
72+
using namespace sycl;
73+
template <typename T, typename = X<detail::Y>> struct Arg1 { T val; };
74+
75+
[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel",
76+
2)]] void
77+
foo(Arg1<int> arg) {
78+
arg.val = 42;
79+
}
80+
6381
// CHECK: Forward declarations of kernel and its argument types:
6482
// CHECK-NEXT: namespace ns {
6583
// CHECK-NEXT: struct notatuple;
@@ -98,3 +116,17 @@ template void templated3(Arg<int, notatuple, 3, ns1::hasDefaultArg<>, int, int>,
98116
// CHECK-NEXT: static constexpr auto __sycl_shim5() {
99117
// 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>;
100118
// CHECK-NEXT: }
119+
120+
// CHECK Forward declarations of kernel and its argument types:
121+
// CHECK: namespace sycl { namespace detail {
122+
// CHECK-NEXT: struct Y;
123+
// CHECK-NEXT: }}
124+
// CHECK-NEXT: namespace sycl {
125+
// CHECK-NEXT: template <typename T> struct X;
126+
// CHECK-NEXT: }
127+
// CHECK-NEXT: template <typename T, typename> struct Arg1;
128+
129+
// CHECK: void foo(Arg1<int, sycl::X<sycl::detail::Y> > arg);
130+
// CHECK-NEXT: static constexpr auto __sycl_shim6() {
131+
// CHECK-NEXT: return (void (*)(struct Arg1<int, struct sycl::X<struct sycl::detail::Y> >))foo;
132+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)