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

New Error with IVF 10.0.026

GVautier
New Contributor III
779 Views
The following code doesn't cause any problem with CVF and IVF 9 and 10.0.025.

 integer*4 function get_lig(ptr_lig,buffer,lig)
 integer*4,intent(in) :: ptr_lig(0:1)
 character*1,pointer :: buffer(:)
 character*(*),intent(out) :: lig
 ...
 end function
 integer*4,pointer :: ptr_lig(:)
-> dummy=get_lig(ptr_lig(0),buffer,lig)

With IVF 10.0.026, the following error code is generated at compile time :

Error: If the actual argument is scalar, the corresponding dummy 
argument shall be scalar unless the actual argument is an element
of an array that is not an assumed-shape or pointer array, or a
substring of such an element. [PTR_LIG]

I doesn't understand the error message because, for me, there is no problem about passing the address of an array element to a function expecting an array and this code runs perfectly for years.

Is this normal? If yes is there a compiler switch to avoid that kind of error?


Thanks



0 Kudos
5 Replies
Steven_L_Intel1
Employee
779 Views
The error message is correct - the new compiler is detecting a standards violation (and potential memory corruption error) that earlier compilers did not catch.

Ordinarily, passing an array element to a routine where the dummy argument is an array is fine - the language has a rule called "sequence association" for this. But PTR_LIG in the caller is a pointer, and this could be discontiguous, so sequence association is invalid.

Solutions for you might be to pass PTR_LIG(0:1) or to make PTR_LIG an ALLOCATABLE rather than POINTER array. Not knowing the rest of your application I don't know what would work best for you. There is no switch to turn off this error.
0 Kudos
GVautier
New Contributor III
779 Views
Thanks for the reply.

If I pass PTR_LIG(0:1), does it generates a temporary array?


0 Kudos
Steven_L_Intel1
Employee
779 Views
It will do a run-time test and if the section is contiguous, not make a copy. If you want to verify that, turn on the run-time check for "arg_temp_created".
0 Kudos
Intel_C_Intel
Employee
779 Views
Hello. I have attached some sample code that produces the same error that the initial post listed. Based on this thread, we believe that we are experiencing the same error. Could you please confirm that this is correct.

It is interesting that Compaq Visual Fortran 6.1, Intel Fortran 7.1 (Linux), and Intel Visual Fortran 9.1, and f95 don't complain about this standards violation. Is the change between Intel Visual Fortran 9.1 and 10.0 due to the introduction of new Fortran 2003 standard features?

Thanks for looking at this.

Bill

! test_case.f90
!
! FUNCTIONS:
! test_case - Entry point of console application.
!

!****************************************************************************
!
! PROGRAM: test_case
!
! PURPOSE: Entry point for the console application.
!
!****************************************************************************

program test_case

implicit none

! Variables
integer, dimension(1:3, 1:3) :: A
integer, dimension(:,:), pointer :: Ap
integer, dimension(:), pointer :: Cp
integer iujeff
integer i
integer j
integer N

!set N as dimension to 3
N=3

!Open the output file
iujeff=100
open(iujeff, file="test_case_output.txt")

!Output the opening messages
write(iujeff,*) 'Test case for array slicing problem'
write(iujeff,*) ''

! Assign values to A
A(:,1) = (/1, 2, 3/)
A(:,2) = (/2, 20, 30/)
A(:,3) = (/3, 30, 300/)

!write out A matrix
write(iujeff, *) 'The A matrix:'

do i=1,N
write(iujeff, "(3I6)") A(i,:)
end do

!pass a slice into the function
write(iujeff, *) ''
write(iujeff, *) 'Pass slice A(:,3) into subroutine pass_slice'
call pass_slice(A(:,3),N,iujeff)

!pass the slice as A(1,3)
write(iujeff, *) ''
write(iujeff, *) 'Pass A(1,3) into subroutine pass_slice'
call pass_slice(A(1,3),N,iujeff)


!allocate and assign values to Ap
allocate(Ap(1:N,1:N))
do i=1,N
do j=1,N
Ap(i,j)=i+10*(j-1)
end do
end do

!output Ap
write(iujeff, *) ''
write(iujeff, *) 'The Ap matrix '
do i=1,N
write(iujeff, "(3I6)") Ap(i,:)
end do

!pass slice of Ap
write(iujeff, *) ''
write(iujeff, *) 'Pass slice Ap(:,2)'
call pass_slice(Ap(:,2), N, iujeff)

!*************************************************************** ***
! location of the problem
! pass slice of Ap using 1 as the first index
! This does not work if the compiler is 10.026
! However, it does work if the compiler is compaq 6.0
! and if the compiler is g95 4.0.1 (linux)
!******************************************************************
write(iujeff, *) ''
write(iujeff, *) 'Pass slice Ap(1,2)'
call pass_slice(Ap(1,2),N,iujeff)

!close the file
close(iujeff)

contains

subroutine pass_slice(C,N,iuval)
!define variables
integer, dimension(1:3) :: C
integer :: N
integer :: iuval

!output the passed array
write(iuval,*) 'The passed array into pass_slice is'
&nbs p; write(iuval, "(3I6)") C(:)
end subroutine pass_slice

end program test_case

0 Kudos
Steven_L_Intel1
Employee
779 Views
It compiles without a message in those other compilers because they do not notice the error. It was a bug in our earlier compilers that the error was not detected and it is an error in gfortran that the error is not detected - I suggest you file a bug report against gfortran.

The text in Fortran 2003 is (emphasis mine):

25 If the actual argument is scalar, the corresponding dummy argument shall be scalar unless the actual
26 argument is of type default character, of type character with the C character kind (15.1), or is an element
27 or substring of an element of an array that is not an assumed-shape or pointer array.

Fortran 95 has similar wording.

This rule is in place to prevent the possibility of "sequence association" with a non-contiguous array argument.

We reserve the right to change the compiler so that incorrect programs are properly diagnosed, even if the error was not detected by earlier versions.
0 Kudos
Reply