extern void abort (void);
struct A
{
int i;
};
struct B
{
struct A a;
int j;
};
static void
foo (struct B *p)
{
((struct A *)p)->i = 1;
}
int main()
{
struct A a;
a.i = 0;
foo ((struct B *)&a);
if (a.i != 1)
abort ();
return 0;
}
Folding (struct A *)p to &p->a causes us to see
a.i = 0;
a.0_1 = (struct B *) &a;
a.0_1->a.i = 1;
D.2703_2 = a.i;
where the store a.0_1->a.i does not alias a.i because of TBAA on the base
object (you can't access an object of type A via a pointer to type B).
This blocks the fix for PR41316.
--
Summary: folding causes strict aliasing violation
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Keywords: wrong-code, alias
Severity: normal
Priority: P3
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: rguenth at gcc dot gnu dot org
OtherBugsDependingO 41316
nThis:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41317