Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
1 View

-CB finds issues where everything works as inteded?

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
Highlighted
1 View

What version of ifort are you

What version of ifort are you using?

Jim Dempsey

0 Kudos
Highlighted
Black Belt
1 View

The behavior I see is an

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.

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
Employee
1 View

Thank you for the convenient

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
Highlighted
Valued Contributor III
1 View

Kevin,

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
Highlighted
Employee
1 View

It might FortranFan. I made a

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

0 Kudos
Highlighted
1 View

FWIW

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
Highlighted
Beginner
1 View

Thanks for all your comments.

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
Highlighted
1 View

Robin,

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
Highlighted
Valued Contributor I
1 View

Quote:jimdempseyatthecove

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