Message ID | 20100902214401.GA64816@troutmask.apl.washington.edu |
---|---|
State | New |
Headers | show |
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 > 2010-09-02 Steven G. Kargl<kargl@gcc.gnu.org> > > PR fortran/45495 > * gfortran.dg/dummy_optional_arg.f90: New test. > > 2010-09-02 Steven G. Kargl<kargl@gcc.gnu.org> > > PR fortran/45495 > * fortran/expr.c (check_inquiry): Optional dummy argument are not > permitted in a restricted expression. >
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.
On Thu, Sep 2, 2010 at 2:44 PM, Steve Kargl <sgk@troutmask.apl.washington.edu> wrote: > 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, > > The attach patch enforces the above restriction. It has been > built and regression tested on x86_64-*-freebsd. OK for trunk? > > > 2010-09-02 Steven G. Kargl <kargl@gcc.gnu.org> > > PR fortran/45495 > * gfortran.dg/dummy_optional_arg.f90: New test. > > 2010-09-02 Steven G. Kargl <kargl@gcc.gnu.org> > > PR fortran/45495 > * fortran/expr.c (check_inquiry): Optional dummy argument are not > permitted in a restricted expression. > The new test fails on Linux/x86: /export/gnu/import/svn/gcc-test/src-trunk/gcc/testsuite/gfortran.dg/dummy_procedure_1.f90:39.10:^M ^M call s1(i) ! { dg-error "Expected a procedure for argument" }^M 1^M Error: Expected a procedure for argument 'f' at (1)^M /export/gnu/import/svn/gcc-test/src-trunk/gcc/testsuite/gfortran.dg/dummy_procedure_1.f90:43.10:^M ^M call s1(z) ! { dg-error "Expected a procedure for argument" }^M 1^M Error: Expected a procedure for argument 'f' at (1)^M /export/gnu/import/svn/gcc-test/src-trunk/gcc/testsuite/gfortran.dg/dummy_procedure_1.f90:44.10:^M ^M call s2(x) ! { dg-error "Invalid procedure argument" }^M 1^M Error: Invalid procedure argument at (1)^M PASS: gfortran.dg/dummy_procedure_1.f90 -O (test for errors, line 39) FAIL: gfortran.dg/dummy_procedure_1.f90 -O (test for errors, line 40)
On Fri, Sep 03, 2010 at 11:03:22AM -0700, H.J. Lu wrote: > > ? ? ? ?PR fortran/45495 > > ? ? ? ?* gfortran.dg/dummy_optional_arg.f90: New test. > > > > 2010-09-02 ?Steven G. Kargl ?<kargl@gcc.gnu.org> > > > > ? ? ? ?PR fortran/45495 > > ? ? ? ?* fortran/expr.c (check_inquiry): Optional dummy argument are not > > ? ? ? ?permitted in a restricted expression. > > > > The new test fails on Linux/x86: (snip) > PASS: gfortran.dg/dummy_procedure_1.f90 -O (test for errors, line 39) > FAIL: gfortran.dg/dummy_procedure_1.f90 -O (test for errors, line 40) Wrong thread. I haven't committed this patch, yet.
Index: gcc/testsuite/gfortran.dg/dummy_optional_arg.f90 =================================================================== --- gcc/testsuite/gfortran.dg/dummy_optional_arg.f90 (revision 0) +++ gcc/testsuite/gfortran.dg/dummy_optional_arg.f90 (revision 0) @@ -0,0 +1,11 @@ +! { dg-do compile } +! PR fortran/45495 +! +! Code originally submitted by Philip Mason <pmason at ricardo dot com> +! +function jack(aa) + character(len=*), intent(in) :: aa + optional :: aa + character(len=len(aa)+1) :: jack ! { dg-error "cannot be OPTIONAL" } + jack = '' +end function jack Index: gcc/fortran/expr.c =================================================================== --- gcc/fortran/expr.c (revision 163791) +++ gcc/fortran/expr.c (working copy) @@ -2305,6 +2305,12 @@ check_inquiry (gfc_expr *e, int not_rest && ap->expr->expr_type != EXPR_VARIABLE && check_restricted (ap->expr) == FAILURE) return MATCH_ERROR; + + if (not_restricted == 0 + && ap->expr->expr_type == EXPR_VARIABLE + && ap->expr->symtree->n.sym->attr.optional + && ap->expr->symtree->n.sym->attr.dummy) + return MATCH_NO; } return MATCH_YES;