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

             Bug #: 51638
           Summary: gfortran optimization breaks a single variable used as
                    both input and output for subroutine call
    Classification: Unclassified
           Product: gcc
           Version: fortran-dev
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: bard...@iram.fr


Created attachment 26153
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26153
Program fails with -O flag under 32 bits systems

Hello,

the attached program provides 2 subroutines which do not run correctly if the
program is compiled with the optimization option (-O). Since the program
behaves correctly without this option, this sounds like a bug (at least it
severely annoys us). The subroutines are inherited from our Fortran 77 legacy
code, which behaved well with the other compilers (ifc/ifort, g95, ...) for at
least one decade.

* About the test program:
 it should be self-explanatory. The idea it to swap the bytes in 4 and 8 bytes
integers, but I am not sure this is a major point. The key point is that the
same variable is used as 2 different dummy variables (input and output) in the
calling sequence.

 Here is the output when the program fails:
ubuntu-32:~$ gfortran -O test.f90 -o test
(some type mismatch warnings)
ubuntu-32:~$ ./test
 Call to subroutine IEI4EI with single I/O variable failed:
 Input:    2147483647  (int4) =    -1   -1   -1  127  (4 int1)
 Output:   2147483519  (int4) =   127   -1   -1  127  (4 int1)
 Call to subroutine IEI8EI with single I/O variable failed:
 In:   9223372036854775807  (int8) =    -1   -1   -1   -1   -1   -1   -1  127 
(8 int1)
 Out:  9223372036854775679  (int8) =   127   -1   -1   -1   -1   -1   -1  127 
(8 int1)

You can see that the bytes of the output variable are not correctly swapped.


* About the context:
- Many (if not all) 32 bits linux (and MinGW) are affected, including the
latest 32 bits Ubuntu (11.10).
- No 64 bits linux I tested is affected.
- All the gfortran versions seem affected, including latest 4.7.0 20111215
- The optimization seems mandatory to reproduce the bug, although I suspect I
observed the bug without this option in the past.

Thanks for your help. Unfortunately I won't be available for feedback during
Xmas holidays.

Reply via email to