[Patch, fortran] PR34640 - ICE when assigning item of a derived-component to a pointer
Thomas Koenig
tkoenig@netcologne.de
Tue Jul 4 21:04:00 GMT 2017
Hi Paul,
first, this patch looks really good - it certainly fixes a lot of the
ICEs.
I have a few points (a part already mentioned in private mail).
Consider the test case:
module x
use iso_c_binding
implicit none
type foo
complex :: c
integer :: i
end type foo
contains
subroutine printit(c)
complex, pointer, dimension(:) :: c
integer :: i
integer(kind=8) :: a
a = transfer(c_loc(c(1)),a)
print '(A,Z16)',"Adrress of first element is ", a
end subroutine printit
subroutine p2(c)
complex, dimension(:), target :: c
integer :: i
integer(kind=8) :: a
a = transfer(c_loc(c(1)),a)
print '(A,Z16)',"Adrress of first element is ", a
end subroutine p2
end module x
program main
use x
use iso_c_binding
implicit none
type(foo), dimension(5), target :: a
integer :: i
complex, dimension(:), pointer :: pc
complex, dimension(4), target :: v
integer(kind=8) :: s1, s2
a%i = 0
do i=1,5
a(i)%c = cmplx(i**2,i)
end do
pc => a%c
print *,"Pointer to complex passed to pointer argument:"
call printit(pc)
print *,"Pointer to complex passed to array argument"
call p2(pc)
s1 = transfer(c_loc(a(1)),s1)
print '(A,Z16,/)',"Main program: Address of first element: ", s1
pc => v
print *,"Pointer to complex passed to pointer argument:"
call printit(pc)
print *,"Complex array passed to array argument"
call p2(v)
s1 = transfer(c_loc(v(1)),s1)
print '(A,Z16)',"Address of first element: ", s1
end program main
This yields:
Pointer to complex passed to pointer argument:
Adrress of first element is 10021C90FF0
Pointer to complex passed to array argument
Adrress of first element is 10021C90FF0
Main program: Address of first element: 3FFFCEC599A4
Pointer to complex passed to pointer argument:
Adrress of first element is 10021C90FF0
Complex array passed to array argument
Adrress of first element is 3FFFCEC59A20
Address of first element: 3FFFCEC59A20
It appears that a temporary is created when passing
a pointer array to a pointer array dummy argument.
I think this would be wrong code, because the
subroutine could stash away the pointer and later
access data through it.
The same seems to happen when passing a pointer to
a normal argument - a temporary copy appears to be made.
While this code is correct, I am wodering if it
is intentional. Is the span field in the array
descriptor used in the called subroutine?
Regards
Thomas
More information about the Fortran
mailing list