https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578
Bug ID: 99578 Summary: gcc-11 -Warray-bounds or -Wstringop-overread warning when accessing a pointer from integer literal Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: arnd at linaro dot org Target Milestone: --- This snippet from the Linux kernel reads a data structure from an architecturally defined location in memory into a local copy: struct sharpsl_param_info { unsigned int comadj_keyword; }; extern struct sharpsl_param_info sharpsl_param; typedef unsigned long __kernel_size_t; extern void * memcpy(void *, const void *, __kernel_size_t); void sharpsl_save_param(void) { memcpy(&sharpsl_param, (void *)(0xe8ffc000), sizeof(struct sharpsl_param_info)); } With gcc-11, this now triggers a -Wstringop-overread warning on x86: arch/arm/common/sharpsl_param.i: In function ‘sharpsl_save_param’: arch/arm/common/sharpsl_param.i:11:2: warning: ‘memcpy’ reading 4 bytes from a region of size 0 [-Wstringop-overread] 11 | memcpy(&sharpsl_param, (void *)(0xe8ffc000), sizeof(struct sharpsl_param_info)); I tried to reproduce this on godbolt.org, which apparently has a slightly different snapshot version and instead produces -Warray-bounds warning for the same input: https://godbolt.org/z/ve6h6b I could not find a way to avoid this warning, other than turning off the entire warning option globally or with a pragma. Accessing a pointer from a literal integer value is not too unusual in the kernel and should not cause a warning.