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

    <tr>
        <th>Summary</th>
        <td>
            offsetof gives the wrong result on large enough types
        </td>
    </tr>

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

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

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

<pre>
    `offsetof` provides the wrong result on types big enough to overflow. 

```cpp
struct S {
    char a[~0UL >> 3];
    char b;
 char c;
};

static_assert(__builtin_offsetof(S, b) == ~0UL >> 3);
static_assert(__builtin_offsetof(S, c) == __builtin_offsetof(S, b) + 1);
=
```
> error: static assertion failed due to requirement '__builtin_offsetof(S, c) == __builtin_offsetof(S, b) + 1'
> note: expression evaluates to '0 == 2305843009213693952'

This is because clang uses `unsigned` internally in places `size_t` should probably used instead.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysU8uO4zYQ_JrWpTEGRep50MGOx6fcJjkbFNWSGNCkwocnziHfHsge2zMLLHYPCwgU2GhWVZNVMgQ9WaIOyh2U-0ymODvfKeeFjdpmvRsuHVTMjWOg6EaoGC7enfVAAeNM-O6dndBTSCaisxgvCwXs9YRkXZpmjA7dmfxo3PsGge2BbT_Wit0-tSy3Sog-qYhvCPXuVkFEVLP0KKHc_cf-_B1BvIJ4RQHlHsS3Xf2zdN2rxx7qZ_udTEatjjIE8hF4czz2SZuo7fExK2_egP-GPfAWQexB7PGrBt4-QH8eTn2C-xEp32H-mWU99vXy7vVXJO-dB7HFmxS8SdHO4ii1oQGHROtrePo7aU8nshGB179SaP1UY12kVQz9s3gKYZVBZ2mSjKtx3MrM7uBcsLIpBGMtz0XVirbkT6zr-sesA-qAPSmZAqEy0k6YAgWEiiV7NfGwmlPbSN5KYy6oLS5GqltP0P_SMa4dYXbJDKuLe9mby4oyoLYhkhw2N7ps6MTQilZm1OVVm7OqLEuRzV0z1rweq1zVQ1MNvBiJq7ovx1a0hWBKZLrjjAvWMJFzXpb5phCKGBuHvBnrtukFFIxOUpuNMefTxvkp0yEk6qpCNEVmZE8mXMPI-XVIENvROxvJDsD5GlHfrUdf-jQFKJjRIYYnWNTRUHd_I5z0-Ts5NdJP9MjoGtosedPNMS4BxBb4Afhh0nFO_Ua5E_DDyvHxe1m8-4tUBH64qg_AD9cB_g8AAP__P0xRAw">