From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4E000382FC9B; Thu, 24 Nov 2022 17:09:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E000382FC9B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669309795; bh=Jbrt9n2r6JuvFMoYe3VWpHPTefH7xRqrT+3Pu7haS94=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TWCO2Gc0QWkTZ+iLmKuoheGb2yiO9FDecd4EbvuXfdTlMBIlXUEGBY9a/EAMSelOO wPOusq99siPtOhu7FcTt33SpMQzbg/ixy/97CJmOFOVCodo2/lutWkZpx/Bgrm3ha9 zZ8wN9itim7xOgj4JXn4ubrZal7VANX/GEoQPqDg= From: "vincent-gcc at vinc17 dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107839] spurious "may be used uninitialized" warning while all uses are under "if (c)" Date: Thu, 24 Nov 2022 17:09:53 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: vincent-gcc at vinc17 dot net X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107839 --- Comment #3 from Vincent Lef=C3=A8vre --- (In reply to Richard Biener from comment #2) > it's loop invariant motion that hoists the v + v compute out of the loop > and thus outside of its controlling condition. You can see it's careful > to not introduce undefined overflow that is possibly conditionally > executed only but it fails to consider the case of 'v' being conditionally > uninitialized. >=20 > It's very difficult to do the right thing here - it might be tempting to > hoist the compute as >=20 > if (c) > tem =3D v+v; > while (1) > if (c) > f(tem); Couldn't the -Wmaybe-uninitialized warning be disabled on hoisted code, so = that the controlling condition wouldn't be needed? To make sure not to disable potential warnings, the information that v was = used for tem should be kept together with tem in the loop. Something like ((void)v,tem), though GCC doesn't currently warn on that if v is uninitiali= zed (but that's another issue that should be solved). However... > Maybe the simplest thing would be to never hoist v + v, or only > hoist it when the controlling branch is not loop invariant. >=20 > The original testcase is probably more "sensible", does it still have > a loop invariant controlling condition and a loop invariant computation > under that control? In my tmd/binary32/hrcases.c file, there doesn't seem to be a loop invarian= t, so I'm wondering what is the real cause. The code looks like the following: static inline double cldiff (clock_t t1, clock_t t0) { return (double) (t1 - t0) / CLOCKS_PER_SEC; } and in a function hrsearch() where its mprog argument (named c above) is an integer that enables progress output when it is nonzero: if (mprog) { mctr =3D 0; nctr =3D 0; t0 =3D ti =3D clock (); } do { [...] if (mprog && ++mctr =3D=3D mprog) { mctr =3D 0; tj =3D clock (); mpfr_fprintf (stderr, "[exponent %ld: %8.2fs %8.2fs %5lu / %lu]\= n", e, cldiff (tj, ti), cldiff (tj, t0), ++nctr, nprog); ti =3D tj; } [...] } while (mpfr_get_exp (x) < e + 2); The warning I get is In function =E2=80=98cldiff=E2=80=99, inlined from =E2=80=98hrsearch=E2=80=99 at hrcases.c:298:11, inlined from =E2=80=98main=E2=80=99 at hrcases.c:520:9: hrcases.c:46:23: warning: =E2=80=98t0=E2=80=99 may be used uninitialized [-Wmaybe-uninitialized] 46 | return (double) (t1 - t0) / CLOCKS_PER_SEC; | ~~~~^~~~~ hrcases.c: In function =E2=80=98main=E2=80=99: hrcases.c:128:11: note: =E2=80=98t0=E2=80=99 was declared here 128 | clock_t t0, ti, tj; | ^~ So the operation on t0 is tj - t0, and as tj is set just before, I don't see how it can be used in a loop invariant. This can be simplified as follows: int f (int); void g (int mprog) { int t0, ti, tj; if (mprog) t0 =3D ti =3D f(0); do if (mprog) { tj =3D f(0); f(tj - ti); f(tj - t0); ti =3D tj; } while (f(0)); } and I get tst.c: In function =E2=80=98g=E2=80=99: tst.c:13:9: warning: =E2=80=98t0=E2=80=99 may be used uninitialized [-Wmayb= e-uninitialized] 13 | f(tj - ti); | ^~~~~~~~~~ tst.c:4:7: note: =E2=80=98t0=E2=80=99 was declared here 4 | int t0, ti, tj; | ^~ BTW, the warning is incorrect: I can't see t0 in "f(tj - ti);".=