Skip to content

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

@ex-rzr

Description

@ex-rzr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions