public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/100870] New: Constant expression for bind(C) name in interface body not importable
@ 2021-06-02  7:51 ehlert at thch dot uni-bonn.de
  2021-06-03 16:17 ` [Bug fortran/100870] " kargl at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: ehlert at thch dot uni-bonn.de @ 2021-06-02  7:51 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100870
           Summary: Constant expression for bind(C) name in interface body
                    not importable
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ehlert at thch dot uni-bonn.de
  Target Milestone: ---

Created attachment 50906
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50906&action=edit
Minimal reproducer

Following example fails to compile with GFortran 10.2.0. The example was
checked with Intel's and NAG's Fortran compiler, which both accept the usage of
constant expressions imported into an interface body as valid Fortran code.
>From the Fortran standard this usage is valid Fortran 2003.


Code example to trigger the bug (also in os.f90 attachment):

module m_os
  use, intrinsic :: iso_c_binding
  implicit none
  character(len=*), parameter :: chdir_symbol = "chdir"

  interface
    function chdir(path) result(stat) bind(C, name=chdir_symbol)
      import :: c_char, c_int, chdir_symbol
      character(kind=c_char, len=1), intent(in) :: path(*)
      integer(c_int) :: stat
    end function chdir
  end interface
end module m_os


Output showing GFortran rejecting this code with an error

❯ gfortran -v -save-temps -Wall -Wextra -fno-strict-aliasing -fwrapv -c os.f90
Using built-in specs.
COLLECT_GCC=gfortran
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --with-isl
--with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit
--enable-cet=auto --enable-checking=release --enable-clocale=gnu
--enable-default-pie --enable-default-ssp --enable-gnu-indirect-function
--enable-gnu-unique-object --enable-install-libiberty --enable-linker-build-id
--enable-lto --enable-multilib --enable-plugin --enable-shared
--enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-libunwind-exceptions --disable-werror
gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-fno-strict-aliasing'
'-fwrapv' '-c' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/f951 os.f90 -quiet -dumpbase os.f90
-mtune=generic -march=x86-64 -auxbase os -Wall -Wextra -version
-fno-strict-aliasing -fwrapv -fintrinsic-modules-path
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/finclude
-fpre-include=/usr/include/finclude/math-vector-fortran.h -o os.s
GNU Fortran (GCC) version 10.2.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 10.2.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.2.1, isl version isl-0.21-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU Fortran2008 (GCC) version 10.2.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 10.2.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.2.1, isl version isl-0.21-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
os.f90:7:51:

    7 |     function chdir(path) result(stat) bind(C, name=chdir_symbol)
      |                                                   1
Error: Parameter ‘chdir_symbol’ at (1) has not been declared or is a variable,
which does not reduce to a constant expression
os.f90:8:13:

    8 |       import :: c_char, c_int, chdir_symbol
      |             1
Error: IMPORT statement at (1) only permitted in an INTERFACE body
os.f90:9:21:

    9 |       character(kind=c_char, len=1), intent(in) :: path(*)
      |                     1
Error: Parameter ‘c_char’ at (1) has not been declared or is a variable, which
does not reduce to a constant expression
os.f90:10:14:

   10 |       integer(c_int) :: stat
      |              1
Error: Parameter ‘c_int’ at (1) has not been declared or is a variable, which
does not reduce to a constant expression
os.f90:11:7:

   11 |     end function chdir
      |       1
Error: Expecting END INTERFACE statement at (1)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug fortran/100870] Constant expression for bind(C) name in interface body not importable
  2021-06-02  7:51 [Bug fortran/100870] New: Constant expression for bind(C) name in interface body not importable ehlert at thch dot uni-bonn.de
@ 2021-06-03 16:17 ` kargl at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: kargl at gcc dot gnu.org @ 2021-06-03 16:17 UTC (permalink / raw)
  To: gcc-bugs

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

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |kargl at gcc dot gnu.org
         Resolution|---                         |DUPLICATE

--- Comment #1 from kargl at gcc dot gnu.org ---
Interesting bug.  gfortran tries to reduce the constant
expression to a constant during the parse phase.  This
reduction occurs too early and needs to be moved to
the resolution phase.  In particular, decl.c:8052-8123
need to change/move to someplace in resolve.c where the
host namespace can be resolved to accommodate the import
statement.  Good Luck and happy hacking.

*** This bug has been marked as a duplicate of bug 86694 ***

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-03 16:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-02  7:51 [Bug fortran/100870] New: Constant expression for bind(C) name in interface body not importable ehlert at thch dot uni-bonn.de
2021-06-03 16:17 ` [Bug fortran/100870] " kargl at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).