Fortran code containing preprocessor instructions needed for handling
system-specific behaviour is traditionally written to files with
the extension .F (rather than .f). The GCC driver would preprocess this
file in a first step, writing the intermediate code to a temporary .f file.

The regression (observed with both GCC 4.0.1 (gfortran) and GCC 3.3.6 (g77))
is that the preprocessing stage fails (3.3.6) when any Fortran-specific options
are used (e.g. '-Wsurprising' as an option known to both gfortran and g77)
or issues a warning about an unrecognized option (4.0.1).
This worked in older versions (tested with 3.4.3, 3.3.3, 3.2, 3.0.4).
If the code in the .F file does not contain preprocessor instructions, one
could explicitly set the language ('-x f77') to force acceptance of the
Fortran specific options - but the preprocessor stage is skipped then
in all GCC versions, just as if using a .f file name extension.

To fix this regression, the preprocessing stage should accept (and ignore) the
Fortran-specific options, as it used to be in earlier versions.
Not sure if this should be assigned to the preprocessor or the driver component.

While 4.0.1 just issues an irritating warning and continues, no
Fortran-specific options can be used anymore for .F files to be preprocessed 
in 3.3.6 (and perhaps 3.4.4, untested).

Demonstration script hello.sh (use as 'FC=g77 ./hello.sh' with GCC 3.x.x):
#!/bin/sh

if [ -z $FC ]; then
  FC="gfortran"
fi

set -x
cat >hello.f <<EndOfF
      Program MAIN
#ifdef TEST1
      Write(*,*) 'Hello, world no. 1'
#else
      Write(*,*) 'Hello, world no. 2'
#endif
      End
EndOfF

ln -sf hello.f hello.F
echo "Without Fortran-specific option compilation works fine:"
${FC} -g -Wall -DTEST1 hello.F -o hello1
./hello1
${FC} -g -Wall hello.F -o hello2
./hello2
echo "Both gfortran and g77 version 3.3.6 (perhaps also 3.4.4?) fail/complain"
echo " with Fortran-specific options while older g77 version are OK:"
${FC} -g -Wall -Wsurprising hello.F -o hello
echo "When setting the language explicitly, the preprocessor is skipped:"
${FC} -g -Wall -Wsurprising -x f77 hello.F -o hello

-- 
           Summary: [gfortran & g77]  Regression compiling Fortran code with
                    preprocessor instructions
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: driver
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Konrad dot Bernloehr at mpi-hd dot mpg dot de
                CC: gcc-bugs at gcc dot gnu dot org
GCC target triplet: i586-mandriva-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23532
  • [Bug driver/23532] New: [gfo... Konrad dot Bernloehr at mpi-hd dot mpg dot de

Reply via email to