https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119033
--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
Also for objsz the ((size_t)a == (size_t)b) ? b : a to a folding is problematic
since &test.a[i] and &test.b[0] point to different sub-objects (which is also
what later path-sensitive alias analysis uses).
Variant with only integers in the a == b ? b : a folding which fails the
same way:
#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;
size_t a = (size_t)&test.a[i];
size_t b = (size_t)&test.b[0];
size_t ptr = (a == b) ? b : a;
*(int *)ptr=2;
//test2 (ptr);
return test.b[0];
}
int main()
{
__builtin_printf ("%i %i\n",test3(0), test3(3));
return 0;
}
IIRC we've seen duplicate PRs where foo.a/b were instead two possibly
adjacent but distinct global or local variables. Note there is no
points-to analysis involved in this PR, we fold/propagate the memory
access to test.a[i] = 2 which may not alias with the load from test.b[0].
With the above testcase that does not have any casts the issue appears
during GENERIC frontend folding already.