Bug 100309 - [11/12 regression] false positive -Wstringop-overflow/stringop-overread/array-bounds on reinterpret_cast'd integers
Summary: [11/12 regression] false positive -Wstringop-overflow/stringop-overread/array...
Status: RESOLVED DUPLICATE of bug 99578
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 11.1.0
: P3 normal
Target Milestone: 11.2
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2021-04-28 08:27 UTC by Michael Scire
Modified: 2021-04-28 16:11 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Minimal test case code. (277 bytes, text/plain)
2021-04-28 08:27 UTC, Michael Scire
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Scire 2021-04-28 08:27:18 UTC
Created attachment 50697 [details]
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);
}
Comment 1 Harald van Dijk 2021-04-28 08:38:48 UTC
This is a duplicate of bug 99578.
Comment 2 Martin Sebor 2021-04-28 16:11:36 UTC
Thus resolved as a dupe.

*** This bug has been marked as a duplicate of bug 99578 ***