Skip to content

Commit 07e8d8f

Browse files
[SYCL] Add global namespace specifier for Enum Values (#1939)
This patch is a follow up to commit e7020a1. The prior commit appends required scope resolution operator when kernel name is templated with enum type but not enum value. This patch adds the missing scope resolution operator when handling enum values. Signed-off-by: Elizabeth Andrews <[email protected]>
1 parent 5880d2d commit 07e8d8f

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class NamedDecl : public Decl {
295295
bool WithGlobalNsPrefix = false) const;
296296

297297
// FIXME: Remove string version.
298-
std::string getQualifiedNameAsString() const;
298+
std::string getQualifiedNameAsString(bool WithGlobalNsPrefix = false) const;
299299

300300
/// Appends a human-readable name for this declaration into the given stream.
301301
///

clang/lib/AST/Decl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,10 +1527,11 @@ void NamedDecl::printName(raw_ostream &os) const {
15271527
os << Name;
15281528
}
15291529

1530-
std::string NamedDecl::getQualifiedNameAsString() const {
1530+
std::string NamedDecl::getQualifiedNameAsString(bool WithGlobalNsPrefix) const {
15311531
std::string QualName;
15321532
llvm::raw_string_ostream OS(QualName);
1533-
printQualifiedName(OS, getASTContext().getPrintingPolicy());
1533+
printQualifiedName(OS, getASTContext().getPrintingPolicy(),
1534+
WithGlobalNsPrefix);
15341535
return OS.str();
15351536
}
15361537

clang/lib/Sema/SemaSYCL.cpp

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

21392139
if (ET) {
21402140
const llvm::APSInt &Val = Arg.getAsIntegral();
2141-
ArgOS << "static_cast<" << ET->getDecl()->getQualifiedNameAsString()
2141+
ArgOS << "static_cast<"
2142+
<< ET->getDecl()->getQualifiedNameAsString(
2143+
/*WithGlobalNsPrefix*/ true)
21422144
<< ">"
21432145
<< "(" << Val << ")";
21442146
} else {

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<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)>>
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<static_cast<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)