From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DE05C384B070; Sun, 14 Mar 2021 21:25:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE05C384B070 From: "arnd at linaro dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/99578] gcc-11 -Warray-bounds or -Wstringop-overread warning when accessing a pointer from integer literal Date: Sun, 14 Mar 2021 21:25:51 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: diagnostic 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: Message-ID: In-Reply-To: References: 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: Sun, 14 Mar 2021 21:25:52 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99578 --- Comment #6 from Arnd Bergmann --- I figured out the qnx4 warning in the end: https://godbolt.org/z/hvqjr3 struct qnx4_inode_entry { char di_status; union { struct { char di_fname[16]; char di_pad[32]; }; struct { char dl_fname[48]; }; }; }; int qnx4_readdir(struct qnx4_inode_entry *de) { if (!de->di_fname[0]) return 0; if (de->di_status) return __builtin_strnlen(de->di_fname, sizeof(de->di_fname)); else return __builtin_strnlen(de->dl_fname, sizeof(de->dl_fname)); return 0; } This produces :22:16: warning: '__builtin_strnlen' specified bound 48 exceeds sou= rce size 16 [-Wstringop-overread] because the first access on the object seems to decide which layout is assu= med. Changing (!de->di_fname[0]) to (!de->dl_fname[0]) shuts up the warning since that is a longer field. This is probably enough as a workaround, if you can confirm that the behavior of the compiler is also intentional for this inpu= t.=