From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.smtpout.orange.fr (smtp-18.smtpout.orange.fr [80.12.242.18]) by sourceware.org (Postfix) with ESMTPS id 4FDE93858D3C for ; Tue, 4 Jul 2023 13:35:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4FDE93858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orange.fr Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=orange.fr Received: from [192.168.1.16] ([86.215.161.51]) by smtp.orange.fr with ESMTPA id GgBsq7HmjgNRdGgBsqQPI2; Tue, 04 Jul 2023 15:35:36 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=orange.fr; s=t20230301; t=1688477736; bh=NYOiWUEGK2Dvdrf1t9v84XRoG9wrPV41kTWUXzO2L0Y=; h=Date:Subject:To:References:From:In-Reply-To; b=h8l70tTLoK57CU44QY18Wg+q37jkLg1MVS1KXUevmZhaRjRQxFjTs9rldHSBY+pOY FOl4RH/5R33bDmvoj0UwQkZhFHAuZTx0ZQ9oBb08gdB8cUu3tgdRs5qbkMnW6jvS2V r8+Fm03rAWKvKai4T6jTwol9C7k9lVQSKFj16TE4mw6kZw10Eug5DlTitnfVJWCbGe TvnYeTP3OLMN8Ok7sWwT0wKhuw1SaS4GUeIvt0o+oeAb0IpSbGltcrEXJkxx0zBdDu CG/L/4aEefmhO1RO6CmIiEuPN/oVJM0Huv6cnpuwsv/w5K/Qeg739m9VUDFbo4mX0g oqi7vjbxxsNoA== X-ME-Helo: [192.168.1.16] X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Tue, 04 Jul 2023 15:35:36 +0200 X-ME-IP: 86.215.161.51 Message-ID: Date: Tue, 4 Jul 2023 15:35:36 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH] Fortran: fixes for procedures with ALLOCATABLE,INTENT(OUT) arguments [PR92178] Content-Language: en-US To: Harald Anlauf , fortran , gcc-patches References: <5a5306ae-0db1-c7e2-e744-a3beced17636@orange.fr> <3adc2904-9876-74d6-2b5d-3cc1896866c3@gmx.de> From: Mikael Morin In-Reply-To: <3adc2904-9876-74d6-2b5d-3cc1896866c3@gmx.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.2 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,JMQ_SPF_NEUTRAL,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Le 03/07/2023 à 22:49, Harald Anlauf a écrit : > Hi Mikael, > > Am 03.07.23 um 13:46 schrieb Mikael Morin: >> These look good, but I'm surprised that there is no similar change at >> the 6819 line. >> This is the class array actual vs class array dummy case. >> It seems to be checked by the "bar" subroutine in your testcase, except >> that the intent(out) argument comes last there, whereas it was coming >> first with the original testcases in the PR. >> Can you double check? > > I believe I tried that before and encountered regressions. > The change > > diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc > index 16e8f037cfc..43e013fa720 100644 > --- a/gcc/fortran/trans-expr.cc > +++ b/gcc/fortran/trans-expr.cc > @@ -6844,7 +6844,8 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * > sym, >                   else >                     tmp = gfc_finish_block (&block); > > -                 gfc_add_expr_to_block (&se->pre, tmp); > +//               gfc_add_expr_to_block (&se->pre, tmp); > +                 gfc_add_expr_to_block (&dealloc_blk, tmp); >                 } > >               /* The conversion does not repackage the reference to a > class > > regresses on: > gfortran.dg/class_array_16.f90 > gfortran.dg/finalize_12.f90 > gfortran.dg/optional_class_1.f90 > > A simplified testcase for further study: > > program p >   implicit none >   class(*),  allocatable :: c(:) >   c = [3, 4] >   call bar (allocated (c), c, allocated (c)) >   if (allocated (c)) stop 14 > contains >   subroutine bar (alloc, x, alloc2) >     logical :: alloc, alloc2 >     class(*), allocatable, intent(out) :: x(:) >     if (allocated (x)) stop 5 >     if (.not. alloc)   stop 6 >     if (.not. alloc2)  stop 16 >   end subroutine bar > end > > (This fails in a different place for the posted patch and for > the above trial change.  Need to go to the drawing board...) > I've had a quick look. The code originally generated looks like: D.4343 = (void *[0:] * restrict) c._data.data != 0B; if (c._data.data != 0B) // free c._data.data c._data.data = 0B; ... class.3._data = c._data; ... D.4345 = (void *[0:] * restrict) c._data.data != 0B; bar (&D.4343, &class.3, &D.4345); this fails because D.4345 has the wrong value. With your change, it becomes: D.4343 = (void *[0:] * restrict) c._data.data != 0B; ... class.3._data = c._data; ... D.4345 = (void *[0:] * restrict) c._data.data != 0B; if (c._data.data != 0B) // free c._data.data c._data.data = 0B; bar (&D.4343, &class.3, &D.4345); and then it is class.3._data that has the wrong value. So basically the initialization of class.3 should move with the deallocation. I can reproduce a similar problem with your unmodified patch on the following variant: program p implicit none class(*), allocatable :: c c = 3 call bar (c, allocated (c)) if (allocated (c)) stop 14 contains subroutine bar (x, alloc2) logical :: alloc, alloc2 class(*), allocatable, intent(out) :: x(..) if (allocated (x)) stop 5 if (.not. alloc) stop 6 if (.not. alloc2) stop 16 end subroutine bar end