http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57321
Bug ID: 57321
Summary: static function call miscompiled at -Os and above
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: dhazeghi at yahoo dot com
The testcase below is miscompiled by gcc 4.8 on x86_64-linux, resulting in a
segfault when built with -Os or higher optimization levels. This does not
occur with gcc 4.7 or current trunk. The segfault appears on line 8, where p
is dereferenced and compared.
$ gcc-4.8 -v
gcc version 4.8.0 (GCC)
$ gcc-4.8 -O1 small.c
$ ./a.out
$ gcc-4.7 -Os small.c
$ ./a.out
$ gcc-4.8 -Os small.c
$ ./a.out
Segmentation fault (core dumped)
------------------------
int a = 1;
int *b;
int **c;
static int
bar(int *p)
{
if (*p == a)
{
int *i[7][1][9] = {{{ 0 }}};
int **j[1][1][1];
j[0][0][0] = &i[0][0][0] ;
*b = &p != c;
}
return 0;
}
void
foo(int p, int q)
{
int i = 0;
if (bar (&i))
;
}
int
main()
{
foo (0, 0);
return 0;
}