From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id 432C33858D20; Sun, 9 Jun 2024 15:57:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 432C33858D20 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 432C33858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1036 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717948669; cv=none; b=dU+VXOZ4GFesp8SfM4Ozu+luKs8VzdDDVUaWdEDSAev3K2cgLZaF971CwbCVBw5kxryaOFL0NphToy3ie9/uzlKvbgQDLYwTfGpiFiMgrT39+OLJH8P2l96PFR1sFjGNcXeE3WCy+BYAdbPiEXNf1sAxvwkkzr40YZ9yfWnSEKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717948669; c=relaxed/simple; bh=v8YfEbG8lautiLQ9G12zV0LEidChY/AiWVC3amFD+ZA=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=wGALjm0EfdpUEcjJ+DwALWrYq+KYO5CfpRhYIqEGEMtpd4HKvPpg6VqWqrkgsd6ZcrhU6k1mCMgRSW6mzYHK15ieeyJfvxqkgwr+KSwOnHKb5+ZsXLr6bimG6Ks2lr+HXkw2vYuQkP8WOmBCzlREM6qkG5uZ4O2bfnLIH7gED/g= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-2c2c6277ef3so1563864a91.3; Sun, 09 Jun 2024 08:57:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717948666; x=1718553466; darn=gcc.gnu.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=EmxfN4Orio9BkN84aTsB6Lk7Fm4MUylK1Ck0iRai4dU=; b=ENr35QWZrwv05z6nRhntJE89e75YYsTWOJ+CSBdCSeXIbI1zxGZneW8ZiYzeDMIeJn A6fgUsVWCP+7TJ7vk6uvE+XcA5hRiX2BZj95cXoV0Y6qY+Ukf3F9TGU5xsVlu3uc7ABS jxeNwpyPhUFUJzPQ6yzo5gBwLV9Uf5OaHvlWxKE3JyKYr3aW58QqOyXraMls3lsEY8qs IbhTq10peuBft5waRJvxf7kR+oqcGyYnxTwgfpsxr8o7sq8PAkqEX/AMBmivVkvUIlcq ETcjVU4zVybAHw5n0jDzPsEo1kk3qT83Nx98fSWuqU8XISELilQL479zscBaK90oS8Yq eoNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717948666; x=1718553466; h=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=EmxfN4Orio9BkN84aTsB6Lk7Fm4MUylK1Ck0iRai4dU=; b=bqV8KIp6UxUduUBsaqJcGplPdgSNAeOKOSZKPtUlVpiSAZcxMUA6t/brIhyheRPa/E nrH2Wo4uz2VSYzrCvVUhA7MLSiwDVRyzY49NMRscCA6YC7cXnudDEUvj600OZkKtTL1W 9cwfd7Ho4BTabIl/gUCoot/Rk5JQOYeZKpzcdOBVNNDEOb9D9eNkPbSb95rBapFvYIeh GTFY5GQn2pgba7qP3SGVYTI7fkgyM+1x/vBGQmyZruee3DNzlbSz5tEs4VOmWvp+5b3l Hz9j6ep7TAbNW1kVyAOpEeonHsYuPcEuz3MAZBw8sMRYE4yUE9lBDiHo/CzFqC1V3oej 7RDg== X-Forwarded-Encrypted: i=1; AJvYcCUct4sbkqMNX9E2O1hwTTeRGNB8McSCXZYf+BBARJZP2qz1ytUDiM0ekDUR70rsc8ZeQSg+GO88emubIsqdC/hyNK1w9qDtmQ== X-Gm-Message-State: AOJu0Yx0q/3CZ1RyUi9nZitai4KIbl11GpmuCjRfA4+EEBL+MuwoyjoW GoH5NBJgu89MrcnLiFY69i1+qzBJD30ZRQH6cyObCRhV7QEquwh94ZDboywFsATgue6MeUZ9oQA Mwm9O0QnLb4nn3xWCI35gTR1pkkDlxqoXabY= X-Google-Smtp-Source: AGHT+IH0Uko3BglQxDoUpGOcEJ7TAnaVVhu00KG+fxndmYN3QbELddSGCgRI1KGKj+oLDbSi7bcgYaqfVjjY1heqVcQ= X-Received: by 2002:a17:90a:4a95:b0:2c2:d468:76df with SMTP id 98e67ed59e1d1-2c2d4687a71mr4662157a91.31.1717948665534; Sun, 09 Jun 2024 08:57:45 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Paul Richard Thomas Date: Sun, 9 Jun 2024 16:57:34 +0100 Message-ID: Subject: Re: [Patch, fortran] PR59104 To: "fortran@gcc.gnu.org" , gcc-patches Content-Type: multipart/alternative; boundary="000000000000f3a01a061a77172d" X-Spam-Status: No, score=-1.2 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: --000000000000f3a01a061a77172d Content-Type: text/plain; charset="UTF-8" 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 > > > > --000000000000f3a01a061a77172d--