From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 26C6E385840D; Sat, 18 Sep 2021 22:48:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26C6E385840D From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/102386] [12 regression] bogus -Wrestrict for unreachable memcpy() Date: Sat, 18 Sep 2021 22:48:02 +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: 12.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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_status resolution cc keywords blocked 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: Sat, 18 Sep 2021 22:48:02 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102386 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID CC| |msebor at gcc dot gnu.org Keywords| |diagnostic Blocks| |84774 --- Comment #1 from Martin Sebor --- The warning is correct (at -O0 GCC issues a -Wuninitialized for dereferenci= ng the uninitialized pBlb), but I suspect you're expecting it to be suppressed because the memcpy call is eliminated. I've simplified the test case and changed the names in it to make it easier to see what I assume you're really pointing out: $ cat pr102386.c && gcc -O2 -S -Wall pr102386.c struct S { int n, a[8]; }; static int n =3D 0; // not const but not modified void f (struct S *p) { if (n) // folded to false by ccp2 { void *q =3D p->a, *r =3D p->a; int n =3D 8; __builtin_memcpy (q, r, n); // -Wrestrict } } pr102386.c: In function =E2=80=98f=E2=80=99: pr102386.c:11:7: warning: =E2=80=98__builtin_memcpy=E2=80=99 accessing 8 by= tes at offsets 4 and 4 overlaps 8 bytes at offset 4 [-Wrestrict] 11 | __builtin_memcpy (q, r, n); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ Although the memcpy call does ultimately end up removed (by ccp2) as unreachable because the static global variable N is never set in the file, = the warning is issued before that happens, during folding. This might change if/when warnings are deferred until the end of compilation but I don't see = this use case as compelling enough to consider this particular instance a bug. = Feel free to reopen it if you have a more compelling use case. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D84774 [Bug 84774] [meta-bug] bogus/missing -Wrestrict=