From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 131046 invoked by alias); 4 Jul 2017 21:04:06 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 131018 invoked by uid 89); 4 Jul 2017 21:04:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=transfer X-Spam-User: qpsmtpd, 2 recipients X-HELO: cc-smtpout1.netcologne.de Received: from cc-smtpout1.netcologne.de (HELO cc-smtpout1.netcologne.de) (89.1.8.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Jul 2017 21:04:03 +0000 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout1.netcologne.de (Postfix) with ESMTP id CDB2F12D87; Tue, 4 Jul 2017 23:04:00 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin2.netcologne.de (Postfix) with ESMTP id C02B511DCB; Tue, 4 Jul 2017 23:04:00 +0200 (CEST) Received: from [78.35.144.8] (helo=cc-smtpin2.netcologne.de) by localhost with ESMTP (eXpurgate 4.1.9) (envelope-from ) id 595c02c0-022c-7f0000012729-7f000001e48d-1 for ; Tue, 04 Jul 2017 23:04:00 +0200 Received: from [192.168.178.20] (xdsl-78-35-144-8.netcologne.de [78.35.144.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA; Tue, 4 Jul 2017 23:03:58 +0200 (CEST) Subject: Re: [Patch, fortran] PR34640 - ICE when assigning item of a derived-component to a pointer To: Paul Richard Thomas , "fortran@gcc.gnu.org" , gcc-patches References: From: Thomas Koenig Message-ID: <36a479a8-e22b-f675-7f3d-b7324f872357@netcologne.de> Date: Tue, 04 Jul 2017 21:04:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2017-07/txt/msg00235.txt.bz2 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