[Bug fortran/49103] New: local variables exchange values / wrong code with -O3

thomas.orgis at awi dot de gcc-bugzilla@gcc.gnu.org
Sat May 21 17:54:00 GMT 2011


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

           Summary: local variables exchange values / wrong code with -O3
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: thomas.orgis@awi.de
              Host: x86_64-unknown-linux-gnu
            Target: x86_64-unknown-linux-gnu
             Build: x86_64-unknown-linux-gnu


Created attachment 24321
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24321
test program exposing the bug

After upgrading to gfortran 4.6.0, I noticed crashes in my codebase. This seems
to boil down to some local messup of variable values. I observe this with -O3,
but not with -O2 plus all available flags that are included in -O3. So, this
must be one of the internal optimizations that are not accessible via
individual flags.

The example is ripped out of a larger codebase and it shows. I spent over a
whole day diagnosing and trimming down already. Hopefully, you will mainly have
to look at the lower 100 lines. The routine grid_faces is the point of
interest, with a call to base_new triggering the issue.

The bad example:

shell$ gfortran -O3 gcc46gridbug.f90
shell$ ./a.out 
 LOG: Coordinate mapping:           1           2           3
 LOG:       back mapping:           1           2           3
 LOG: Base point:   0.0000000000000000        0.0000000000000000       
0.0000000000000000     
 generating base functions
 grid: faces
 Here is the bug. The grades should be (2 2):           2           2
 Compare the base grades:           1           1
 Here is the bug. The grades should be (2 2):           1           1
 Compare the base grades:           1           1
 grades again           2           2
 Here is the bug. The grades should be (2 2):           2           2
 Compare the base grades:           1           1
 Here is the bug. The grades should be (2 2):           1           1
 Compare the base grades:           1           1
 grades again           2           2
 Here is the bug. The grades should be (2 2):           2           2
 Compare the base grades:           1           1
 Here is the bug. The grades should be (2 2):           1           1
 Compare the base grades:           1           1
 grades again           2           2
 grid finished
 PASS


And the good example:

shell$ gfortran -O2 gcc46gridbug.f90 
shell$ ./a.out 
 LOG: Coordinate mapping:           1           2           3
 LOG:       back mapping:           1           2           3
 LOG: Base point:   0.0000000000000000        0.0000000000000000       
0.0000000000000000     
 generating base functions
 grid: faces
 Here is the bug. The grades should be (2 2):           2           2
 Compare the base grades:           1           1
 Here is the bug. The grades should be (2 2):           2           2
 Compare the base grades:           1           1
 grades again           2           2
 Here is the bug. The grades should be (2 2):           2           2
 Compare the base grades:           1           1
 Here is the bug. The grades should be (2 2):           2           2
 Compare the base grades:           1           1
 grades again           2           2
 Here is the bug. The grades should be (2 2):           2           2
 Compare the base grades:           1           1
 Here is the bug. The grades should be (2 2):           2           2
 Compare the base grades:           1           1
 grades again           2           2
 grid finished
 PASS

The code worked with gcc 4.3.3 and 4.5.1, as well as the intel compiler 11.1. I
hesitate to count in open64 and the sun/oracle compilers as, while they might
not show this bug, they have enough others that stopped me from using them:-/

If this still should be an error on my side, I'd appreciate to be enlightened.



More information about the Gcc-bugs mailing list