https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82697
Bug ID: 82697 Summary: Wrong optimization with aliasing and "if" Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: ch3root at openwall dot com Target Milestone: --- A testcase is simplified from https://stackoverflow.com/questions/46592132/is-this-use-of-the-effective-type-rule-strictly-conforming : ---------------------------------------------------------------------- #include <stdlib.h> #include <stdio.h> __attribute__((__noinline__)) void test(int *pi, long *pl, int f) { *pl = 0; *pi = 1; if (f) *pl = 2; } int main(void) { void *p = malloc(10); test(p, p, 0); printf("%d\n", *(int *)p); } ---------------------------------------------------------------------- Results: ---------------------------------------------------------------------- $ gcc -std=c11 -pedantic -Wall -Wextra test.c && ./a.out 1 $ gcc -std=c11 -pedantic -Wall -Wextra -O3 test.c && ./a.out 0 ---------------------------------------------------------------------- gcc version: gcc (GCC) 8.0.0 20171024 (experimental)