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

-CB finds issues where everything works as inteded?

Robin_T_
Novice
404 Views

Hello,

when I run the following program

program testbounds
	implicit none
	REAL, DIMENSION (5,5) :: A
	INTEGER, DIMENSION (2) :: K = (/ 1, 3 /)

	A = 0.d0
	A (2, (/1, 3, 5/)) = 1.d0
	print*, A    
	print*, A (2, K)

end program testbounds

without check options it runs fine and delivers the desired result. When i use compiler option -CB I get

forrtl: severe (408): fort: (3): Subscript #2 of the array A has value 0 which is less than the lower bound of 1

Image              PC                Routine            Line        Source             
testbounds.x         0000000000404E66  Unknown               Unknown  Unknown
testbounds.x         0000000000402D84  MAIN__                      9  testbounds.f90
testbounds.x         0000000000402B9E  Unknown               Unknown  Unknown
libc-2.22.so       00002B2D3557A6E5  __libc_start_main     Unknown  Unknown
testbounds.x         0000000000402AA9  Unknown               Unknown  Unknown

This is a bit strange to me and annoying because it prevents the use of -CB to find the real errors.

0 Kudos
9 Replies
jimdempseyatthecove
Honored Contributor III
404 Views

What version of ifort are you using?

Jim Dempsey

0 Kudos
Steve_Lionel
Honored Contributor III
404 Views

The behavior I see is an access violation/segfault, but I think it's just another symptom of the underlying compiler bug in that it is looking in the wrong place for the vector subscript bounds.  I am sure one of the Intel folks will be along to write this up for development.

0 Kudos
Kevin_D_Intel
Employee
404 Views

Thank you for the convenient reproducer. I too can reproduce this. On Linux, when run repeatedly I see either a SegV or a forrtl bounds error similar to what is shown in the original post. I escalated the issue to Development.

(Internal tracking id: DPD200418047)

0 Kudos
FortranFan
Honored Contributor II
404 Views

Kevin,

Do you think this is related to the vector-subscript issue noticed in this recent thread?  Thanks,

https://software.intel.com/zh-cn/comment/1895746

 

0 Kudos
Kevin_D_Intel
Employee
404 Views

It might FortranFan. I made a note in the internal report about that.

0 Kudos
jimdempseyatthecove
Honored Contributor III
404 Views

FWIW

program testbounds
 implicit none
 REAL, DIMENSION (5,5) :: A
 INTEGER, DIMENSION (2) :: K = (/ 1, 3 /)

 A = 0.d0
 A (2, (/1, 3, 5/)) = 1.d0
 print*, A    
 print*, (A(2, K)) ! add ()'s

end program testbounds

Jim Dempsey

0 Kudos
Robin_T_
Novice
404 Views

Thanks for all your comments.

I forgot to mention that I am using ifort version 17.0.1 on Linux 4.4.21-81-default x86_64

Adding the brackets, as proposed by Jim, works in that case but in the more complicated case:

 

program testbounds

	REAL, DIMENSION (5,5) :: A
  INTEGER, DIMENSION (2) :: K = [1, 3]

	A = 0.d0
	A (2, [1, 5]) = 1.d0
	A (2, 3) = 2.d0
	open (13, status = 'scratch')
	write (13, *) (A (2, [3, 5]))
	read (13, *) (A (3, [3, 5]))
	close (13)
	print *, A

end program testbounds

this does not help either:

ifort -m64 -fpp -fopenmp -O3 -g -traceback -CB -c testbounds.f90
ifort testbounds.o -m64 -fpp -fopenmp -O3 -g -traceback -CB -o testbounds.x

forrtl: severe (408): fort: (2): Subscript #2 of the array A has value 32767 which is greater than the upper bound of 5

Image              PC                Routine            Line        Source             
testbounds.x       0000000000406836  Unknown               Unknown  Unknown
testbounds.x       0000000000402C59  MAIN__                     11  testbounds.f90
testbounds.x       0000000000402A9E  Unknown               Unknown  Unknown
libc-2.22.so       00002B9CD779C6E5  __libc_start_main     Unknown  Unknown
testbounds.x       00000000004029A9  Unknown               Unknown  Unknown

So it works for write but not for read

0 Kudos
jimdempseyatthecove
Honored Contributor III
404 Views

Robin,

The PRINT works because a temporary variable is created. A little overhead traded off against a bug fix.

For the READ, you do want to read into a temporary variable (which would be discarded had it worked).

I was going to suggest using associate, but this appears to expose a compiler bug (at least I think it is a bug)

program testbounds
 implicit none
 REAL, DIMENSION (5,5) :: A
 INTEGER, DIMENSION (2) :: K = (/ 1, 3 /)

 A = 0.d0
 A (2, [1, 5]) = 1.d0
 A (2, 3) = 2.d0
 open (13, status = 'scratch')
    associate( slice => A (2, [3, 5]))
   write (13, *) slice
      slice = 0.0
   print*, (A(2, K)) ! add ()'s
      rewind(13)
   read (13, *) slice
    end associate
    close (13)
 print *, A
 print*, (A(2, K)) ! add ()'s

end program testbounds

1>C:\test\testbounds\testbounds\testbounds.f90(19): error #6421: This scalar or array name is invalid in this context.   [SLICE]

Can someone explain why this does not work?

Jim Dempsey

0 Kudos
Juergen_R_R
Valued Contributor I
404 Views

jimdempseyatthecove wrote:

 

program testbounds
 implicit none
 REAL, DIMENSION (5,5) :: A
 INTEGER, DIMENSION (2) :: K = (/ 1, 3 /)

 A = 0.d0
 A (2, [1, 5]) = 1.d0
 A (2, 3) = 2.d0
 open (13, status = 'scratch')
    associate( slice => A (2, [3, 5]))
   write (13, *) slice
      slice = 0.0
   print*, (A(2, K)) ! add ()'s
      rewind(13)
   read (13, *) slice
    end associate
    close (13)
 print *, A
 print*, (A(2, K)) ! add ()'s

end program testbounds

1>C:\test\testbounds\testbounds\testbounds.f90(19): error #6421: This scalar or array name is invalid in this context.   [SLICE]

Can someone explain why this does not work?

Jim Dempsey

associate-name => selector.  The standard says that if the selector is a variable with a vector subscript, the associated name must not appear in a variable definition context. e.g. Fortran Handbook, Sec. 8.2.1. A(2, 3:5) would work, than it's an array slice, not a vector subscript.

 

0 Kudos
Reply