[Bug c/69776] New: Wrong optimization with aliasing
ch3root at openwall dot com
gcc-bugzilla@gcc.gnu.org
Thu Feb 11 22:15:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69776
Bug ID: 69776
Summary: Wrong optimization with aliasing
Product: gcc
Version: 5.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: ch3root at openwall dot com
Target Milestone: ---
The program:
#include <stdlib.h>
#include <stdio.h>
int main()
{
void *p = malloc(10);
int *pi = p;
double *pd = p;
*pi = 1;
printf("*pi = %d\n", *pi);
int a = *pi;
*pd = 0;
*pi = a;
printf("p = %p\n", p);
printf("*pi = %d\n", *pi);
}
compiled with `gcc -std=c11 -pedantic -O2` prints this:
*pi = 1
p = 0x1165010
*pi = 0
The last value is wrong, it should be 1.
Tested on gcc 4.7.2, 4.9.2 and 5.2.0 -- all affected.
More information about the Gcc-bugs
mailing list