From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EDE70385801E; Mon, 1 Feb 2021 00:01:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EDE70385801E From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/87489] [8/9/10/11 Regression] Spurious -Wnonnull warning Date: Mon, 01 Feb 2021 00:01:48 +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: 8.2.0 X-Bugzilla-Keywords: deferred, diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: attachments.created 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: Mon, 01 Feb 2021 00:01:49 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D87489 --- Comment #12 from Martin Sebor --- Created attachment 50098 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D50098&action=3Dedit Patch to move -Wnonnull to pass_merge_phi. No change in GCC 11 so far. I've reduced the test case in attachment 44775= to just the essentials and copied it below. The dumps confirm that the warnin= g in this case is issued too early, before the strlen(0B) call has been eliminat= ed.=20 As Jeff notes in comment #11, FRE3 is the first pass where the bad strlen c= all has been removed. $ cat pr87489.c && gcc -O -S -Wall -Wpedantic -fdump-tree-all pr87489.c && = grep strlen * | grep 0B extern void f (const void*, int); static void g (int i, const char *s) { int j =3D 0; if (i) j |=3D 1; if (j) f (&j, 0); if (j & 1) f (s, __builtin_strlen (s)); } void h (void) { g (0, 0); } In function =E2=80=98g=E2=80=99, inlined from =E2=80=98h=E2=80=99 at ../pr87489.c:19:3: pr87489.c:14:11: warning: argument 1 null where non-null expected [-Wnonnul= l] 14 | f (s, __builtin_strlen (s)); | ^~~~~~~~~~~~~~~~~~~~ pr87489.c: In function =E2=80=98h=E2=80=99: pr87489.c:14:11: note: in a call to built-in function =E2=80=98__builtin_st= rlen=E2=80=99 pr87489.c.092t.fixup_cfg3: _6 =3D __builtin_strlen (0B); pr87489.c.097t.adjust_alignment: _6 =3D __builtin_strlen (0B); pr87489.c.098t.ccp2: _6 =3D __builtin_strlen (0B); pr87489.c.099t.post_ipa_warn1: _6 =3D __builtin_strlen (0B); pr87489.c.101t.backprop: _6 =3D __builtin_strlen (0B); pr87489.c.102t.phiprop: _6 =3D __builtin_strlen (0B); pr87489.c.103t.forwprop2: _6 =3D __builtin_strlen (0B); pr87489.c.104t.objsz2: _6 =3D __builtin_strlen (0B); pr87489.c.105t.alias: _6 =3D __builtin_strlen (0B); pr87489.c.106t.retslot: _6 =3D __builtin_strlen (0B); As an experiment, I tried running -Wnonnull later, in mergephi2 (see the attached patch titled gcc-87489.diff). That avoids the warning, passes bootstrap, and causes no testsuite regressions.=