https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112716

--- Comment #14 from uecker at gcc dot gnu.org ---
(In reply to Richard Biener from comment #13)
> (In reply to uecker from comment #11)
> > I asked the C FE and it wants to get this fixed.
> 
> That was a funny comment?

Yes sorry.
> 
> But yes, when there are new C standards like C23 changing interoperability
> rules a GCC extension needs to be amended to say how it behaves here.  I
> would simply say the types covered by the GCC extension are exempt from the
> C23 tag compatibility rules.

The new C23 tag compatibility rules apply inside one TU only and cross-TU
nothing has changed. Across TUs, structurally equivalent types which also have
the same tag are already required to be compatible in all previous versions of
C and this works correctly in GCC for all structure/union types without GNU
extensions. It also works in GCC for structures with GNU extensions and across
TUs but only without LTO. 

So the bug here is that LTO - unrelated to C23 - behaves inconsistently for
structs with GNU extension relative to  1) non-LTO GCC and 2) to what could be
expected from general C rules. Note that we have a similar LTO bug for flexible
array members with [] and [0].
(for non-LTO it works, of course, because there is no cross-TU TBAA in this
case).

So I think the rule how LTO decides to do structural comparison should be
changed. 

> 
> That said - if C23 tag compatibility is something like the C++ ODR then
> the frontend could produce a "mangling" (simply the tag name) and direct
> the middle-end to handle compatibility that way.  Note that C++ specifically
> exempts "local" types from the ODR.  I think C is wrong here to not allow
> this - it will basically force all structs with that T to be "compatible"
> whether or not the types are even structurally related?

The struct have to have the same tag (or both no tag) and must be structurally
equivalent. Structs with different tag or which are not structurally equivalent
are not compatible. But nothing has changed here with C23 for the cross-TU
case, the only question is how the GNU extensions fit in her.

IMHO at least the cases where the arrays are at the end of the struct

struct foo { ...; int x[]; }
struct foo { ...; int x[0]; };
struct foo { ...; int x[n]; };

should all be treated as compatible for TBAA purposes. 

The case where there is a VLA in the middle of a struct

struct foo { int x[n]; ... };

it also would be good if this worked. But those are very obscure.

Martin

Reply via email to