This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/82697] New: Wrong optimization with aliasing and "if"
- From: "ch3root at openwall dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 24 Oct 2017 10:05:23 +0000
- Subject: [Bug tree-optimization/82697] New: Wrong optimization with aliasing and "if"
- Auto-submitted: auto-generated
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)