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-04-11 19:09 UTC (History)
3 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.