From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BB8843952005; Thu, 17 Mar 2022 08:26:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB8843952005 From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/103984] [12 regression] Possible maybe-uninitialized false positive on shaderc-2021.0 since r12-6329-g4f6bc28fc7dd86bd Date: Thu, 17 Mar 2022 08:26:56 +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, EH X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.0 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 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: Thu, 17 Mar 2022 08:26:57 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103984 --- Comment #18 from CVS Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:7276a18aba41eed65c0cf535ae029e0ceeca6c77 commit r12-7686-g7276a18aba41eed65c0cf535ae029e0ceeca6c77 Author: Jakub Jelinek Date: Thu Mar 17 09:23:45 2022 +0100 gimplify: Emit clobbers for TARGET_EXPR_SLOT vars later [PR103984] As mentioned in the PR, we emit a bogus uninitialized warning but easily could emit wrong-code for it or similar testcases too. The bug is that we emit clobber for a TARGET_EXPR_SLOT too early: D.2499.e =3D B::qux (&h); [return slot optimization] D.2516 =3D 1; try { B::B (&D.2498, &h); try { _2 =3D baz (&D.2498); D.2499.f =3D _2; D.2516 =3D 0; try { try { bar (&D.2499); } finally { C::~C (&D.2499); } } finally { D.2499 =3D {CLOBBER(eol)}; } } finally { D.2498 =3D {CLOBBER(eol)}; } } catch { if (D.2516 !=3D 0) goto ; else goto ; : A::~A (&D.2499.e); goto ; : : } The CLOBBER for D.2499 is essentially only emitted on the non-exception= al path, if B::B or baz throws, then there is no CLOBBER for it but there is a conditional destructor A::~A (&D.2499.e). Now, ehcleanup1 sink_clobbers optimization assumes that clobbers in the EH cases are emitted after last use and so sinks the D.2499 =3D {CLOBBER(eol)}; late= r, so we then have # _3 =3D PHI <1(3), 0(9)> : D.2499 =3D{v} {CLOBBER(eol)}; D.2498 =3D{v} {CLOBBER(eol)}; if (_3 !=3D 0) goto ; [INV] else goto ; [INV] : _35 =3D D.2499.a; if (&D.2499.b !=3D _35) where that _35 =3D D.2499.a comes from inline expansion of the A::~A dt= or, and that is a load from a clobbered memory. Now, what the gimplifier sees in this case is a CLEANUP_POINT_EXPR with somewhere inside of it a TARGET_EXPR for D.2499 (with the C::~C (&D.249= 9) cleanup) which in its TARGET_EXPR_INITIAL has another TARGET_EXPR for D.2516 bool flag which has CLEANUP_EH_ONLY which performs that conditio= nal A::~A (&D.2499.e) call. The following patch ensures that CLOBBERs (and asan poisoning) are emit= ted after even those gimple_push_cleanup pushed cleanups from within the TARGET_EXPR_INITIAL gimplification (i.e. the last point where the slot could be in theory used). In my first version of the patch I've done it by j= ust moving the /* Add a clobber for the temporary going out of scope, like gimplify_bind_expr. */ if (gimplify_ctxp->in_cleanup_point_expr && needs_to_live_in_memory (temp)) { ... } block earlier in gimplify_target_expr, but that regressed a couple of t= ests where temp is marked TREE_ADDRESSABLE only during (well, very early dur= ing that) the gimplification of TARGET_EXPR_INITIAL, so we didn't emit e.g.= on pr80032.C or stack2.C tests any clobbers for the slots and thus stack s= lot reuse wasn't performed. So that we don't regress those tests, this patch gimplifies TARGET_EXPR_INITIAL as before, but doesn't emit it directly into pre_p, emits it into a temporary sequence. Then emits the CLOBBER cleanup into pre_p, then asan poisoning if needed, then appends the TARGET_EXPR_INITIAL temporary sequence and finally adds TARGET_EXPR_CLE= ANUP gimple_push_cleanup. The earlier a GIMPLE_WCE appears in the sequence,= the outer try/finally or try/catch it is. So, with this patch the part of the testcase in gimple dump cited above looks instead like: try { D.2499.e =3D B::qux (&h); [return slot optimization] D.2516 =3D 1; try { try { B::B (&D.2498, &h); _2 =3D baz (&D.2498); D.2499.f =3D _2; D.2516 =3D 0; try { bar (&D.2499); } finally { C::~C (&D.2499); } } finally { D.2498 =3D {CLOBBER(eol)}; } } catch { if (D.2516 !=3D 0) goto ; else goto ; : A::~A (&D.2499.e); goto ; : : } } finally { D.2499 =3D {CLOBBER(eol)}; } 2022-03-17 Jakub Jelinek PR middle-end/103984 * gimplify.cc (gimplify_target_expr): Gimplify type sizes and TARGET_EXPR_INITIAL into a temporary sequence, then push clobbe= rs and asan unpoisioning, then append the temporary sequence and finally the TARGET_EXPR_CLEANUP clobbers. * g++.dg/opt/pr103984.C: New test.=