From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id CE9E63858D34; Mon, 10 Jun 2024 06:22:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CE9E63858D34 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CE9E63858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718000550; cv=none; b=H+YvKbEiRKAouuk6Ad9nPAvAbdj0tH3YTkDN9g7uLW3ZeCylHZ8NqdBcU6NgYyIpadR7QNm/WcKgeEKQXI0g0B3F/7XXuwZGJE2FRUQwr/Z12wHLZ0o/nBHzcxN+qYDa2oBYU+mvEnSoWR6UIyg/6UPae3DyjJo6Br/XRTQeANo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718000550; c=relaxed/simple; bh=6msyfhn8OZ2ZSyiheKo+OUnnli3pj7RuhVoc4Bqy3xQ=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=Zi+XbCVmhN3UY88LbF8yJOw026rqguFH11MPmimbO00zjdVrhesZfrMt7+vgunaMTsofcsD2xa41Dp2xb9Hr+lBdn/UySvwezhqzlu/J9O59881PoKF+JNniRT357XsZABqZyBRx9nPFiulePD9PFGMbNy0OW2H4SX2UrEp/ZI0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-6e5fd488d9fso1599791a12.3; Sun, 09 Jun 2024 23:22:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718000548; x=1718605348; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=nK1gdGLq6pDQa84fhQwOjFOostrCRUWB8v6IQk/RX9c=; b=R969pUkUy7FHsxvOiDH/DT2qYQ6z11h4iiGKh6UOPdkWc5xjaL3Y/c4G92NrOATHOg yarsvokGBZQP4GrU4lYu8C+hR0zrymGsR1SIaYffqF4rmbe4dqV1g2frhBgf7OKtz+jA JEgcpYRvqbkU1aJ/X5IA9HmjyoPGJ9lKsi4/WVnfempX08X7g3Gcp34Uj30qC8xQ+tH1 m4ymi4h5VutrexS9aAxPGjcYWd5gPaZsE1r3d+PjXZdKOdHABI0eiEDy2Hrq4U9tL8l8 7cGYQco3eOc92qMRWRfLXViAkoTx6FV/6dAKY6eYYnUmpg39jIo1i4D1vLiYojSDJNJ8 xBMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718000548; x=1718605348; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nK1gdGLq6pDQa84fhQwOjFOostrCRUWB8v6IQk/RX9c=; b=fo66wwKicXhQXEk+lTmTTVedEa6V7ODLCewnV/Qaq7Vy6zLdvN4RIHLT3p7mqhr8Nf v8oCPgvq+X6IjPMCxN78UHMFDbBMvma94giwvh98dglahjz2KzeSkSh3aWBZETuReJt0 eUBIwHkqwulT4p1XkVL06JgWJU1fTwG4WfRyby8ClLrx1Q3YDo6Tw8kYTBfVuqTpTtU8 QrcCp0b33LKWCSA0SQEsxYOzRayQS+6wP1A7q+KY2diHm+QpOeK1W2nif/YGXjmrBQuk UXbUQkLAlueO6i2UIixvGms5OEbzdUnL3UHWARZkS/6AXfx3s3qEiXHGl2pLGbhzU+Gz waNQ== X-Forwarded-Encrypted: i=1; AJvYcCWwzKheLeF3SnCwU0htrRvBVM2Ylj5omACsy2ZFAT6DKrYI9qlQGn1FJPOV3fEsBYwZXVRwoEzfqWOgjcl7YPBBaua3lQ3xoQ== X-Gm-Message-State: AOJu0YxXbLSaGej+Fo2dY5RfJAS3xnQbo9HXV1gXvJ5EyNHdAw+3gb5A dSPKftPcyfYc4b2RXFZt8e01tT2amJQZaHCtF5TSFYrnXlJpbkpQZGHKQOzH5mNSCIyAowyIhPO FYrEXmFpl+DC7pH2adIE7x1PnSiFIYIhb X-Google-Smtp-Source: AGHT+IGHq5R0qIs13LC7vma+njiHUvwgCx7P9HhETEP1/db1bEoVLTGcxR2PwLtQHE39xAKn/flbEJVnttvjLtuilA4= X-Received: by 2002:a17:90a:bb0f:b0:2c2:cd5c:62ac with SMTP id 98e67ed59e1d1-2c2cd5c66c6mr7260956a91.9.1718000547675; Sun, 09 Jun 2024 23:22:27 -0700 (PDT) MIME-Version: 1.0 References: <74b99484-7cd9-4e76-a40f-2b9c844ae99f@gmx.de> In-Reply-To: <74b99484-7cd9-4e76-a40f-2b9c844ae99f@gmx.de> From: Paul Richard Thomas Date: Mon, 10 Jun 2024 07:22:16 +0100 Message-ID: Subject: Re: [Patch, fortran] PR59104 To: Harald Anlauf Cc: "fortran@gcc.gnu.org" , gcc-patches Content-Type: multipart/alternative; boundary="0000000000005e4557061a832c79" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --0000000000005e4557061a832c79 Content-Type: text/plain; charset="UTF-8" Hi Harald, Thanks for the loophole detection! It is obvious now I see it, as is the fix. I'll get on to it as soon as I find some time. Cheers Paul On Sun, 9 Jun 2024 at 21:35, Harald Anlauf wrote: > Hi Paul, > > your approach sounds entirely reasonable. > > But as the following addition to the testcase shows, there seem to > be loopholes left. > > When I add the following to function f: > > integer :: l1(size(y)) > integer :: l2(size(z)) > print *, size (l1), size (l2), size (z) > > I get: > > 0 0 3 > > Expected: > > 2 3 3 > > Can you please check? > > Thanks, > Harald > > > Am 09.06.24 um 17:57 schrieb Paul Richard Thomas: > > Hi All, > > > > I have extended the testcase - see below and have > > s/dependent_decls_2/dependent_decls_2.f90/ in the ChnageLog. > > > > Cheers > > > > Paul > > > > ! { dg-do run } > > ! > > ! Fix for PR59104 in which the dependence on the old style function > result > > ! was not taken into account in the ordering of auto array allocation and > > ! characters with dependent lengths. > > ! > > ! Contributed by Tobias Burnus > > ! > > module m > > implicit none > > integer, parameter :: dp = kind([double precision::]) > > contains > > function f(x) > > integer, intent(in) :: x > > real(dp) f(x/2) > > real(dp) g(x/2) > > integer y(size (f)+1) ! This was the original problem > > integer z(size (f) + size (y)) ! Found in development of the > fix > > integer w(size (f) + size (y) + x) ! Check dummy is OK > > f = 10.0 > > y = 1 ! Stop -Wall from complaining > > z = 1 > > g = 1 > > w = 1 > > if (size (f) .ne. 1) stop 1 > > if (size (g) .ne. 1) stop 2 > > if (size (y) .ne. 2) stop 3 > > if (size (z) .ne. 3) stop 4 > > if (size (w) .ne. 5) stop 5 > > end function f > > function e(x) result(f) > > integer, intent(in) :: x > > real(dp) f(x/2) > > real(dp) g(x/2) > > integer y(size (f)+1) > > integer z(size (f) + size (y)) ! As was this. > > integer w(size (f) + size (y) + x) > > f = 10.0 > > y = 1 > > z = 1 > > g = 1 > > w = 1 > > if (size (f) .ne. 2) stop 6 > > if (size (g) .ne. 2) stop 7 > > if (size (y) .ne. 3) stop 8 > > if (size (z) .ne. 5) stop 9 > > if (size (w) .ne. 9) stop 10 > > end function > > function d(x) ! After fixes to arrays, what was needed was known! > > integer, intent(in) :: x > > character(len = x/2) :: d > > character(len = len (d)) :: line > > character(len = len (d) + len (line)) :: line2 > > character(len = len (d) + len (line) + x) :: line3 > > line = repeat ("a", len (d)) > > line2 = repeat ("b", x) > > line3 = repeat ("c", len (line3)) > > if (len (line2) .ne. x) stop 11 > > if (line3 .ne. "cccccccc") stop 12 > > d = line > > end > > end module m > > > > program p > > use m > > implicit none > > real(dp) y > > > > y = sum (f (2)) > > if (int (y) .ne. 10) stop 13 > > y = sum (e (4)) > > if (int (y) .ne. 20) stop 14 > > if (d (4) .ne. "aa") stop 15 > > end program p > > > > > > > > On Sun, 9 Jun 2024 at 07:14, Paul Richard Thomas < > > paul.richard.thomas@gmail.com> wrote: > > > >> Hi All, > >> > >> The attached fixes a problem that, judging by the comments, has been > >> looked at periodically over the last ten years but just looked to be too > >> fiendishly complicated to fix. This is not in small part because of the > >> confusing ordering of dummies in the tlink chain and the unintuitive > >> placement of all deferred initializations to the front of the init > chain in > >> the wrapped block. > >> > >> The result of the existing ordering is that the initialization code for > >> non-dummy variables that depends on the function result occurs before > any > >> initialization code for the function result itself. The fix ensures > that: > >> (i) These variables are placed correctly in the tlink chain, respecting > >> inter-dependencies; and (ii) The dependent initializations are placed at > >> the end of the wrapped block init chain. The details appear in the > >> comments in the patch. It is entirely possible that a less clunky fix > >> exists but I failed to find it. > >> > >> OK for mainline? > >> > >> Regards > >> > >> Paul > >> > >> > >> > >> > > > > --0000000000005e4557061a832c79--