Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28457 Discussions

COMPILER BUG? allocatable explicit-len character result

DataScientist
Valued Contributor I
406 Views

I have a small Fortran code that does not compile with both Intel and gfortran under any circumstances. Specifically, the following code yields an Internal compiler error with Intel ifort compiler version 2021.2, but gfortran compiles and runs it without any issues.

 

 

 

module bug_mod
    implicit none
    interface
    pure module function bug(Array) result(ArrayNew)
        character(*), intent(in), contiguous    :: Array(:)
        character(len(Array))   , allocatable   :: ArrayNew(:) ! catastrophic internal error with ifort 2021.2. Fine with gfortran 10.3
       !character(:)            , allocatable   :: ArrayNew(:) ! catastrophic internal error with gfortran 10.3. Fine with ifort 2021.2
    end function
    end interface
end module bug_mod

submodule (bug_mod) implementation_smod
    implicit none
contains
    module procedure bug
        allocate(ArrayNew, source = Array)
    end procedure
end submodule implementation_smod

program main
    use bug_mod, only: bug
    character(2) :: Array(3) = ["AA", "BB", "CC"]
    character(2), allocatable :: ArrayNew(:)
    ArrayNew = bug(Array)
end program main

 

 

 

Interestingly, if I uncomment the commented line in the above code and comment out the line above it, then ifort compiles and runs the code happily, while gfortran returns an internal compiler error. Which one is right? Both seem to be compiler bugs.

 

The issue for both compilers seems to be the separation of interface from the implementation. If I duplicate the interface in the submodule, both compilers can compile and run the code.

 

 

0 Kudos
1 Solution
FortranFan
Honored Contributor II
347 Views

@DataScientist ,

For whatever it's worth, I think the code you have posted conforms to the standard.  Regardless, an internal compiler error is always a compiler bug.  I suggest you submit support requests with both the compiler implementors.

View solution in original post

1 Reply
FortranFan
Honored Contributor II
348 Views

@DataScientist ,

For whatever it's worth, I think the code you have posted conforms to the standard.  Regardless, an internal compiler error is always a compiler bug.  I suggest you submit support requests with both the compiler implementors.

Reply