Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCL C++ [[cl::packed]] attribute does not work for enum class #61

Open
ex-rzr opened this issue Dec 16, 2016 · 1 comment
Open

OpenCL C++ [[cl::packed]] attribute does not work for enum class #61

ex-rzr opened this issue Dec 16, 2016 · 1 comment

Comments

@ex-rzr
Copy link

ex-rzr commented Dec 16, 2016

It works for enum but ignored for enum class.

Here is an example:

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.
@ex-rzr ex-rzr changed the title OpenCL C++ packed attribute does not work enum class OpenCL C++ packed attribute does not work for enum class Dec 16, 2016
@ex-rzr ex-rzr changed the title OpenCL C++ packed attribute does not work for enum class OpenCL C++ [[cl::packed]] attribute does not work for enum class Dec 16, 2016
@bsochack
Copy link

It's a compiler bug and it should be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants