c: fix incorrect TBAA for tagged types across translation units [PR117490]
Two different declarations of tagged types in the same translation unit
are incompatible in C before C23 and without tag also in C23. Still,
two such types can be compatible to the same tagged type in a different
translation unit, but this means that pointers can alias.
typedef struct { int i; } s1;
typedef struct { int i; } s2;
int f(s1 *p1, s2 *p2)
{
p1->i = 2;
p2->i = 3; // p2->i can alias p1->i
return p1->i;
}
We need to assign the same TYPE_CANONICAL to both types. This patch fixes
this for C23 and types without tag by also forming equivalence classes for
such types based on their structure as already done for types with tag.
Because this change exposes checking errors related to flexible array
members (cf. PR113688), one test is restricted to C17 for now.
PR c/117490
gcc/c/ChangeLog:
* c-typeck.cc (tagged_types_tu_compatible): Form equivalence
classed for tagless types in C23.
gcc/testsuite/ChangeLog:
* gcc.dg/gnu23-tag-alias-4.c: Adapt test.
* gcc.dg/gnu23-tag-alias-7.c: Adapt test.
* gcc.dg/guality/zero-length-array.c: Restrict to c17.
* gcc.dg/pr117490.c: New test.