From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) by sourceware.org (Postfix) with ESMTPS id 7963D3858D33 for ; Sun, 20 Nov 2022 23:31:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7963D3858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=troutmask.apl.washington.edu Authentication-Results: sourceware.org; spf=none smtp.mailfrom=troutmask.apl.washington.edu Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.16.1/8.16.1) with ESMTPS id 2AKNV4Rq093414 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO) for ; Sun, 20 Nov 2022 15:31:04 -0800 (PST) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.16.1/8.16.1/Submit) id 2AKNV4Eo093413 for fortran@gcc.gnu.org; Sun, 20 Nov 2022 15:31:04 -0800 (PST) (envelope-from sgk) Date: Sun, 20 Nov 2022 15:31:04 -0800 From: Steve Kargl To: Harald Anlauf via Fortran Subject: Re: typespec in forall and implied-do Message-ID: Reply-To: sgk@troutmask.apl.washington.edu References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_NONE,SPF_NONE,TXREP 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: On Sun, Nov 20, 2022 at 10:28:40PM +0100, Harald Anlauf via Fortran wrote: > Steve, > > for unknown reasons I cannot reply to your mail on gmane, > so trying directly via mailing list. > > I tried your patch, and it works on the supplied testcases. > > However, there is a scoping issue for the declaration of the > index variable, as can be seen by the following variation: > > program foo > use iso_fortran_env, only : k => real_kinds > implicit none > integer, parameter :: n = size(k) > integer(8) :: i > !!$ integer, parameter :: & > !!$ & p(n) = [(precision(real(1.,k(i))), integer :: i = 1, n)] > integer, parameter :: & > & q(n) = [(kind(i), integer(2) :: i = 1, n)] > integer, parameter :: & > & r(n) = [(storage_size(i), integer(1) :: i = 1, n)] > !!$ print *, p > print *, q > print *, r > end program foo > > After your patch, gfortran prints: > > 8 8 8 8 > 64 64 64 64 > > This suggests that the integer kind is taken from the host decl, > which is kind=8, and not the local one (2 or 1). > > Crayftn (which chokes on your original testcase): > > 3*2 > 3*8 > > This is what I expect. > > Intel doesn't accept storage_size() here, which is a bug. > Commenting the uses of array r, I then get: > > 2 2 2 > > At least this agrees with Cray. > > Can you have another look at this? > Unfortunately, gfortran does not define a namespace for an implied-do index and uses a kludge by adding the attr.implied_index attribute to the symbol. Unfortunately**2, gfortran uses gfc_match_iterator for all places that 'i = start, stop [,step]' and there is no way to know if what is being parsed. With the introduction of an optional typespec, there is no easy way to deal with it in a clean way. Things get messy quickly when trying to deal with implicit typing and explicitly typed symbols. So, if the implied-do index has previously been typed such as integer(8) i print *, (i, integer(2) i=1, 3) the integer(2) is ignored. That's this part of the gfc_match_iterator diff + if (seen_ts && var->ts.type == BT_UNKNOWN) + { + var->ts.type = ts.type; + var->ts.kind = ts.kind; + var->symtree->n.sym->ts.type = ts.type; + var->symtree->n.sym->ts.kind = ts.kind; + } Perhaps, a better way would be to simply create a shadow symbol if a typespec appears in an iterator print *, (i, integer i=1,3) would become print *, (_i, integer _i=1,3) The issue is then that implied-do object list needs to be walked and all occurrence of i must be replaced with _i. -- Steve