Skip to content

Commit 9a01c12

Browse files
committed
[SYCL] Fix one more bug in int-header generation
When free function kernel defined as a template has an argument whose type is an alias, we need to look into the underlying type, or otherwise we emit nonsense.
1 parent 9ebbd0a commit 9a01c12

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6814,13 +6814,18 @@ class FreeFunctionPrinter {
68146814
QualType T = Param->getType();
68156815
QualType CT = T.getCanonicalType();
68166816

6817-
auto *TST = dyn_cast<TemplateSpecializationType>(T.getTypePtr());
6818-
auto *CTST = dyn_cast<TemplateSpecializationType>(CT.getTypePtr());
6817+
const auto *TST = dyn_cast<TemplateSpecializationType>(T.getTypePtr());
6818+
const auto *CTST = dyn_cast<TemplateSpecializationType>(CT.getTypePtr());
68196819
if (!TST || !CTST) {
68206820
ParmListOstream << T.getAsString(Policy);
68216821
continue;
68226822
}
68236823

6824+
const TemplateSpecializationType *TSTAsNonAlias =
6825+
TST->getAsNonAliasTemplateSpecializationType();
6826+
if (TSTAsNonAlias)
6827+
TST = TSTAsNonAlias;
6828+
68246829
TemplateName CTN = CTST->getTemplateName();
68256830
CTN.getAsTemplateDecl()->printQualifiedName(ParmListOstream);
68266831
ParmListOstream << "<";

clang/test/CodeGenSYCL/free-function-kernel-type-alias-arg.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ struct Bar {};
2323
template<typename T1>
2424
using BarUsing = Bar<T1, float>;
2525

26+
template<typename T1, typename T2>
27+
using BarUsing2 = Bar<Foo<T2>, T1>;
28+
2629
class Baz {
2730
public:
2831
using type = BarUsing<double>;
2932
};
3033

34+
template <typename T1, typename T2, typename T3 = BarUsing2<T1, T2>,
35+
typename T4 = BarUsing<T2>>
36+
struct AliasAsDefaultArg {};
37+
3138
} // namespace ns
3239

3340
[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]]
@@ -57,7 +64,25 @@ template void bar_using(ns::BarUsing<int>);
5764

5865
// CHECK: template <typename T> void bar_using(ns::Bar<T, float>);
5966

67+
template<typename T1, typename T2>
68+
[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]]
69+
void bar_using2(ns::BarUsing2<T1, T2> Arg) {}
70+
template void bar_using2(ns::BarUsing2<int, float>);
71+
72+
// CHECK: template <typename T1, typename T2> void bar_using2(ns::Bar<ns::Foo<T2>, T1>);
73+
6074
[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]]
6175
void baz_type(ns::Baz::type Arg) {}
6276

6377
// CHECK: void baz_type(ns::Bar<double, float> Arg);
78+
79+
#if 0
80+
// This test case fails, but it is added here in advance to add a record of a
81+
// known bug.
82+
template<typename T1, typename T2>
83+
[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]]
84+
void alias_as_default_template_arg(ns::AliasAsDefaultArg<T1, T2> Arg) {}
85+
template void alias_as_default_template_arg(ns::AliasAsDefaultArg<int, float>);
86+
87+
// CHECK-DISABLED: template <typename T1, typename T2> void alias_as_default_template_arg(ns::AliasAsDefaultArg<T1, T2, ns::Bar<ns::Foo<T2>, T1>, ns::Bar<T2, float>>);
88+
#endif

0 commit comments

Comments
 (0)