[Bug c/69776] Wrong optimization with aliasing
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Feb 11 22:20:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69776
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>The last value is wrong, it should be 1.
Why do you think that?
If we look at your code:
void *p = malloc(10);
int *pi = p;
double *pd = p;
<< at this point p has no effective type.
*pi = 1;
printf("*pi = %d\n", *pi);
<< Now it has an effective type of int or a struct containing int
int a = *pi;
<< a read
*pd = 0;
<< a write to a double, it does not alias int at all so it can be moved past
the next statement
*pi = a;
<< store via an int
Since the order of pi and pd is not specified due to different aliasing of int
and double so either can be done first
printf("p = %p\n", p);
printf("*pi = %d\n", *pi);
More information about the Gcc-bugs
mailing list