Bug 82065 - gfortran rejects redundant use of intrinsic module constant
Summary: gfortran rejects redundant use of intrinsic module constant
Status: WAITING
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2017-08-31 20:55 UTC by Damian Rouson
Modified: 2018-10-28 11:26 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-09-03 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Damian Rouson 2017-08-31 20:55:41 UTC
gfortran 6, 7, and 8 generate compiler error messages when a variable in the  iso_fortran_env intrinsic model is accessed via use association where it is also available via host association:

$ cat use-intrinsic-module-twice.f90 
  use iso_fortran_env
  implicit none
  print *, integer_kinds
  call testsub
contains
  subroutine testsub
    use iso_fortran_env
    print * , integer_kinds
  end subroutine
end

$ gfortran use-intrinsic-module-twice.f90 
/tmp/ccoAKOqk.s: Assembler messages:
/tmp/ccoAKOqk.s:134: Error: symbol `__iso_fortran_env_MOD_integer_kinds' is already defined

$ gfortran --version
GNU Fortran (GCC) 8.0.0 20170731 (experimental)
Comment 1 Dominique d'Humieres 2017-09-03 09:34:12 UTC
Confirmed on x86_64-apple-darwin16 from 4.8 up to trunk (8.0). Note that the error is given by the as. Is it the case on linux?
Comment 2 Harald Anlauf 2017-09-03 18:35:59 UTC
(In reply to Dominique d'Humieres from comment #1)
> Confirmed on x86_64-apple-darwin16 from 4.8 up to trunk (8.0). Note that the
> error is given by the as. Is it the case on linux?

Yes.

Note that the error goes away when any of the print statements is
commented out.
Comment 3 Harald Anlauf 2018-02-13 22:28:03 UTC
Slight variation of the original testcase that compiles
but gives a wrong result:

  use iso_fortran_env
  implicit none
  print *, integer_kinds
  call testsub
  call testsub2
contains
  subroutine testsub
    print *, integer_kinds
  end subroutine
  subroutine testsub2
    use iso_fortran_env, only : x => integer_kinds
    print *, x
  end subroutine
end

% ./a.out 
           1           2           4           8
           1           2           4           8
           0           0           0           0
Comment 4 Xin Wang 2018-04-09 11:27:20 UTC
Another variation, used in separate subroutines:

---8<---

implicit none

call sub1
call sub2

contains

  subroutine sub1
    use iso_fortran_env

    print *, integer_kinds
  end subroutine sub1

  subroutine sub2
    use iso_fortran_env

    print *, integer_kinds
  end subroutine sub2
end program

--->8---

Output:

---8<---

% gcc foo.f90 -lgfortran
/tmp//ccLBqjJe.s: Assembler messages:
/tmp//ccLBqjJe.s:158: Error: symbol `__iso_fortran_env_MOD_integer_kinds' is already defined

--->8---


Tested in:

gcc6 (FreeBSD Ports Collection) 6.4.0
gcc7 (FreeBSD Ports Collection) 7.3.0
gcc8 (FreeBSD Ports Collection) 8.0.1 20180325 (experimental)
Comment 5 Harald Anlauf 2018-04-11 19:09:20 UTC
This looks pretty much like a namespace problem.

Adding in the example in comment #4

    common /x/ integer_kinds

e.g. to subroutine sub1 makes the code illegal but compile.
It then prints:

           1           2           4           8
           0           0           0           0

I have looked at use_iso_fortran_env_module in module.c, but
frankly I do not understand how the code is supposed to work.
Comment 6 c.friedrich 2018-10-28 11:26:56 UTC
Slightly different case but probably the same bug:

      subroutine sub(i)
c      if(i==1.or.i==2) call sub1 ! this works
      if(any(i==[1,2])) call sub1 ! this does not
      call sub2                                                                                           

      contains                                                                                                       

      subroutine sub1                                                                                                
      use iso_fortran_env                                                                                            
      real(real64) :: a                                                                          
      end subroutine sub1                                                                                            

      subroutine sub2                                                                                                
      use iso_fortran_env                                                                                            
      real(real64) :: b                                                                                              
      end subroutine sub2

      end

Compilation fails with any optimization level different from -O0:
/tmp/ccZ13RIp.s: Assembler messages:
/tmp/ccZ13RIp.s:23: Error: symbol `__iso_fortran_env_MOD_real64' is already defined

Slight changes of the code makes the error disappear. For example, not using the "any" construction in the if command. Or commenting out one of the two subroutine calls. Or commening out any of the declarations (a or b) in the subroutines. Or using "real(8)" instead of "real(real64)".

Tested versions: 5.5.0, 7.3.0