================
@@ -7,7 +7,8 @@
 /// Zero-sized structs should not crash.
 int b() {
   struct {      } a[10];
-  __builtin_memcpy(&a[2], a, 2); // c-warning {{buffer has size 0, but size 
argument is 2}}
+  __builtin_memcpy(&a[2], a, 2); // c-warning {{buffer has size 0, but size 
argument is 2}} \
+                                 // c-warning {{'memcpy' reading 2 bytes from 
a region of size 0}}
----------------
jpjepko wrote:

I believe the only reason we see this warning in C is because C++ defines the 
size of an empty struct as 1 byte, whereas in C it is 0 via a compiler 
extension. If you bump up the size arg to 9 you do get a `-Wfortify-source` 
warning.

https://godbolt.org/z/6scenbofj

At least for C, there is both an overread and overwrite (since both buffers are 
0 bytes) so I would contend they are both valid here.

https://github.com/llvm/llvm-project/pull/183004
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to