KhronosGroup / KhronosGroup/SPIR

OpenCL C++ attributes do not work for array variables/fields

Open
#60 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
183
Forks
51
PR merge metrics
No merged PRs in 30d

Description

(tested on spirv-1.1 branch)

Here is a test file based on examples from OpenCL C++ specification:
```cpp
struct foo1
{
char a;
int x[2] [[cl::packed]];
int y [[cl::packed]];
};

struct foo2
{
int x[2] [[cl::aligned(8)]];
int y [[cl::aligned(8)]];
};

int x [[cl::aligned(16)]] = 0;
short array[3] [[cl::aligned]];
```

Output for `clang -cc1 array-attribute-cpp.cl -triple spir-unknown-unknown -cl-std=c++`:
```
array-attribute-cpp.cl:4:16: error: 'packed' attribute cannot be applied to types
int x[2] [[cl::packed]];
^
array-attribute-cpp.cl:10:16: error: 'aligned' attribute cannot be applied to types
int x[2] [[cl::aligned(8)]];
^
array-attribute-cpp.cl:15:18: error: 'aligned' attribute cannot be applied to types
short array[3] [[cl::aligned]];
^
3 errors generated.
```

The same OpenCL C code (but using `__attribute__`) is compiled without errors:
```c
struct foo1
{
char a;
int x[2] __attribute__ ((packed));
int y __attribute__ ((packed));
};

struct foo2
{
int x[2] __attribute__ ((aligned (8)));
int y __attribute__ ((aligned (8)));
};

int x __attribute__((aligned (16))) = 0;
short array[3] __attribute__ ((aligned));
```

(Interesting that `int z [[cl::aligned(8)]] [2];` is compiled, but `int z __attribute__ ((aligned (8))) [2];` is not)

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue with array-attribute-cpp.cl using the shown clang -cc1 command and compare the C++ attribute cases with the working __attribute__ cases. Trace the attribute handling for cl::packed and cl::aligned on array variables and fields; done means those examples compile without the reported type-application errors.

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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.