Skip to content

Commit 5d9a176

Browse files
[SYCL] Fix error with type aliases used as free function kernel args (#20123)
This PR fixes type name that is being printed as free function kernel argument type in its forward-declaration in the integration header. Before the change, we used the original argument type name, which could be an alias - this patch makes use of the canonical type's name to make sure that all type aliases are "unwrapped".
1 parent 09cccf3 commit 5d9a176

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6822,13 +6822,13 @@ class FreeFunctionPrinter {
68226822
continue;
68236823
}
68246824

6825-
TemplateName TN = TST->getTemplateName();
6825+
TemplateName CTN = CTST->getTemplateName();
6826+
CTN.getAsTemplateDecl()->printQualifiedName(ParmListOstream);
6827+
ParmListOstream << "<";
6828+
68266829
auto SpecArgs = TST->template_arguments();
68276830
auto DeclArgs = CTST->template_arguments();
68286831

6829-
TN.getAsTemplateDecl()->printQualifiedName(ParmListOstream);
6830-
ParmListOstream << "<";
6831-
68326832
for (size_t I = 0, E = std::max(DeclArgs.size(), SpecArgs.size()),
68336833
SE = SpecArgs.size();
68346834
I < E; ++I) {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -triple spir64-unknown-unknown -sycl-std=2020 -fsycl-int-header=%t.h %s
2+
// RUN: FileCheck -input-file=%t.h %s
3+
//
4+
// The purpose of this test is to ensure that forward declarations of free
5+
// function kernels are emitted properly.
6+
// However, this test checks a specific scenario:
7+
// - free function arguments are type aliases (through using or typedef)
8+
9+
namespace ns {
10+
11+
using IntUsing = int;
12+
typedef int IntTypedef;
13+
14+
template <typename T>
15+
struct Foo {};
16+
17+
using FooIntUsing = Foo<int>;
18+
typedef Foo<int> FooIntTypedef;
19+
20+
template <typename T1, typename T2>
21+
struct Bar {};
22+
23+
template<typename T1>
24+
using BarUsing = Bar<T1, float>;
25+
26+
class Baz {
27+
public:
28+
using type = BarUsing<double>;
29+
};
30+
31+
} // namespace ns
32+
33+
[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]]
34+
void int_using(ns::IntUsing Arg) {}
35+
36+
// CHECK: void int_using(int Arg);
37+
38+
[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]]
39+
void int_typedef(ns::IntTypedef Arg) {}
40+
41+
// CHECK: void int_typedef(int Arg);
42+
43+
[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]]
44+
void foo_using(ns::FooIntUsing Arg) {}
45+
46+
// CHECK: void foo_using(ns::Foo<int> Arg);
47+
48+
[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]]
49+
void foo_typedef(ns::FooIntTypedef Arg) {}
50+
51+
// CHECK: void foo_typedef(ns::Foo<int> Arg);
52+
53+
template<typename T>
54+
[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]]
55+
void bar_using(ns::BarUsing<T> Arg) {}
56+
template void bar_using(ns::BarUsing<int>);
57+
58+
// CHECK: template <typename T> void bar_using(ns::Bar<T, float>);
59+
60+
[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]]
61+
void baz_type(ns::Baz::type Arg) {}
62+
63+
// CHECK: void baz_type(ns::Bar<double, float> Arg);

0 commit comments

Comments
 (0)