<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/146047>146047</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang][CUDA][HIP] __declspec(empty_bases) leads to inconsistent struct layout between host and device
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mkuron
</td>
</tr>
</table>
<pre>
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.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVt2O2zYTfRr6ZmCDon73whe2_PnLAkUQtGlzaVDkWGJDkQZJ2XWevqBke-3dNtlmYUALDmc458zhDLn3qjWIS5KvSb6Z8SF01i37r4OzZtZYeV7-poxA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