From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9E04B385E00A; Tue, 30 Aug 2022 08:54:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E04B385E00A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661849680; bh=p1FW1PdIsKMS8gyQKTFKDrwEip6/cXd1BmJK3LpZPKE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kMSy4ljNFt1OfsaBqMVlG87pukCJuzthP+D6eDs3woWSFwQI5zwe++4jya5ZyGWHB SzAcdwRt/IR29wwz4bX2A0r63xlGFBfUkrW+SQPaoOtugCQHFNP2lRkGzCOo/ullmL KGkTayVK/mLMJp5W/TfdPWp/jXycU3GKEoWRF9ik= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/66459] bogus warning 'w.offset' may be used uninitialized in this function [-Wmaybe-uninitialized] caused by loop invariant motion (LIM) Date: Tue, 30 Aug 2022 08:54:37 +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: 5.1.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW 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: cf_reconfirmed_on short_desc 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=3D66459 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed|2019-02-03 00:00:00 |2022-8-30 Summary|bogus warning 'w.offset' |bogus warning 'w.offset' |may be used uninitialized |may be used uninitialized |in this function |in this function |[-Wmaybe-uninitialized] |[-Wmaybe-uninitialized] | |caused by loop invariant | |motion (LIM) --- Comment #6 from Richard Biener --- what we warn about in the end is the path when l =3D=3D 0 && n > 0. that's= also visible in the initial gfortran IL: try { w.data =3D 0B; w.dtype =3D {.elem_len=3D4, .rank=3D2, .type=3D1}; if (*l) { ... } L.1:; { integer(kind=3D4) D.4258; D.4258 =3D *n; i =3D 1; while (1) { { logical(kind=3D4) D.4261; D.4261 =3D i > D.4258; if (D.4261) goto L.3; { integer(kind=3D4) D.4262; D.4262 =3D *m; j =3D 1; while (1) { { logical(kind=3D4) D.4265; D.4265 =3D j > D.4262; if (D.4265) goto L.5; if ((integer(kind=3D4)[0:] * restrict) w.data !=3D 0B) { (*(integer(kind=3D4)[0:] * restrict) w.data)[(w.o= ffset + (integer(kind=3D8)) i * w.dim[1].stride) + (integer(kind=3D8)) j] =3D 0; } L.6:; L.4:; j =3D j + 1; } } L.5:; } L.2:; i =3D i + 1; } } L.3:; the n > 0 check is simplified from D.4258 =3D *n; i =3D 1; D.4261 =3D i > D= .4258; There's some extra guard, m > j, but that's not related so what uninit analysis would need to see is the w.data !=3D 0 guard but as Manu said, the LIM pass hoists the loop invariant uses out of this conditional. IIRC there's a related bug somewhere for LIM exposing uninitialized uses to code paths that are not known to execute but here it's not trivial to see the uninitializedness. The bogus diagnostic goes away with -fno-tree-loop-im (but you usually do not want to do that for performance reasons). At -O3 we unswitch on w.data !=3D 0 but LIM already moved the access then. One old idea is to make sure to disable diagnostics on stmts we move for the sake of introducing false negatives ...=