On Mon, Nov 13, 2017 at 11:01 AM, Michael Matz <m...@suse.de> wrote: > Hi, > > On Thu, 9 Nov 2017, Bin.Cheng wrote: > >> So I have two questions here. >> A) Is this special kind union type only generated by fortran FE for >> equivalence+common? > > It's not special in that it isn't marked in any way. For all purposes > it's a normal union type with surprising field(offset)s. I don't know if > it can occur for any situations except equivalence+common. Not from the > fortran frontend I believe. > >> B) For the special union type that has non-zero offset fields. Is it >> safe to assume field A is not the last flex array: if there is field B >> that offset_B >= (offset_A + length_A)? > > No. You can make equivalences between all kinds of objects, > including non-arrays. You can also equivalence (say) an integer variable > and an individual array element. Also flex arrays don't enter the > picture, you can equivalize (tm) also arrays of fixed size.
Just a remark on the optimization you want to achieve. Rather than trying to fix things through max_size and friends you can also look at nonoverlapping_component_refs_of_decl_p and/or nonoverlapping_component_refs_p both of which currently punt for UNION_TYPEs. So I was thinking of a good condition to quickly decide whether UNION_TYPE fields may overlap or not (and thus to distinguish the Fortran case which then requires more elaborate processing). A simple one might be to quickly bail out if DECL_FIELD_[BIT_]OFFSET are the same. This might be a more local "fix" for the missed aliasing than trying to jump into the flex array issues. Richard. > > Ciao, > Michael.