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

            Bug ID: 82796
           Summary: Private+equivalence in used module breaks compilation
                    of pure function
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ripero84 at gmail dot com
  Target Milestone: ---

gfortran (multiple versions including 7.2.0, 6.4.0 and 5.4.1,) fails to compile
the following code

===============================================================

MODULE EQ
  implicit none

  INTEGER :: N1
  INTEGER :: N2
  INTEGER, DIMENSION(2) :: a

  EQUIVALENCE (a(1), N1)
  EQUIVALENCE (a(2), N2)

  COMMON /A/ a
END MODULE EQ

!--------------------------------------------------------------

module m
  use eq
  implicit none
  private

  type, public :: t
    integer :: i
  end type t

end module m

!--------------------------------------------------------------

module p
  implicit none
contains

  pure integer function d(h)
    use m, only: t
    implicit none
    integer, intent(in) :: h
    d = h
  end function

end module p

===============================================================

As far as I can see (see also
https://groups.google.com/forum/#!topic/comp.lang.fortran/9sC7kUje0Mc ), the
pure function is not attempting to access the variables that are affected by
the EQUIVALENCE in module EQ - what's more, the function should not be allowed
to have access to them since they are private.

Other compilers (intel, nag) and older versions of gfortran (4.8.4., 4.9.3) do
not complain about this and compile the code.

The compilation error is provided below.

===============================================================

$ gfortran-7 -v -c -std=f2008 foo.f90 -o foo.o
Using built-in specs.
COLLECT_GCC=gfortran-7
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 7.2.0-12'
--with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-major-version-only --program-suffix=-7
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie
--with-system-zlib --with-target-system-zlib --enable-objc-gc=auto
--enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 7.2.1 20171025 (Debian 7.2.0-12) 
COLLECT_GCC_OPTIONS='-v' '-c' '-std=f2008' '-o' 'foo.o' '-mtune=generic'
'-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/7/f951 foo.f90 -quiet -dumpbase foo.f90
-mtune=generic -march=x86-64 -auxbase-strip foo.o -std=f2008 -version
-fintrinsic-modules-path /usr/lib/gcc/x86_64-linux-gnu/7/finclude -o
/tmp/ccpUItgn.s
GNU Fortran (Debian 7.2.0-12) version 7.2.1 20171025 (x86_64-linux-gnu)
        compiled by GNU C version 7.2.1 20171025, GMP version 6.1.2, MPFR
version 3.1.6, MPC version 1.0.3, isl version isl-0.18-GMP

warning: MPFR header version 3.1.6 differs from library version 3.1.5.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU Fortran2008 (Debian 7.2.0-12) version 7.2.1 20171025 (x86_64-linux-gnu)
        compiled by GNU C version 7.2.1 20171025, GMP version 6.1.2, MPFR
version 3.1.6, MPC version 1.0.3, isl version isl-0.18-GMP

warning: MPFR header version 3.1.6 differs from library version 3.1.5.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
foo.f90:34:8:

     use m, only: t
        1
Error: Common block member ‘a’ at (1) cannot be an EQUIVALENCE object in the
pure procedure ‘d’
foo.f90:34:8:

     use m, only: t
        1
Error: Common block member ‘a’ at (1) cannot be an EQUIVALENCE object in the
pure procedure ‘d’

Reply via email to