KhronosGroup / KhronosGroup/SPIR
OpenCL C++ [[cl::packed]] attribute does not work for enum class
- Dominant language
- C++
- Stars
- 183
- Forks
- 51
- PR merge metrics
- No merged PRs in 30d
Description
It works for `enum` but ignored for `enum class`.
Here is an example:
```cpp
enum [[cl::packed]] enum1
{
e11 = 0,
e12 = 100
};
enum [[cl::packed]] enum2
{
e21 = 0,
e22 = 1000
};
enum class [[cl::packed]] enum3
{
e31 = 0,
e32 = 100
};
enum class [[cl::packed]] enum4
{
e41 = 0,
e42 = 1000
};
void f(enum1, enum2, enum3, enum4);
kernel void k()
{
f(enum1::e11, enum2::e22, enum3::e32, enum4::e42);
}
static_assert(sizeof(enum1) == 1, "enum1");
static_assert(sizeof(enum2) == 2, "enum2");
static_assert(sizeof(enum3) == 1, "enum3");
static_assert(sizeof(enum4) == 2, "enum4");
```
SPIR-V
```
4 TypeInt 3 8 0
4 TypeInt 4 16 0
4 TypeInt 5 32 0
4 Constant 3 15 0
4 Constant 4 16 1000
4 Constant 5 17 100
4 Constant 5 18 1000
2 TypeVoid 2
7 TypeFunction 6 2 3 4 5 5 <-- should be 3 4 3 4
```
Output:
```
packed-enum.cl:35:1: error: static_assert failed "enum3"
static_assert(sizeof(enum3) == 1, "enum3");
^ ~~~~~~~~~~~~~~~~~~
packed-enum.cl:36:1: error: static_assert failed "enum4"
static_assert(sizeof(enum4) == 2, "enum4");
^ ~~~~~~~~~~~~~~~~~~
2 errors generated.
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by compiling the provided OpenCL C++ reproducer and comparing the enum and enum class results against the shown SPIR-V output. Trace how [[cl::packed]] affects the four enum declarations; done means enum3 and enum4 satisfy their static_assert checks and the function type uses 8- and 16-bit types as indicated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100