https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107206
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jamborm at gcc dot gnu.org --- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- 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] ={v} {CLOBBER}; MEM[(struct YD.10174 *)&yD.11526].xD.10179.iD.10156 = 0; MEM[(struct optionalD.10180 *)&yD.11526 + 4B] ={v} {CLOBBER}; MEM[(union _StorageD.10576 *)&yD.11526 + 4B] ={v} {CLOBBER}; MEM[(struct _Optional_payload_baseD.10507 *)&yD.11526 + 4B]._M_engagedD.10644 = 0; D.11546 ={v} {CLOBBER}; MEM[(struct XD.10147 *)&D.11546] ={v} {CLOBBER}; _22 = MEM[(const struct XD.10147 &)&yD.11526].iD.10156; MEM[(struct XD.10147 *)&D.11546].iD.10156 = _22; D.11546.oD.11384 = yD.11526.oD.11384; MEM[(struct YD.10174 *)&zD.11527] ={v} {CLOBBER}; MEM[(struct XD.10147 *)&zD.11527] ={v} {CLOBBER}; _21 = MEM[(const struct XD.10147 &)&D.11546].iD.10156; MEM[(struct XD.10147 *)&zD.11527].iD.10156 = _21; MEM[(struct YD.10174 *)&zD.11527].oD.11384 = MEM[(const struct YD.10174 &)&D.11546].oD.11384; D.11546 ={v} {CLOBBER(eol)}; MEM[(struct _Optional_baseD.10197 *)&D.11678] ={v} {CLOBBER}; MEM[(struct __as_base D.10805 &)&D.11678] ={v} {CLOBBER}; MEM[(union _StorageD.10576 *)&D.11678] ={v} {CLOBBER}; MEM[(union _StorageD.10576 *)&D.11678]._M_valueD.10616 = 1; MEM[(struct _Optional_payload_baseD.10507 *)&D.11678]._M_engagedD.10644 = 1; zD.11527.yD.11476.oD.11384 = D.11678; D.11678 ={v} {CLOBBER(eol)}; MEM[(struct YD.10174 *)&wD.11680] ={v} {CLOBBER}; MEM[(struct XD.10147 *)&wD.11680] ={v} {CLOBBER}; _19 = MEM[(const struct XD.10147 &)&zD.11527].iD.10156; MEM[(struct XD.10147 *)&wD.11680].iD.10156 = _19; MEM[(struct YD.10174 *)&wD.11680].oD.11384 = 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 = yD.11526.oD.11384; SR.19_9 = MEM <intD.9> [(struct optionalD.10180 *)&yD.11526 + 4B]; SR.20_6 = MEM <unsigned char> [(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 = (11546)'D.11546', offset = 32, size = 64, expr = D.11546.o, type = struct optional, reverse = 0, grp_read = 1, grp_write = 1, grp_assignment_read = 1, grp_assignment_write = 1, grp_scalar_read = 0, grp_scalar_write = 0, grp_total_scalarization = 0, grp_hint = 0, grp_covered = 0, grp_unscalarizable_region = 0, grp_unscalarized_data = 1, grp_same_access_path = 1, grp_partial_lhs = 0, grp_to_be_replaced = 0, grp_to_be_debug_replaced = 0} here D.11546.o is of an aggregate type containing a union member. Somehow there's * access { base = (11546)'D.11546', offset = 32, size = 32, expr = D.11546.o.D.11379._M_payload.D.10892._M_payload._M_value, type = int, reverse = 0, grp_read = 1, grp_write = 1, grp_assignment_read = 1, grp_assignment_write = 1, grp_scalar_read = 0, grp_scalar_write = 0, grp_total_scalarization = 0, grp_hint = 0, grp_covered = 1, grp_unscalarizable_region = 0, grp_unscalarized_data = 0, grp_same_access_path = 0, grp_partial_lhs = 0, grp_to_be_replaced = 1, grp_to_be_debug_replaced = 0} but I don't see any such access in the IL before SRA?!