<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63600>63600</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
ABI incompatibiliy with cl.exe: [[msvc::no_unique_address]] produces wrong size struct
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
georg-emg
</td>
</tr>
</table>
<pre>
cl.exe has a custom attribute named [[msvc::no_unique_address]]. This attribute is not recognized by clang-cl, and ignored. Code that uses this attribute will produce binaries that are ABI incompatible with cl.exe.
The following code compiles correctly in Visual Studio 17.6.2 when using cl.exe, but not clang-cl.exe:
~~~cpp
struct Empty {};
struct Test
{
int _dummy;
[[msvc::no_unique_address]] Empty _empty;
};
static_assert(sizeof(Test) == sizeof(int));
~~~
Output from cl.exe:
~~~
> cl.exe /EHsc /std:c++20 /c test.cpp
Microsoft (R) C/C++-Optimierungscompiler Version 19.36.32532 für x64
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.
test.cpp
~~~
Output from clang-cl.exe:
~~~
>clang-cl.exe /EHsc /std:c++20 /c test.cpp
test.cpp(8,4): warning: unknown attribute 'no_unique_address' ignored [-Wunknown-attributes]
[[msvc::no_unique_address]] Empty _empty;
^~~~~~~~~~~~~~~~~~~~~~~
test.cpp(11,1): error: static assertion failed due to requirement 'sizeof(Test) == sizeof(int)'
static_assert(sizeof(Test) == sizeof(int));
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning and 1 error generated.
~~~
clang-cl.exe generates a `struct Test` with size 8 bytes rather than the correct 4 bytes, resulting in potential crashes.
cl.exe version: 19.36.32532 für x64
clang-cl.exe version: 15.0.1 with target x86_64-pc-windows-msvc
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVc2O2zYQfhr6MrAgUZZsH3zwzxrtoQiQBulxQVFjiS1FKuRwHefgZy8oeb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