Issue 124251
Summary clang-cl: "memset will always overflow" diagnostic bug
Labels new issue
Assignees
Reporter tycho
    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
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to