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

    <tr>
        <th>Summary</th>
        <td>
            clang-cl: "memset will always overflow" diagnostic bug
        </td>
    </tr>

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

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

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

<pre>
    Have only been able to reproduce this with the clang-cl driver mode, and the `/std:c++latest` argument appears to play a role -- doesn't repro with `/std:c++20` or `/std:c++17`.

Simple test case, slightly reduced from real code (replaced library memset with builtin for the repro):
```
struct Quadric
{
        // a00*x^2 + a11*y^2 + a22*z^2 + 2*(a10*xy + a20*xz + a21*yz) + b0*x + b1*y + b2*z + c
        float a00, a11, a22;
        float a10, a20, a21;
        float b0, b1, b2, c;
        float w;
};

void z(Quadric &p) {
    __builtin_memset(&p, 0, sizeof(Quadric));
}
```
Compiling with `--driver-mode=cl /std:c++latest` yields:
```
<source>(12,5): warning: 'memset' will always overflow; destination buffer has size 43, but size argument is 44 [-Wfortify-source]
   12 |     __builtin_memset(&p, 0, sizeof(Quadric));
      |     ^
```

It's reproducible on godbolt, which is currently on revision d2234ca16310a9e9bd595561353556ea6ba0176f:
https://gcc.godbolt.org/z/7ooof5cda
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVE-P-jYT_jTmMgLZE0LIIQdgF73vseqhx5VjTxJXJka2Aw2fvrLDsvptt6dKSJnhsed55o9HhmD6kahh5ZGVbys5xcH5Js5qcKvW6bn5n7wRuNHO0BKNIFtLEB14unqnJ0UQBxPgbuIAcSBQVo79WlnQ3tzIw8VpYngCOeqMsx1neA5Rs-KgGB4ZHq2MFCLbcZC-ny40RpDXK0kfEtHVyhkkeGcJ1mvQjsLIsIqLgoX4h6DIU0Dnf8JExXZ8w_iB8cPv5nJNGVGIoGTI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