https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100309
Bug ID: 100309 Summary: [11 regression] false positive -Wstringop-overflow/stringop-overread/array-bounds on reinterpret_cast'd integers Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sciresm.gccbugzilla at gmail dot com Target Milestone: --- Created attachment 50697 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50697&action=edit Minimal test case code. Bug occurs in GCC 11.1.0, but none of the 10.x releases. It appears that GCC is now inferring a size of 0 when doing reinterpret_cast<void*>(ConstantInteger); when doing std::memcpy/std::memset to/from the result pointers, bogus warnings are emitted about reading/writing to regions of zero size. My target is an embedded system with a fixed memory layout; I have been using constexpr uintptr_t/size_ts's to describe the memory regions, and correspondingly calls to set or copy memory regions are now emitting bogus warnings. I have made an example minimal test case here (also attached): https://godbolt.org/z/WPaGY8eaz Relevant errors (compiling with -O -Werror): void StringopOverread() { // error: 'void* memset(void*, int, size_t)' writing 16 bytes into a region of size 0 overflows the destination [-Werror=stringop-overflow=] std::memset(reinterpret_cast<void *>(0xCAFEBABE), 0xCC, 0x10); } void StringopOverflow2(const void *src) { // error: 'void* memcpy(void*, const void*, size_t)' writing 16 bytes into a region of size 0 overflows the destination [-Werror=stringop-overflow=] std::memcpy(reinterpret_cast<void *>(0xCAFEBABE), src, 0x10); } void StringopOverread(void *dst) { // error: 'void* memcpy(void*, const void*, size_t)' reading 16 bytes from a region of size 0 [-Werror=stringop-overread] std::memcpy(dst, reinterpret_cast<void *>(0xCAFEBABE), 0x10); }