Ifort/ifx issue with optional assumed-rank arrays

This program below with a cascaded optional array, which is assumed-rank in the last called routine, works fine with gfortran, but fails on execution with any version of ifort/ifx.

module foo
implicit none

contains

    subroutine foo1(a)
        real, intent(in), optional :: a(:)
        call foo2(a)
    end subroutine

   subroutine foo2(a)
        real, intent(in), optional :: a(..)
       if (present(a)) then
            print*, rank(a)
        else
            print*, "a not present"
        end if
   end subroutine   

end module

program bar
use foo
implicit none

call foo1()

end

Is it a ifort/ifx bug, or is the code invalid?

forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source             
libc.so.6          00007F889BE42520  Unknown               Unknown  Unknown
output.s           0000000000405214  Unknown               Unknown  Unknown
output.s           0000000000405450  Unknown               Unknown  Unknown
output.s           000000000040518D  Unknown               Unknown  Unknown
libc.so.6          00007F889BE29D90  Unknown               Unknown  Unknown
libc.so.6          00007F889BE29E40  __libc_start_main     Unknown  Unknown
output.s           00000000004050A5  Unknown               Unknown  Unknown

Try it here: Compiler Explorer

I would make a post about this on the Intel community (under the Fortran compiler subsection). They seem eager to get bugs fixed these days.

2 Likes

@hakostra Yes, this is the right think to do, but I wanted to make sure it was (likely) a bug before posting there…

Different compilers have different ways to do a lot of things. You can try to write a 2D array say of random numbers with an implied do loop using the intel compiler and then see the result with gfortran !

Maybe, but that’s not the point… If this code is valid, then there is a bug in the compiler here.

Reported on the Intel forum:

FWIW, I think the program is standards conforming. However, when I turn on the stack trace (i.e. -g -traceback) I see the segfault coming from the beginning of foo1.

forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source             
libc.so.6          00007F23A2842520  Unknown               Unknown  Unknown
output.s           0000000000405214  foo1                        6  example.f90
output.s           0000000000405450  bar                        26  example.f90
output.s           000000000040518D  Unknown               Unknown  Unknown
libc.so.6          00007F23A2829D90  Unknown               Unknown  Unknown
libc.so.6          00007F23A2829E40  __libc_start_main     Unknown  Unknown
output.s           00000000004050A5  Unknown               Unknown  Unknown

I suspect that means the assumed rank is a red-herring.

I posted a reply on the Intel Forum - this code is working in the current main branch. This will appear in the next update release, 2024.1

4 Likes