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

Issue with optional assumed-rank arrays

PierU
Novice
775 Views

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: https://godbolt.org/z/8svecrEGc

 

 

1 Solution
Ron_Green
Moderator
737 Views

As you state, this segfaults with the current ifx 2024.0.0.  But I tested with our internal code that will come with our next update release, 2024.1.0.  In this future version of 2024.1.0 it is fixed in ifx and ifort

 

$ ifx repro.f90

$ ./a.out

a not present

 

View solution in original post

4 Replies
Ron_Green
Moderator
738 Views

As you state, this segfaults with the current ifx 2024.0.0.  But I tested with our internal code that will come with our next update release, 2024.1.0.  In this future version of 2024.1.0 it is fixed in ifx and ifort

 

$ ifx repro.f90

$ ./a.out

a not present

 

riad_h_1
Novice
292 Views

I  have a similar issue even with  the 2024.1 release:

integer, allocatable :: x

print*,'When x is unallocated:'
call foo(x); call foo_ar(x)
print*,'When x is allocated:'
x = 1
call foo(x); call foo_ar(x)

contains

   subroutine foo ( x )
      integer, optional, intent(in) :: x
      if ( present(x) ) then
         print*,'- with foo: x is present'
      else
         print*,'- with foo: x is absent'
      end if
   end subroutine foo

   subroutine foo_ar ( x )
      integer, optional, intent(in) :: x(..)
      if ( present(x) ) then
         print*,'- with foo_ar: x is present'
      else
         print*,'- with foo_ar: x is absent'
      end if
   end subroutine foo_ar

end

I get with ifx ((IFX) 2024.1.2 20240508):

 When x is unallocated:
 - with foo: x is absent
 - with foo_ar: x is present
 When x is allocated:
 - with foo: x is present
 - with foo_ar: x is present

While with gfortran (GNU Fortran (SUSE Linux) 7.5.0):

When x is unallocated:
 - with foo: x is absent
 - with foo_ar: x is absent
 When x is allocated:
 - with foo: x is present
 - with foo_ar: x is present

 

0 Kudos
Ron_Green
Moderator
261 Views

A new and different bug.  I will open a new bug report. Thank you for finding this.  

 

15.5.2.13 Argument presence and restrictions on arguments not present

   A dummy argument or an entity that is host associated with a dummy  argument is not present if the dummy argument

  • does not correspond to an actual argument
  • corresponds to an actual argument that is not present, or
  • does not have the ALLOCATABLE or POINTER attribute, and corresponds to an actual argument that
    • has the ALLOCATABLE attribute and is not allocated, or
    • has the POINTER attribute and is disassociated;

otherwise, it is present.

0 Kudos
Ron_Green
Moderator
248 Views

bug tracking ID is CMPLRLLVM-59233


0 Kudos
Reply