From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DDC7C3858290; Tue, 11 Oct 2022 10:20:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DDC7C3858290 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665483617; bh=ugkQD8D2DoKWp5MLNpdaBBUYhNcNrdpMCM+W2dizko4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Yk28ObxCj94zLEiF/w+ajIVLWzn5cnhbD2Y666zRMdBA7ysvmicISyaPRvqeYDCvc ZgrS0PRg4p/OpNyCQ5k73RHwcDsevZFnDviBMXXcyo2Akapxgu6g9PGD2G9RpqWJM4 Y0vnzfOUGK/hjIhxfTS+XmsSENJnIejs/sS8/nn4= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/107206] Bogus -Wuninitialized in std::optional Date: Tue, 11 Oct 2022 10:20:17 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 12.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: cc 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=3D107206 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jamborm at gcc dot gnu.org --- Comment #3 from Richard Biener --- So this goes wrong in SRA somewhere where we decide to scalarize yD.11526 with its std::optional member which isn't engaged. Before early SRA we have MEM[(struct YD.10174 *)&yD.11526] =3D{v} {CLOBBER}; MEM[(struct YD.10174 *)&yD.11526].xD.10179.iD.10156 =3D 0; MEM[(struct optionalD.10180 *)&yD.11526 + 4B] =3D{v} {CLOBBER}; MEM[(union _StorageD.10576 *)&yD.11526 + 4B] =3D{v} {CLOBBER}; MEM[(struct _Optional_payload_baseD.10507 *)&yD.11526 + 4B]._M_engagedD.1= 0644 =3D 0; D.11546 =3D{v} {CLOBBER}; MEM[(struct XD.10147 *)&D.11546] =3D{v} {CLOBBER}; _22 =3D MEM[(const struct XD.10147 &)&yD.11526].iD.10156; MEM[(struct XD.10147 *)&D.11546].iD.10156 =3D _22; D.11546.oD.11384 =3D yD.11526.oD.11384; MEM[(struct YD.10174 *)&zD.11527] =3D{v} {CLOBBER}; MEM[(struct XD.10147 *)&zD.11527] =3D{v} {CLOBBER}; _21 =3D MEM[(const struct XD.10147 &)&D.11546].iD.10156; MEM[(struct XD.10147 *)&zD.11527].iD.10156 =3D _21; MEM[(struct YD.10174 *)&zD.11527].oD.11384 =3D MEM[(const struct YD.10174 &)&D.11546].oD.11384; D.11546 =3D{v} {CLOBBER(eol)}; MEM[(struct _Optional_baseD.10197 *)&D.11678] =3D{v} {CLOBBER}; MEM[(struct __as_base D.10805 &)&D.11678] =3D{v} {CLOBBER}; MEM[(union _StorageD.10576 *)&D.11678] =3D{v} {CLOBBER}; MEM[(union _StorageD.10576 *)&D.11678]._M_valueD.10616 =3D 1; MEM[(struct _Optional_payload_baseD.10507 *)&D.11678]._M_engagedD.10644 = =3D 1; zD.11527.yD.11476.oD.11384 =3D D.11678; D.11678 =3D{v} {CLOBBER(eol)}; MEM[(struct YD.10174 *)&wD.11680] =3D{v} {CLOBBER}; MEM[(struct XD.10147 *)&wD.11680] =3D{v} {CLOBBER}; _19 =3D MEM[(const struct XD.10147 &)&zD.11527].iD.10156; MEM[(struct XD.10147 *)&wD.11680].iD.10156 =3D _19; MEM[(struct YD.10174 *)&wD.11680].oD.11384 =3D MEM[(const struct YD.10174 &)&zD.11527].oD.11384; fD.11523 (&wD.11680.yD.11476); and SRA possibly follows the copy chains eventually seeing the value accesses to D.11678 and deciding based on that the type to use to access the value union of std::optional which is (simplified) struct _Empty_byte { }; union _Storage { _Empty_byte _M_empty; _Up _M_value; } with _Up being int in this testcase. Note that _M_empty is properly initialized but as the store is to an empty type this store is elided by gimplification. Note that SRA doesn't dump anything on yD.11526 but still generates D.11546.oD.11384 =3D yD.11526.oD.11384; SR.19_9 =3D MEM [(struct optionalD.10180 *)&yD.11526 + 4B]; SR.20_6 =3D MEM [(struct optionalD.10180 *)&yD.11526 + 8B= ]; possibly from the scalarization of D.11546: Created a replacement for D.11546 offset: 0, size: 32: SR.18D.11910 Created a replacement for D.11546 offset: 32, size: 32: SR.19D.11911 Changing the type of a replacement for D.11546 offset: 64, size: 8 to an integer. Created a replacement for D.11546 offset: 64, size: 8: SR.20D.11912 ... access { base =3D (11546)'D.11546', offset =3D 32, size =3D 64, expr =3D D.= 11546.o, type =3D struct optional, reverse =3D 0, grp_read =3D 1, grp_write =3D 1, grp_assignment_read =3D 1, grp_assignment_write =3D 1, grp_scalar_read =3D = 0, grp_scalar_write =3D 0, grp_total_scalarization =3D 0, grp_hint =3D 0, grp_= covered =3D 0, grp_unscalarizable_region =3D 0, grp_unscalarized_data =3D 1, grp_same_access_path =3D 1, grp_partial_lhs =3D 0, grp_to_be_replaced =3D 0, grp_to_be_debug_replaced =3D 0} here D.11546.o is of an aggregate type containing a union member. Somehow there's * access { base =3D (11546)'D.11546', offset =3D 32, size =3D 32, expr =3D D.11546.o.D.11379._M_payload.D.10892._M_payload._M_value, type =3D int, rev= erse =3D 0, grp_read =3D 1, grp_write =3D 1, grp_assignment_read =3D 1, grp_assignme= nt_write =3D 1, grp_scalar_read =3D 0, grp_scalar_write =3D 0, grp_total_scalarization = =3D 0, grp_hint =3D 0, grp_covered =3D 1, grp_unscalarizable_region =3D 0, grp_unscalarized_data =3D 0, grp_same_access_path =3D 0, grp_partial_lhs = =3D 0, grp_to_be_replaced =3D 1, grp_to_be_debug_replaced =3D 0} but I don't see any such access in the IL before SRA?!=