Issue |
146047
|
Summary |
[Clang][CUDA][HIP] __declspec(empty_bases) leads to inconsistent struct layout between host and device
|
Labels |
clang
|
Assignees |
|
Reporter |
mkuron
|
Since #87651, the struct layout when compiling CUDA/HIP code for Windows is consistent between host and device. However, there is the `__declspec(empty_bases)` attribute that can modify the struct layout. Right now this attribute is respected on the host side but ignored on the device side.
Consider this example:
```c++
struct A {};
struct B {};
struct __declspec(empty_bases) C : A, B {
int i;
};
__attribute__((global)) void C_kernel(C c)
{
c.i = 1;
}
```
The device-side compilation reports `warning: __declspec attribute 'empty_bases' is not supported [-Wignored-attributes]`. With `-fdump-record-layouts`, you can see that the device-side layout is
```
0 | struct C
0 | struct A (base) (empty)
1 | struct B (base) (empty)
4 | int i
| [sizeof=8, align=4,
| nvsize=8, nvalign=4]
```
while the host-side layout is
```
0 | struct C
0 | struct A (base) (empty)
0 | struct B (base) (empty)
0 | int i
| [sizeof=4, align=4,
| nvsize=4, nvalign=4]
```
Godbolt: https://cuda.godbolt.org/z/ccrs4Ecf6
Since #87651 you no longer need the `empty_bases` attribute to manually make struct layouts consistent between host and device. The attribute is used e.g. in Nvidia's CCCL library for nvcc compatibility and since https://github.com/NVIDIA/cccl/pull/3155/commits/fc84efda5b15a6eee0224a4685a4270653bfbe16 it is causing a layout consistency with Clang on Windows.
To solve this issue, Clang should respect `__declspec(empty_bases)` on the device side too when targeting Windows.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs