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?

> > 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.  
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.

-- 
Joseph S. Myers
jos...@codesourcery.com

Reply via email to