<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/109777>109777</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang does not support union or struct types for "register" variables
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          DavidSpickett
      </td>
    </tr>
</table>

<pre>
    Originally reported by https://discourse.llvm.org/t/frontend-how-to-use-register-union-or-struct-in-c/81392.

https://godbolt.org/z/bz8nM1E9x

```
typedef union Test {
    int i;
} Test;

register Test t asm ("x21");

typedef struct Test2 {
    int i;
} Test2;

register Test t2 asm ("x22");

register int t3 asm ("w23");
register int *t4 asm ("x24");
```
Clang does not allow the first 2, the union and struct, despite their sizeof being correct for the register chosen.
```
<source>:5:22: error: size of register 'x21' does not match variable size
    5 | register Test t asm ("x21");
      | ^
<source>:5:1: error: bad type for named register variable
    5 | register Test t asm ("x21");
      | ^
<source>:11:1: error: bad type for named register variable
   11 | register Test t2 asm ("w22");
      | ^
```
GCC allows all of them.

It appears that types have to be explicitly added, as was done for pointers https://github.com/llvm/llvm-project/commit/2e31e4e47b09ca5e889e7470e5ae372348661692.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vd2OszYQfRpzMyLCAwS44CJfdlP1oupF-wLGngS3gJE9ZDf79BUk2XxE26qfqkYRP8bH58zM8ViFYE8DUS3ybyJ_idTErfP1izpb89to9Z_EHDXOXOpfvT3ZQXXdBTyNzjMZaC7QMo9BpDuBB4EHY4N2kw-06bpzv3H-JPDAAg9H7wamwcSte4vZxVOg2NPJBiYfT4N1Q-x8HNhPmmM7xFrgoZRphRuRvIhkd72uyU7ONK7jG8uHwEPzUQ6_yNfq_XuQ2Ca3__LKl5EMHWEhhd8pMIji2_UbAIAdGKxIbyOieFnmPAaW6136Fc-gQg8CS4H4jlIgCqyeEHfaa4gLDv8NMf4zM66o8UvqT8jMwOl3iDdMnxCruQJ3nK0IsmeCdW73nRpOYBwFGByD6jr3BtwSHK0PDChwv7xec68Gc0vHPG4ojJZp_m49BPtB7ggN2eEE2nlPmuHo_AL_FKlbF2jYfKlFpPvgJq9JpK8i3eUi3SGKdAfkvfPzw8wB7vhYTmCxlK94hNAr1i2clbeq6WiBPCqWgyj28CNegOU3o0T--rc65UpmowzM7lnCH1RP5kF5F_b_apLyv4mS8itRuDLis3W_UrUu8E_7_dVhYb7NheSW-lW_-JlBjSMpH4BbxYviAK06E7CDhoDex85qy90FlDFkZiOqAG8qgHHDNbrR2YHJh6dWd7LcTs1Gu17gYe52t1s8evcHzZ4-aNf3dn5ASiVllBVNUmmVU1lWVGRFQrmitMA0K7dbua1wE5k6NVVaqYhqWWAhC0zyMmprSXQ8YrbNVSGxkVudYZ4lhSoLIzPdZJGtMcEsqTCTSZLk5abU2zJNSSbbrKQmO4osoV7Z7rMzRzaEiWqZVEVRRJ1qqAvLMYCo5308FyR_iXy9RNVMpyCypLOBw2MJttxRrdfbPkzjfD7cdrnz9553zf6cUoF4N4NA_DRMiCbf1T-c5iWOIPBwC-Vc418BAAD__xidDHA">