Skip to content

Commit c19372e

Browse files
author
Ilya Stepykin
authored
[SYCL] Don't emit 'typename' for aliases in integration header. (#1055)
Skip keyword printing if SuppressTypedefs policy is used. Signed-off-by: Ilya Stepykin <[email protected]>
1 parent 478b7c0 commit c19372e

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

clang/include/clang/AST/PrettyPrinter.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,13 @@ struct PrintingPolicy {
169169
/// When true, suppress printing of lifetime qualifier in ARC.
170170
unsigned SuppressLifetimeQualifiers : 1;
171171

172-
/// When true prints a canonical type instead of an alias. E.g.
172+
/// When true prints a canonical type instead of an alias.
173+
/// Also removes preceeding keywords if there is one. E.g.
173174
/// \code
174-
/// using SizeT = int;
175-
/// template<SizeT N> class C;
175+
/// namespace NS {
176+
/// using SizeT = int;
177+
/// }
178+
/// template<typename NS::SizeT N> class C;
176179
/// \endcode
177180
/// will be printed as
178181
/// \code

clang/lib/AST/TypePrinter.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,9 +1327,14 @@ void TypePrinter::printElaboratedBefore(const ElaboratedType *T,
13271327
// The tag definition will take care of these.
13281328
if (!Policy.IncludeTagDefinition)
13291329
{
1330-
OS << TypeWithKeyword::getKeywordName(T->getKeyword());
1331-
if (T->getKeyword() != ETK_None)
1332-
OS << " ";
1330+
// When removing aliases don't print keywords to avoid having things
1331+
// like 'typename int'
1332+
if (!Policy.SuppressTypedefs)
1333+
{
1334+
OS << TypeWithKeyword::getKeywordName(T->getKeyword());
1335+
if (T->getKeyword() != ETK_None)
1336+
OS << " ";
1337+
}
13331338
NestedNameSpecifier *Qualifier = T->getQualifier();
13341339
if (Qualifier && !(Policy.SuppressTypedefs &&
13351340
T->getNamedType()->getTypeClass() == Type::Typedef))

clang/test/CodeGenSYCL/kernel_name_with_typedefs.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ struct kernel_name2<space::clong_t, volatile space::culong_t> {};
8585
template <>
8686
struct kernel_name2<space::a_t, volatile space::b_t> {};
8787

88+
// CHECK: template <long T> struct kernel_name3;
89+
template <typename space::long_t T>
90+
struct kernel_name3;
91+
92+
struct foo {
93+
using type = long;
94+
};
95+
96+
// CHECK: template <long T> struct kernel_name4;
97+
template <typename foo::type T>
98+
struct kernel_name4;
99+
88100
int main() {
89101
dummy_functor f;
90102
// non-type template arguments
@@ -116,5 +128,10 @@ int main() {
116128
single_task<kernel_name2<space::clong_t, volatile space::culong_t>>(f);
117129
// CHECK: template <> struct KernelInfo<::kernel_name2< ::A, volatile ::space::B>> {
118130
single_task<kernel_name2<space::a_t, volatile space::b_t>>(f);
131+
// CHECK: template <> struct KernelInfo<::kernel_name3<1>> {
132+
single_task<kernel_name3<1>>(f);
133+
// CHECK: template <> struct KernelInfo<::kernel_name4<1>> {
134+
single_task<kernel_name4<1>>(f);
135+
119136
return 0;
120137
}

0 commit comments

Comments
 (0)