Am Dienstag, dem 28.11.2023 um 01:00 +0000 schrieb Joseph Myers: > On Sun, 26 Nov 2023, Martin Uecker wrote: > > > My understand is that it is used for aliasing analysis and also > > checking of conversions. TYPE_CANONICAL must be consistent with > > the idea the middle-end has about type conversions. But as long > > as we do not give the same TYPE_CANONICAL to types the middle-end > > thinks must be incompatible using its own type checking machinery, > > it should be safe even for types the C standard thinks must be > > incompatible for some reason. > > And presumably also for types that definitely can't be assigned because > they have incompatible layout through the use of different array sizes - > since the front end won't generate such assignments, it would never matter > whether the middle end considers them valid without conversion or not?
Yes, for checking assignments we use the stricter language semantics so we should never generate assignments for structs with different fields offsets or sizes. (I will check this again). > > > I also think more rationale is needed for ignoring sizes like this. Is > > > it > > > intended for e.g. making structs with flexible array members > > > alias-compatible with similar structs with a fixed-size array? > > > > The main reason are pointers to arrays: > > > > struct foo { int (*x)[]; } > > struct foo { int (*x)[2]; }; > > struct foo { int (*x)[1]; }; > > Thanks for the explanation. > > I guess the cases involving flexible array members actually show up a bug > in the standard rather than any kind of issue with this patch - the > standard allows one structure ending with a flexible array member, and > another ending with a fixed-size array, to be compatible (and in different > translation units allowed that even before C23), but there is also clear > text in the standard showing it's not intended to require the layout to be > consistent (the fixed-size and flexible arrays might have different > offsets), and what you'd actually get with an assignment or conditional > expression mixing such structures certainly isn't clearly specified. I agree, unfortunately it seems not well specified and we somehow missed that this now becomes more important. > Maybe the right resolution for that issue with the standard would be to > make that particular case incompatible, but it would need to be raised as > an issue after C23 is out. I think FAM may need further consideration from the standard point of view for also other reasons. My other issues I have now run into are structs with variably size which I think do not work properly with LTO already today: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112716 Martin >