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

    <tr>
        <th>Summary</th>
        <td>
            __builtin_object_size incorrect size when passed to function
        </td>
    </tr>

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

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

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

<pre>
    Consider the following example:

```
#include <stdio.h> 
 
static void 
check_size(void *ptr) 

 
    printf("%p, %zu\n", ptr, __builtin_object_size(ptr, 1)); 

 
int 
main(int argc, char *argv[]) 

    struct { 
        unsigned char padding_l; 
        unsigned char buf[41]; 
        unsigned char padding_r; 
    } __stack; 
 
 check_size(&__stack.buf); 
 printf("%p, %zu\n", &__stack.buf, __builtin_object_size(&__stack.buf, 1)); 
 return (0); 

```

When compiled with -O1 or higher, I observe the following:
```
0x806c11d6, 42
0x806c11d6, 41
```

That is, the `__builtin_object_size()` invocation in `check_size` returns a result as if it had been invoked as `__builtin_object_size(ptr, 0);` rather than `__builtin_object_size(ptr, 1);`.  This makes `_FORTIFY_SOURCE` a little more lenient than it should be in some weird corner cases.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVE1v2zgQ_TXUZRCDoj4sH3RonBroKUA3i8WeDIocW7OmSIGk7G5__YKy0sRt0o0hiNbMm_eGM0PKEOhoEVtW3bPqIZNT7J1vT3iWNmzyrHP633brbCCNHmKPcHDGuAvZI-A3OYwGWfGJ8QfGn981X57rpyjIKjNpBFZsQ9TkVj0rPsPVvSwhykgKzo70YlE9qtM-0HdkornaxacxeiY2C4Kt729JAABGTzYemGiYEExUIxNbYKL6PrFqa2fbFmaWLez33UQmkt277h9U8VlscedMbNJT3P_Qe7jVIxuXf4Mky0STDNIfVQpXvfQpZemP52tt38wcAEL0k4pwa0y_yc690VeuUWpN9rg3Lxm9DeymA6vuyzxJ_g_0mdPfAtNO9_sQpTq9cizLTWOYqBfgKsm-LteHWvFz_Ptd-RX5S4PAY5y8BSYa_k7nfh7O-f1XjxaUG0YyqOFCsYe7xxych56OPc7T8AVcF9Cf8fYMvMz-LTH_1vBa5bmuU3Ap3rTmv8npqZcRKCRcEmQ1f78wG1ZzIHt2SkZyFsgm_Ks-1XwpTQAJHsNkIsgAdACK0EsNHaKdGU6ok-c3csvpWAo8U8vYz3eDtB8IzH8ErgCeegowyBNeJXePX5--7P7e__H459ft58QtwVCMBmFwHsGgJbTxKkURQu8mk7JPWw5uQLggeQ3KeYselAwYVpluC70pNjLDNl_nTVkUNS-zvq15o2W9Lrqm49itBSre1Lo6YIllUQuZUSu4KHmdV7wuOS9XWoi1KteyPHSIZdWwkuMgyayMOQ8r548ZhTBhu6nqosqM7NCE-WIVwuIFZmca_Ooh822KueumY2AlNxRieGGJFA22bxYSyCrnPaoI8-clze4oQ0AN0cFhsirNQDZ50_YxjiFNqNgxsTtS7KdupdzAxC5JLcvd6F2iZ2I3JxiY2F03cG7FfwEAAP__dkTSTg">