From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12071 invoked by alias); 3 Sep 2010 17:17:12 -0000 Received: (qmail 12039 invoked by uid 22791); 3 Sep 2010 17:17:11 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from troutmask.apl.washington.edu (HELO troutmask.apl.washington.edu) (128.208.78.105) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 03 Sep 2010 17:17:04 +0000 Received: from troutmask.apl.washington.edu (localhost.apl.washington.edu [127.0.0.1]) by troutmask.apl.washington.edu (8.14.4/8.14.4) with ESMTP id o83HH3Ih091438; Fri, 3 Sep 2010 10:17:03 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.14.4/8.14.4/Submit) id o83HH24r091204; Fri, 3 Sep 2010 10:17:02 -0700 (PDT) (envelope-from sgk) Date: Fri, 03 Sep 2010 17:33:00 -0000 From: Steve Kargl To: Tobias Burnus Cc: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH] fortran/45495 -- optional dummy args cannot not be in restricted expressions Message-ID: <20100903171702.GA60110@troutmask.apl.washington.edu> References: <20100902214401.GA64816@troutmask.apl.washington.edu> <4C8091FF.4000802@net-b.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4C8091FF.4000802@net-b.de> User-Agent: Mutt/1.4.2.3i 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 X-SW-Source: 2010-09/txt/msg00276.txt.bz2 On Fri, Sep 03, 2010 at 08:13:19AM +0200, Tobias Burnus wrote: > Steve Kargl wrote: > >C710 (R729) The scalar-int-expr shall be a restricted expression. > > (2) An object designator with a base object that is a dummy > > argument that has neither the OPTIONAL nor the INTENT(OUT) > > attribute, > > > >The attach patch enforces the above restriction. It has been > >built and regression tested on x86_64-*-freebsd. OK for trunk? > > + if (not_restricted == 0 > + && ap->expr->expr_type == EXPR_VARIABLE > + && ap->expr->symtree->n.sym->attr.optional > + && ap->expr->symtree->n.sym->attr.dummy) > > > The "sym.dummy" part is not needed (but can stay). However, can you add > you add a check whether the dummy is INTENT(OUT)? The following is > invalid and not detected: > > subroutine f(a, str) > integer, intent(out) :: a > character(*) :: str > character(len=len(str(1:a))+1) :: b > end subroutine > > With that change and test case, the patch is OK. > > Thanks for the patch and digging for the constraint! > > Tobias > Including a check for intent(out) causes FAIL: gfortran.dg/spec_expr_2.f90 -O (test for excess errors) FAIL: gfortran.fortran-torture/compile/inquiry_1.f90, -O2 -fomit-frame-pointer troutmask:kargl[203] cat spec_expr_2.f90 ! { dg-do compile } ! PR 22273: Allow INTENT(OUT) dummy:s as arguments to LEN() in specification ! expr:s subroutine lecligne (ligne) character(len=*), intent(out) :: ligne character(len=len(ligne)) :: comment end subroutine lecligne troutmask:kargl[207] cat gfortran.fortran-torture/compile/inquiry_1.f90 ! Check that inquiry functions are allowed as specification expressions. subroutine inquiry(x1) implicit none real, dimension(1:), intent(out) :: x1 real, dimension(1:size(x1)) :: x3 x3 = 0 x1 = x3 end subroutine Unfortunately, Sec 7.1.6 in F2003 is a twisted piece of English. Here's the relevant parts 7.1.6 Specification expression A specification expression is an expression with limitations that make it suitable for use in specifications such as length type parameters (C501) and array bounds (R512, R513). R729 specification-expr is scalar-int-expr C710 (R729) The scalar-int-expr shall be a restricted expression. A restricted expression is an expression in which each operation is intrinsic and each primary is ... (2) An object designator with a base object that is a dummy argument that has neither the OPTIONAL nor the INTENT(OUT) attribute, ... (7) A specification inquiry where each designator or function argument is (a) a restricted expression or (b) a variable whose properties inquired about are not (i) dependent on the upper bound of the last dimension of an assumed-size array, ... (iii) defined by an expression that is not a restricted expression. A specification inquiry is a reference to (1) an array inquiry function (13.5.7), (2) the bit inquiry function BIT SIZE, (3) the character inquiry function LEN, (4) the kind inquiry function KIND, What is throwing me at the moment is (7)(b) and the double negative in (iii). Anyway, I'm confident that my original optional patch is correct. Inclusion of intent(out) seems to go against (7)(b)(iii) in that the property being inquired about is the length of the string. -- Steve