From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3545C3857C70; Sat, 13 Mar 2021 14:23:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3545C3857C70 From: "arnd at linaro dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/99578] New: gcc-11 -Warray-bounds or -Wstringop-overread warning when accessing a pointer from integer literal Date: Sat, 13 Mar 2021 14:23:37 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: arnd at linaro dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Mar 2021 14:23:37 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99578 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 =E2=80=98sharpsl_save_param=E2= =80=99: arch/arm/common/sharpsl_param.i:11:2: warning: =E2=80=98memcpy=E2=80=99 rea= ding 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 en= tire 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 warni= ng.=