Skip to content

Commit e9c769e

Browse files
[SYCL] Fix error when size_t is used as enum base (#8162)
"std::size_t" was emitted in the forward declaration of enum in integration header. This resulted in compilation errors about use of undeclared identifier "std". To fix this, builtin is resolved to integral type in forward declaration.
1 parent 355c822 commit e9c769e

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4781,7 +4781,7 @@ class SYCLFwdDeclEmitter
47814781
D->print(OS, Policy);
47824782

47834783
if (const auto *ED = dyn_cast<EnumDecl>(D)) {
4784-
QualType T = ED->getIntegerType();
4784+
QualType T = ED->getIntegerType().getCanonicalType();
47854785
// Backup since getIntegerType() returns null for enum forward
47864786
// declaration with no fixed underlying type
47874787
if (T.isNull())

clang/test/CodeGenSYCL/kernelname-enum.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
#include "Inputs/sycl.hpp"
77

8+
namespace std {
9+
typedef long unsigned int size_t;
10+
} // namespace std
11+
812
enum unscoped_enum : int {
913
val_1,
1014
val_2
@@ -110,6 +114,14 @@ class dummy_functor_8 {
110114
void operator()() const {}
111115
};
112116

117+
enum class TestStdEnum : std::size_t { A, B };
118+
119+
template <TestStdEnum value>
120+
class dummy_functor_9 {
121+
public:
122+
void operator()() const {}
123+
};
124+
113125
int main() {
114126

115127
dummy_functor_1<no_namespace_int::val_1> f1;
@@ -121,6 +133,7 @@ int main() {
121133
dummy_functor_7<no_namespace_int> f7;
122134
dummy_functor_7<internal::namespace_short> f8;
123135
dummy_functor_8<EnumTypeOut, Baz> f9;
136+
dummy_functor_9<TestStdEnum::A> f10;
124137

125138
sycl::queue q;
126139

@@ -168,6 +181,10 @@ int main() {
168181
cgh.single_task(f9);
169182
});
170183

184+
q.submit([&](sycl::handler &cgh) {
185+
cgh.single_task(f10);
186+
});
187+
171188
return 0;
172189
}
173190

@@ -198,6 +215,8 @@ int main() {
198215
// NUL: enum class EnumValueIn : int;
199216
// NUL: template <EnumValueIn EnumValue, typename EnumTypeIn> class Baz;
200217
// NUL: template <typename EnumTypeOut, template <EnumValueIn EnumValue, typename EnumTypeIn> class T> class dummy_functor_8;
218+
// NUL: enum class TestStdEnum : unsigned long;
219+
// NUL: template <TestStdEnum value> class dummy_functor_9;
201220

202221
// CHECK: Specializations of KernelInfo for kernel function types:
203222
// NUL: template <> struct KernelInfo<::dummy_functor_1<static_cast<::no_namespace_int>(0)>>
@@ -220,3 +239,5 @@ int main() {
220239
// CHECK: template <> struct KernelInfo<::T1<::T3<::type_argument_template_enum::E>>>
221240
// NUL: template <> struct KernelInfo<::dummy_functor_8<::EnumTypeOut, Baz>>
222241
// UL: template <> struct KernelInfoData<'_', 'Z', 'T', 'S', '1', '5', 'd', 'u', 'm', 'm', 'y', '_', 'f', 'u', 'n', 'c', 't', 'o', 'r', '_', '8', 'I', '1', '1', 'E', 'n', 'u', 'm', 'T', 'y', 'p', 'e', 'O', 'u', 't', '3', 'B', 'a', 'z', 'E'>
242+
// NUL: template <> struct KernelInfo<::dummy_functor_9<static_cast<::TestStdEnum>(0)>> {
243+
// UL: template <> struct KernelInfoData<'_', 'Z', 'T', 'S', '1', '5', 'd', 'u', 'm', 'm', 'y', '_', 'f', 'u', 'n', 'c', 't', 'o', 'r', '_', '9', 'I', 'L', '1', '1', 'T', 'e', 's', 't', 'S', 't', 'd', 'E', 'n', 'u', 'm', '0', 'E', 'E'>

clang/test/SemaSYCL/stdtypes_kernel_type.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class U;
1414
class Foo;
1515
} // namespace std
1616

17+
enum class test_enum : std::size_t { a, b };
18+
1719
template <typename T>
1820
struct Templated_kernel_name;
1921

@@ -66,6 +68,9 @@ int main() {
6668
q.submit([&](handler &h) {
6769
h.single_task<std::ptrdiff_t>([=] {});
6870
});
71+
q.submit([&](handler &h) {
72+
h.single_task<Templated_kernel_name<test_enum>>([=] {});
73+
});
6974

7075
return 0;
7176
}

0 commit comments

Comments
 (0)