From: Thomas Koenig <tkoenig@netcologne.de>
To: Paul Richard Thomas <paul.richard.thomas@gmail.com>,
"fortran@gcc.gnu.org" <fortran@gcc.gnu.org>,
gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [Patch, fortran] PR34640 - ICE when assigning item of a derived-component to a pointer
Date: Tue, 04 Jul 2017 21:04:00 -0000 [thread overview]
Message-ID: <36a479a8-e22b-f675-7f3d-b7324f872357@netcologne.de> (raw)
In-Reply-To: <CAGkQGiL4T0hm6uCPSPsvaSzJ=_ELNO2Ubc9jLbDXJ04aUH-2ww@mail.gmail.com>
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
next prev parent reply other threads:[~2017-07-04 21:04 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-24 10:48 Paul Richard Thomas
2017-06-25 10:59 ` Thomas Koenig
2017-06-25 11:43 ` Paul Richard Thomas
2017-07-01 18:17 ` Paul Richard Thomas
2017-07-04 21:04 ` Thomas Koenig [this message]
2017-07-09 18:43 ` Paul Richard Thomas
2017-07-09 21:28 ` Thomas Koenig
2017-07-11 6:16 ` Paul Richard Thomas
2017-07-11 14:24 ` Paul Richard Thomas
2017-07-11 14:48 ` Jerry DeLisle
2017-07-11 18:13 ` Thomas Koenig
2017-07-11 20:23 ` Paul Richard Thomas
2017-09-11 19:47 ` H.J. Lu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=36a479a8-e22b-f675-7f3d-b7324f872357@netcologne.de \
--to=tkoenig@netcologne.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=paul.richard.thomas@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).