[clang] [Clang][Sema] Add -Wstringop-overread warning for source buffer overreads (PR #183004)
John Paul Jepko via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 25 17:58:43 PST 2026
================
@@ -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
More information about the cfe-commits
mailing list