<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/59328>59328</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang frontend generates wrong tbaa.struct metadata for bitfield copy
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
strimo378
</td>
</tr>
</table>
<pre>
Hi all,
I just found out that the tbaa.struct metadata for C/C++ bitfields are generated wrong by clang.
The following code
```
struct a {
int : 8;
int b1 : 8;
int : 8;
int b2 : 8;
};
void c() { a d = d; }
```
generates the memcpy tbaa.struct metadata of `!{i64 1, i64 4, !7, i64 3, i64 4, !7}`. For b1 and b2 the size of b1 and b2 is given as 4 bytes and it should be 1 byte.
If we slightly change the struct in the following way
```
struct a2 {
char : 8;
char b1;
char : 8;
char b2;
};
void c2() { a2 d = d; }
```
we get the correct tbaa.struct metadata: `!{i64 1, i64 1, !12, i64 3, i64 1, !12}`
See https://godbolt.org/z/xqjnanv7s for both examples.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVMGO4zYM_Rr6Qmxg007sOfgwSWB0z-0PSBZta6BIqSRPNvv1hexJk86kiwUCRXqk9Eg-kyIEPVrmFrZ72B4zMcfJ-TZEr0-urJtMOnVt_9AojAE6QH6E_HVdv-PbHCIObrYK3RwxTiItjFEKsQnRz33EE0ehRBQ4OI8HoO4AtAfao9Rx0GxUQOEZR7bsRWSFF-_siPKKvRF23Dwy_jUxDs4Yd9F2xN4pfrTCLv_4LccPfoFQ71cEUduIUL5iA-UNS5AsPqPPPFdX-gRDffx3_-60wh6oAXpJtChQIZRHVFDuMXk-C3RdbwUISwVPfOrP1-eFdAOmu1RAvde7CgugA6ZNlTZARX0Dyq-W-gi7fIOd8ylrYVXKKDEG_ZPT03dUBxz1O1sUASuU1xRbMumIYXKzUSgZi8XwH5W-D3hhDEaPUzRX7CdhR1451ky0XU53JS_i-htC0qOS_ST8F4EWUBZ35Bde9AsF6VFC-n0NL-k7Xlugd95zH58qmAJ6rmDxoVNBXyR8MC0aPvL-yYxTjOcA5StQB9SNTkln4sb5Eaj7CdT9-PvNCvteh6URpYsT8g9xOhsOm0y1pXopX0TGbbGr86JoqKqzqW0KyVVVN2LLdUW7shCSVFPLflB9KRrOdEs5UUF5lRdVuW02PRckhrLOuSeS1Q6qnE9Cm40x76cUTqZDmLndvpTUZEZINmGZPUSWL7gYgSiNIt-mO9_kPAaocqNDDPdXoo6G20MaETh4ZyNbhfceWofI_86h2-zB3p2v2exN-6l8Ok6z3PTuBNQlzo-_b2fv3riPQN0SaQDqlkz-CQAA___j1IZe">