# Ifort/ifx issue with optional assumed-rank arrays

**URL:** <https://fortran-lang.discourse.group/t/ifort-ifx-issue-with-optional-assumed-rank-arrays/6877>\
**Category:** Help\
**Created:** [November 28, 2023, 10:32am UTC](https://fortran-lang.discourse.group/t/ifort-ifx-issue-with-optional-assumed-rank-arrays/6877 "2023-11-28T10:32:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [November 28, 2023, 10:32am UTC](https://fortran-lang.discourse.group/t/ifort-ifx-issue-with-optional-assumed-rank-arrays/6877/1 "2023-11-28T10:32:05Z")

</div>

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.

```auto
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?

```auto
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](https://godbolt.org/z/8svecrEGc)

---

<div class="post-metadata">

**Author:** ![hakostra](https://avatars.discourse-cdn.com/v4/letter/h/a3d4f5/32.png) [@hakostra](https://fortran-lang.discourse.group/u/hakostra)\
**Post date:** [November 28, 2023, 3:16pm UTC](https://fortran-lang.discourse.group/t/ifort-ifx-issue-with-optional-assumed-rank-arrays/6877/2 "2023-11-28T15:16:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [November 28, 2023, 3:40pm UTC](https://fortran-lang.discourse.group/t/ifort-ifx-issue-with-optional-assumed-rank-arrays/6877/3 "2023-11-28T15:40:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [November 28, 2023, 4:07pm UTC](https://fortran-lang.discourse.group/t/ifort-ifx-issue-with-optional-assumed-rank-arrays/6877/4 "2023-11-28T16:07:19Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [November 28, 2023, 4:17pm UTC](https://fortran-lang.discourse.group/t/ifort-ifx-issue-with-optional-assumed-rank-arrays/6877/5 "2023-11-28T16:17:12Z")

</div>

> [@Shahid](#):
>
> Different compilers have different ways to do a lot of things.

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

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [November 28, 2023, 4:59pm UTC](https://fortran-lang.discourse.group/t/ifort-ifx-issue-with-optional-assumed-rank-arrays/6877/6 "2023-11-28T16:59:29Z")

</div>

Reported on the Intel forum:

> **[Issue with optional assumed-rank arrays](https://community.intel.com/t5/Intel-Fortran-Compiler/Issue-with-optional-assumed-rank-arrays/m-p/1548397)**
>
> 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,...

---

<div class="post-metadata">

**Author:** ![everythingfunctional](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/everythingfunctional/32/176_2.png) [@everythingfunctional](https://fortran-lang.discourse.group/u/everythingfunctional)\
**Post date:** [November 28, 2023, 10:06pm UTC](https://fortran-lang.discourse.group/t/ifort-ifx-issue-with-optional-assumed-rank-arrays/6877/7 "2023-11-28T22:06:40Z")

</div>

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`.

```plaintext
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.

---

<div class="post-metadata">

**Author:** ![greenrongreen](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/greenrongreen/32/1249_2.png) [@greenrongreen](https://fortran-lang.discourse.group/u/greenrongreen)\
**Post date:** [November 29, 2023, 12:17am UTC](https://fortran-lang.discourse.group/t/ifort-ifx-issue-with-optional-assumed-rank-arrays/6877/8 "2023-11-29T00:17:53Z")

</div>

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
