https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114713
Bug ID: 114713
Summary: incorrect TBAA for struct with flexible array member
or GNU zero size
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: lto
Assignee: unassigned at gcc dot gnu.org
Reporter: muecker at gwdg dot de
Target Milestone: ---
If one mixes a struct with FAM and one with zero size at the end, then TBAA
considers them incompatible for aliasing purposes when using LTO. One could
decide that those are incompatible types, but this would break code that mixes
both, e.g. during a transition time to standard FAMs. Also affects old versions
of GCC.
https://godbolt.org/z/xodMK9sqE
struct foo { int x; char a[]; };
void test_bar(void* b);
__attribute__((noinline))
int test_foo(struct foo* a, void* b)
{
a->x = 1;
test_bar(b);
return a->x;
}
int main()
{
struct foo y;
if (2 != test_foo(&y, &y))
__builtin_abort();
return 0;
}
// TU2
struct foo { int x; char a[0]; };
void test_bar(void* b)
{
struct foo *p = b;
p->x = 2;
}