[Bug tree-optimization/57521] New: wrong code for expressions in loop at -O3

dhazeghi at yahoo dot com gcc-bugzilla@gcc.gnu.org
Tue Jun 4 00:47:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57521

            Bug ID: 57521
           Summary: wrong code for expressions in loop at -O3
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dhazeghi at yahoo dot com

The following code is miscompiled with current gcc trunk at -O3 optimization on
x86_64-linux.  I've tried to reduce it somewhat from the original form.  Note
that 'e' is only touched in one place.  This also fails on 4.7 and 4.8 and is a
regression from gcc 4.6.


$ gcc-trunk -v
gcc version 4.9.0 20130603 (experimental) [trunk revision 199601] (GCC) 
$ gcc-trunk -O2 wrong.c 
$ ./a.out 
1
$ gcc-4.6 -O3 wrong.c 
$ ./a.out 
1
$ gcc-trunk -O3 wrong.c 
$ ./a.out 
0
$
--------------------------------------

int printf (const char *, ...);

int a, b, c, d, o = 1, p;
short e;

int
fn1 (int * p1)
{
    int f, g, h, j = 0, k = 0, l = 0;
    unsigned int i;
    int *m[1] = { &l };
    for (; b >= 0; b--)
    {
        if (*p1)
            if (j >= 0)
            {
                int n = 1;
                e = 1;
                h = a ? a : 1 % n;
                g = h > 0 ? 0 : h + 1;
                k = c + g;
            }
            else
                continue;
        else
        {

            f = d > 0 ? 0 : d + 1;
            i = f;
            j = 1 + i;
        }
        l++;
    }
    return k;
}

int
main ()
{
    for (;; p++)
    {
        fn1 (&o);
        break;
    }
    printf ("%d\n", e);
    return 0;
}



More information about the Gcc-bugs mailing list