Skip to content

Commit ebefb26

Browse files
[SYCL] Replace C-style cast to static_cast for KernelNameType (#1895)
Cast integer to enumeration type using static_cast for kernels defined as templated function object where the template parameter is of enum type (scoped and unscoped).
1 parent 5a1ef01 commit ebefb26

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2145,7 +2145,9 @@ static void printArgument(ASTContext &Ctx, raw_ostream &ArgOS,
21452145

21462146
if (ET) {
21472147
const llvm::APSInt &Val = Arg.getAsIntegral();
2148-
ArgOS << "(" << ET->getDecl()->getQualifiedNameAsString() << ")" << Val;
2148+
ArgOS << "static_cast<" << ET->getDecl()->getQualifiedNameAsString()
2149+
<< ">"
2150+
<< "(" << Val << ")";
21492151
} else {
21502152
Arg.print(P, ArgOS);
21512153
}

clang/test/CodeGenSYCL/kernelname-enum.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@ int main() {
197197
// CHECK: template <EnumValueIn EnumValue, typename EnumTypeIn> class Baz;
198198
// CHECK: template <typename EnumTypeOut, template <EnumValueIn EnumValue, typename EnumTypeIn> class T> class dummy_functor_8;
199199
// CHECK: Specializations of KernelInfo for kernel function types:
200-
// CHECK: template <> struct KernelInfo<::dummy_functor_1<(no_namespace_int)0>>
201-
// CHECK: template <> struct KernelInfo<::dummy_functor_2<(no_namespace_short)1>>
202-
// CHECK: template <> struct KernelInfo<::dummy_functor_3<(internal::namespace_short)1>>
203-
// CHECK: template <> struct KernelInfo<::dummy_functor_4<(enum_in_anonNS)1>>
204-
// CHECK: template <> struct KernelInfo<::dummy_functor_5<(no_type_set)0>>
205-
// CHECK: template <> struct KernelInfo<::dummy_functor_6<(unscoped_enum)0>>
200+
// CHECK: template <> struct KernelInfo<::dummy_functor_1<static_cast<no_namespace_int>(0)>>
201+
// CHECK: template <> struct KernelInfo<::dummy_functor_2<static_cast<no_namespace_short>(1)>>
202+
// CHECK: template <> struct KernelInfo<::dummy_functor_3<static_cast<internal::namespace_short>(1)>>
203+
// CHECK: template <> struct KernelInfo<::dummy_functor_4<static_cast<enum_in_anonNS>(1)>>
204+
// CHECK: template <> struct KernelInfo<::dummy_functor_5<static_cast<no_type_set>(0)>>
205+
// CHECK: template <> struct KernelInfo<::dummy_functor_6<static_cast<unscoped_enum>(0)>>
206206
// CHECK: template <> struct KernelInfo<::dummy_functor_7<::no_namespace_int>>
207207
// CHECK: template <> struct KernelInfo<::dummy_functor_7<::internal::namespace_short>>
208-
// CHECK: template <> struct KernelInfo<::T1<::T2<(type_argument_template_enum::E)0>>>
208+
// CHECK: template <> struct KernelInfo<::T1<::T2<static_cast<type_argument_template_enum::E>(0)>>>
209209
// CHECK: template <> struct KernelInfo<::T1<::T3<::type_argument_template_enum::E>>>
210210
// CHECK: template <> struct KernelInfo<::dummy_functor_8<::EnumTypeOut, Baz>>

0 commit comments

Comments
 (0)