Possible bug in FPP from pgf90

The FPP in pgf90 is incorrectly expanding a #defined’d macro. A session log reproducing the problem on a code fragment is below. The definition of NGL is incorrectly being expanded to include a character ‘C’ instead of the numeral 3. I have marked the line containing the error with <<<< . Two other compilers, gfortran and ifort, expand the macro correctly.

$ pgf90 -V

pgf90 18.10-1 64-bit target on x86-64 Linux -tp sandybridge
PGI Compilers and Tools
Copyright (c) 2018, NVIDIA CORPORATION.  All rights reserved.
$ cat bug.F90

#define PORDSTATIC 3
# define NGL ((PORDSTATIC)+1)
# define NPTS (NGL*NGL*NGL)
    do ii = 1, NPTS
    end do
$ pgf90 -E bug.F90
# 1 "bug.F90"
# 5 "bug.F90"
    do ii = 1, (((3)+1)*((C)+1)*((3)+1))  <<< HERE, (C) should be (3)
    end do
$ ifort -E bug.F90
# 1 "bug.F90"
    do ii = 1, (((3)+1)*((3)+1)*((3)+1))
    end do
$ gfortran -E bug.F90
# 1 "bug.F90"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "bug.F90"
    do ii = 1, (((3)+1)*((3)+1)*((3)+1))
    end do
$ exit
exit

Hi Michalakes,

Thanks for the report! This is an odd one in that only one of the three NGL macros is getting expanded incorrectly. I’ve added a problem report (TPR#26723) and sent to our compiler engineers for further investigation.

As a work around, you might try using the -Mcpp flag which will use a C preprocessor (pgprepro) rather than our built-in Fortran preprocessor.

% pgf90 -Mcpp bug.F90 -o bug.f90; cat bug.f90


    do ii = 1, (((3)+1)*((3)+1)*((3)+1))
    end do

Best Regards,
Mat

Hi John,
This is fixed in the 21.3 release of the HPC SDK nvfortran compiler.

1 Like