https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119033
Bug ID: 119033
Summary: Unsafe FRE of pointer assignment
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: hubicka at gcc dot gnu.org
Target Milestone: ---
The following (artificial) testcase (pointed to me by Filip Hejsek) is
miscompiled at -O2, since we miss the fact that test3(3) overwrites b[0].
#include <stddef.h>
struct foo
{
int a[3];
int b[3];
};
void test2 (int *a);
__attribute__ ((noipa))
int test3 (int i)
{
struct foo test;
test.b[0]=1;
int *a = &test.a[i];
int *b = &test.b[0];
int *ptr = ((size_t)a == (size_t)b) ? b : a;
*ptr=2;
//test2 (ptr);
return test.b[0];
}
int main()
{
__builtin_printf ("%i %i\n",test3(0), test3(3));
return 0;
}