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

    <tr>
        <th>Summary</th>
        <td>
            __builtin_object_size(P->M, 1) where M is an array and the last member of a struct fails (need "-fstrict-flex-array")
        </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>
    https://godbolt.org/z/EvehMax84

When bos1 is used on a member who is both an array and at the end of a structure, it fails to correctly resolve. This kind of behavior should only happen for flexible array members:

```C
struct middle_array {
    int a;
    unsigned char c[16];
    int b;
};

struct trailing_array {
    int a;
    int b;
    unsigned char c[16];
};

struct flex_array {
    int a;
    int b;
    unsigned char c[];
};
```

Both "middle" and "trailing" should see that "c" is 16 bytes. Only "flex" should be "unbounded":

```
ok:  sizeof(*middle) == 24
ok:  sizeof(middle->c) == 16
ok:  __builtin_object_size(middle, 1) == -1
ok:  __builtin_object_size(middle->c, 1) == 16
ok:  sizeof(*flex) == 8
ok:  __builtin_object_size(flex, 1) == -1
ok:  __builtin_object_size(flex->c, 1) == -1
ok:  sizeof(*trailing) == 24
ok:  sizeof(trailing->c) == 16
ok:  __builtin_object_size(trailing, 1) == -1
WAT: __builtin_object_size(trailing->c, 1) == -1 (expected 16)
```

https://godbolt.org/z/s9nb4Y7q4

This is likely due to trailing all trailing arrays as historical flexible arrays, but it breaks FORTIFY_SOURCE in that any struct with a fixed size trailing array will receive no sanity checking. Please introduce something like "-fstrict-flex-array".

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVd1vmzAQ_2vg5ZQoGBLCAw_9lPZQddo6TX2KbDiCFwdntkmb_fU7Q9KSqFm7aREB-3wfvzuffxa63OW1cxsbxBcBu6VnqUuhlRtrs6TZL_rfbLG-48_zJJhcB5OL_v29xgaE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