From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 35EA53839DF6; Wed, 14 Sep 2022 05:12:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 35EA53839DF6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663132331; bh=7Shewd/KJe86lNQKsqGf9ToYHKgZL5LfUxLYmND93ho=; h=From:To:Subject:Date:From; b=hZ6ZhcXlqA3LQl8i1GhCd5XZWv/YFMLNvoTKDSKdu5ZkHCC1UNos+f5QZJuD7QBs4 gzOPSUUnUpyaWD8rcP+xFC4DvaVSjlVG/KwyKZOvtUWVUzvdIBp/4jiI/8U0TBz06I SqULtONS7IjB6Ge3oms8kVlFSM56PsIba/BO7hYo= From: "neoxic at icloud dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/106939] New: Linker-defined symbols are stained due to 'array subscript is partly outside array bounds' warning Date: Wed, 14 Sep 2022 05:12:10 +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: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: neoxic at icloud dot com 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106939 Bug ID: 106939 Summary: Linker-defined symbols are stained due to 'array subscript is partly outside array bounds' warning Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: neoxic at icloud dot com Target Milestone: --- Working with embedded applications, one often deals with manipulating memory regions via symbols defined in a linker script. Please consider the followi= ng snippet: ----------------------------------------------------- #include extern char _src, _dst; // Defined by the linker int main(void) { memcpy(&_dst, &_src + 1024, 1111); return 0; } ----------------------------------------------------- Compilation with GCC 12.2.0 yields lots of warnings: ----------------------------------------------------- $ cc -O2 -Wall -Wextra -fno-strict-aliasing -fwrapv a.c a.c: In function =E2=80=98main=E2=80=99: a.c:6:29: warning: array subscript 1024 is outside array bounds of =E2=80= =98char[1]=E2=80=99 [-Warray-bounds] 6 | memcpy(&_dst, &_src + 1024, 1111); | ~~~~~~^~~~~~ a.c:3:13: note: at offset 1024 into object =E2=80=98_src=E2=80=99 of size 1 3 | extern char _src, _dst; // Defined by the linker | ^~~~ a.c:6:9: warning: =E2=80=98memcpy=E2=80=99 forming offset [1, 1110] is out = of the bounds [0, 1] of object =E2=80=98_dst=E2=80=99 with type =E2=80=98char=E2=80=99 [-Warray-= bounds] 6 | memcpy(&_dst, &_src + 1024, 1111); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.c:3:19: note: =E2=80=98_dst=E2=80=99 declared here 3 | extern char _src, _dst; // Defined by the linker | ^~~~ ----------------------------------------------------- These symbols are used as mere address anchors, they don't contain anything. But no matter what I do like changing their type, casting their addresses, = etc, I can't get rid of the pesky sticky warnings now. Is there a clean way to w= ork around these warning without turning off Warray-bounds?=