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

Parameterized derived type: unexpected run-time error with arrays of non-default bounds

FortranFan
Honored Contributor III
861 Views

The following simple code encounters an unexpected run-time error:

module m

   type, public :: t( m, n )
      private
      integer, len :: m
      integer, len :: n
      real         :: m_a( m:n )
   contains
      private
      procedure, pass(this), public :: init => init_a_t
   end type t

contains

   subroutine init_a_t( this )

      class(t(*,*)), intent(inout) :: this

      print *, " lbound of this%m_a = ", lbound(this%m_a, dim=1)
      print *, " ubound of this%m_a = ", ubound(this%m_a, dim=1)

      this%m_a = 0.0

      return

   end subroutine init_a_t

end module m

program p

   use m, only : t

   implicit none

   type(t(-1,1)) :: foo

   call foo%init()

   stop

end program p

Upon execution with Intel Fortran compiler version 2015, update 4:

  lbound of this%m_a =  -1
  ubound of this%m_a =  1
forrtl: severe (408): fort: (11): Subscript #1 of the array M_A has value -1 whi
ch is less than the lower bound of 0

Image              PC                Routine            Line        Source

p64.exe            000000013FF3BAD0  Unknown               Unknown  Unknown
p64.exe            000000013FF316EE  M_mp_INIT_A_T              22  m.f90
p64.exe            000000013FF31931  MAIN__                      9  p.f90
p64.exe            000000013FFBDE6E  Unknown               Unknown  Unknown
p64.exe            000000013FFBE93C  Unknown               Unknown  Unknown
p64.exe            000000013FFBEA7E  Unknown               Unknown  Unknown
kernel32.dll       00000000776159DD  Unknown               Unknown  Unknown
ntdll.dll          00000000779AA551  Unknown               Unknown  Unknown
Press any key to continue . . .

 

0 Kudos
6 Replies
Steven_L_Intel1
Employee
861 Views

Thanks, we'll check it out. Escalated as issue DPD200372522. It seems to be just the bounds checking - the assignment is done correctly.

0 Kudos
FortranFan
Honored Contributor III
861 Views

Thanks Steve.

0 Kudos
FortranFan
Honored Contributor III
861 Views

Steve Lionel (Intel) wrote:

.. - the assignment is done correctly.

Steve,

Can you please look into this variation involving an ASSOCIATE construct as well?  So as you indicate, the assignment is done correctly if bounds checking is removed.  However, the array information doesn't seem to extend to the ASSOCIATE block:

module m

   type, public :: t( m, n )
      private
      integer, len :: m
      integer, len :: n
      real         :: m_a( m:n )
   contains
      private
      procedure, pass(this), public :: init => init_a_t
   end type t

contains

   subroutine init_a_t( this )

      class(t(*,*)), intent(inout) :: this

      print *, " lbound of this%m_a = ", lbound(this%m_a, dim=1)
      print *, " ubound of this%m_a = ", ubound(this%m_a, dim=1)

      this%m_a = 0.0
      print *, " this%m_a = ", this%m_a

      asc: associate ( a => this%m_a )
         print *, " lbound of a = ", lbound(a, dim=1)
         print *, " ubound of a = ", ubound(a, dim=1)
         print *, " a = ", a
      end associate asc

      return

   end subroutine init_a_t

end module m
program p

   use m, only : t

   implicit none

   type(t(-1,1)) :: foo

   call foo%init()

   stop

end program p

Upon execution,

  lbound of this%m_a =  -1
  ubound of this%m_a =  1
  this%m_a =  0.000000 0.000000 0.000000
  lbound of a =  0
  ubound of a =  0
  a =  0.000000
Press any key to continue . . .

 

0 Kudos
Steven_L_Intel1
Employee
861 Views

This is pretty much the same as the issue you reported in https://software.intel.com/en-us/forums/topic/542743 I've added this example to that issue, DPD200367383.

0 Kudos
FortranFan
Honored Contributor III
861 Views

Good catch about issue ID DPD200367383.  I was under the impression that was fixed.  I'm having a tough time keeping track of what works with PDTs in what Ifort version and what all issues are still pending, even those submitted by me.  It looks like I need to wait a while before I can consider incorporating PDTs into my code designs.

0 Kudos
Steven_L_Intel1
Employee
861 Views

I expect the initial problem reported here to get fixed in 16.0 Update 1.

0 Kudos
Reply