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

    <tr>
        <th>Summary</th>
        <td>
            __builtin_object_size does not match structure size when flexible array members are statically initialized
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Given a structure ending in a flexible array, that has a static initializer:

```
struct foo {
    size_t count;
    int some[];
};

static struct foo instance = {
 .count = 3,
    .some = { 5, 10, 15, },
};
```

Clang reports the incorrect size with `__builtin_object_size()`.

GCC correctly reports 20:
```
__builtin_object_size(&instance, 1) == 20
```

Clang misses the flexible array members and reports only 8 (the `sizeof()`):
```
__builtin_object_size(&instance, 1) == 8
```

https://godbolt.org/z/W5soYdrdK

cc @nickdesaulniers @isanbard 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVM1u3CAQfprxZZQVxmt7ffCh2Whz6ANUPa0wTNY0GCLASTdPX8H-xFs17aWSNcYM8_2MARGCPliiHup7qB8KMcfR-f6ZKBSDU8f-Ub-SRYEh-lnG2ROSVdoeUKfZJ0M_9WAIhffiCHyLcRQRRxFyiYhaorY6amH0O3movgB7AHaJDTs_-fNEgU_OIbT3pzlExKDfaR9RutlGqBYJbSMGN9FJ-zUF7WJ8Rs5KFgTahiisJITqYcG2yiR5sgK-_aBaJZ7LYqyT05LlmMeJ8rL8hv7W4SlujbAH9PTifAwYR0JtpfOeZMxe8U3HEaFh-_0waxO13bvhB8m4T1ngG-AdNGy1xHzcbvGMYY5XbM4-On6r5HPo5tKa7A54l1wn45z909OkQ6CTpdudgRNNA_mAwqqrOmfNETcIfJMKoGFJg3u6Gkzx_8nf_EX9GONLSFx8B3x3cGpwJq6cPwDfvQPffauD-668-roskhJhzayWz4qCmI3VySCsmQ7CDsIrLFRfqa7qREF92WzWVVOzkhVj38m66do1VbxWNZXl0PC2o062G8ZlTW2he854xeqy5VXJSrZqm64RXJV1w5VsWAlrRpPQZmXM65SUFjqEmfqGt5uuMGIgE_KZ5tzSG-YkcJ6OuO9Tzd0wHwKsmdEhhg-UqKOh_o_tReUooHURJxHluLgRTpt2JPvpX0-L8hkUxhwXN4IqZm_639qv4zgPK-km4Lsk7Py6e_EuiQG-y3YC8F22-ysAAP__-bBvcQ">