https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96277

            Bug ID: 96277
           Summary: optional argument + openmp fails in gfortran v10.1.0
                    with "argument not specified in enclosed parallel"
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: daniel.price at monash dot edu
  Target Milestone: ---

Created attachment 48912
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48912&action=edit
simple test code to reproduce the bug

The attached simple test code shows a bug in gfortran v10.1.0 that is currently
blocking compile of several routines in my (large) simulation code. The issue
appears when optional arguments to a subroutine that are explicitly declared as
shared in openMP parallel declarations with default(none). That is, with
something like:

 subroutine mysub(n,x,sep,y)
  integer, intent(in) :: n
  real,    intent(in) :: x(:)
  real,    intent(out) :: sep
  real,    intent(in), optional :: y(:)
  integer :: i

  sep = 0.
  !$omp parallel do default(none) &
  !$omp shared(x,y,n) &
  !$omp private(i) &
  !$omp reduction(+:sep)
  do i=1,n
     sep = sep + x(i)**2
     if (present(y)) sep = sep + y(i)**2
  enddo

 end subroutine mysub

 The codes compiled fine in gfortran v9:

% gfortran-mp-9 -fopenmp -o test test.f90 
% ./test 
   10.0000000    

whereas with gfortran v10.1.0 the compiler fails with:

% gfortran -fopenmp -o test test.f90
test.f90:19:0:

   19 |      if (present(y)) sep = sep + y(i)**2
      | 
Error: 'y' not specified in enclosing 'parallel'
test.f90:19:0: Error: enclosing 'parallel'

My gfortran version is:

% gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/10.1.0/libexec/gcc/x86_64-apple-darwin19/10.1.0/lto-wrapper
Target: x86_64-apple-darwin19
Configured with: ../configure --build=x86_64-apple-darwin19
--prefix=/usr/local/Cellar/gcc/10.1.0
--libdir=/usr/local/Cellar/gcc/10.1.0/lib/gcc/10 --disable-nls
--enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran
--program-suffix=-10 --with-gmp=/usr/local/opt/gmp
--with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc
--with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew
GCC 10.1.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues
--disable-multilib --with-native-system-header-dir=/usr/include
--with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk
SED=/usr/bin/sed
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.1.0 (Homebrew GCC 10.1.0) 

Any help you can give for how to solve this (either in gfortran or as a
workaround). I've implemented one workaround already, but am still getting seg
faults in that routine and others because of the same problem:

https://github.com/danieljprice/phantom/issues/32

Reply via email to