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

    <tr>
        <th>Summary</th>
        <td>
            __builtin_object_size doesn't correctly reflect flexible array member size
        </td>
    </tr>

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

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

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

<pre>
    This is a more comprehensive test case showing the difference between Clang's and GCC's result of `__builtin_object_size` with an argument that's an object with a flexible array member either initialized in the file or elsewhere (as mentioned in this [comment](https://reviews.llvm.org/D133108#3804039) on [D133108](https://reviews.llvm.org/D133108)).  Compiling the program with GCC and with the `-fdump-tree-optimized=/dev/stdout` option shows that the result of each function reflects the size of the flexible array member that's initialized in this file.  This is the expected output.  When compiled with Clang the result of all functions is 4 which is incorrect.  See https://godbolt.org/z/5jcjo9e5s.
```
struct S {
  int n;
  char a[];
};

extern struct S es;
static struct S s0;
static struct S s1 = { 1, { 0 } };
static struct S s2 = { 2, { 1, 0 } };
static struct S s3 = { 3, { 2, 1, 0 } };
static struct S s4 = { 4, { 3, 2, 1, 0 } };
static struct S s5 = { 5, { 4, 3, 2, 1, 0 } };
static struct S s6 = { 6, { 5, 4, 3, 2, 1, 0 } };

int fes(void) { return __builtin_object_size(&es, 0); }
int fs0(void) { return __builtin_object_size(&s0, 0); }
int fs1(void) { return __builtin_object_size(&s1, 0); }
int fs2(void) { return __builtin_object_size(&s2, 0); }
int fs3(void) { return __builtin_object_size(&s3, 0); }
int fs4(void) { return __builtin_object_size(&s4, 0); }
int fs5(void) { return __builtin_object_size(&s5, 0); }
int fs6(void) { return __builtin_object_size(&s6, 0); }
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVld1uqzgQgJ8GbkaNwOYnXHBxmqrnAc5Ke1kZGIIrgyPbJO15-h07ge6ebaMig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