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

             Bug #: 51342
           Summary: -O2 optimization fails in gcc-4.6.2, but succeeds when
                    -fno-inline-small-functions is added
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: mcala...@atnf.csiro.au


Created attachment 25942
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25942
gcc-4.6 -v -save-temps -O2 -Wall -Wextra -o lcprng lcprng.c

#include <stdio.h>

int lcprng()
{
  static int n = 137;
  while ((n = n * 1103515245 + 12345) < 0);
  return n;
}

int main()
{
  int i, j;

  i = lcprng();
  j = lcprng();
  printf("%12d%12d\n", i, j);

  return 0;
}



The above code fails in gcc 4.6.2 with -O2 optimization.  It succeeds with
lower levels of optimization or with '-O2 -fno-inline-small-functions'.

A successful execution:
% gcc-4.6 -O1 -Wall -Wextra -o lcprng lcprng.c && lcprng
   857745550  1783506108

A failed execution:
% gcc-4.6 -O2 -Wall -Wextra -o lcprng lcprng.c && lcprng
   857745550   -52381521

The output from 'gcc-4.6 -v -save-temps -O2 -Wall -Wextra -o lcprng lcprng.c'
is attached.

Thank you
Mark Calabretta

Reply via email to