public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PATCH] fortran/45495 -- optional dummy args cannot not be in restricted expressions
@ 2010-09-03 17:46 Tobias Burnus
  2010-09-03 19:52 ` Steve Kargl
  0 siblings, 1 reply; 8+ messages in thread
From: Tobias Burnus @ 2010-09-03 17:46 UTC (permalink / raw)
  To: Steve Kargl, fortran, gcc-patches

Steve Kargl wrote:
> 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

OK, a simple check won't do. But I believe my test case is still invalid:

  character(len=len(str(1:a))+1) :: b

The issue is that "a" is not a string whose length is queried but that the
value of "a" itself is used - which is undefined if "a" is INTENT(OUT).


> Anyway, I'm confident that my original optional patch is correct.

I concur. Thus, go ahead with that part.


> Inclusion of intent(out) seems to go against (7)(b)(iii) in that
> the property being inquired about is the length of the string.

To quote only the relevant part of F2008's "7.1.11 Specification expression"
(with cutting out irrelevant parts and adding a comment in brackets):

"A restricted expression is an expression in which each primary is
 a specification inquiry [such as "LEN"] where each designator or function
 argument is a restricted expression or a variable whose properties inquired
 about are not defined by an expression that is not a restricted expression"

I think the standard is pretty clear:
While "len(str)" and "str" are restricted expressions, "str(1:a)" is not;
thus, one should allow len(str) - even if "str" is INTENT(OUT) - but one
should reject "str(1:a)" - if "a" is INTENT(OUT).

Tobias

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] fortran/45495 -- optional dummy args cannot not be in restricted expressions
  2010-09-03 17:46 [PATCH] fortran/45495 -- optional dummy args cannot not be in restricted expressions Tobias Burnus
@ 2010-09-03 19:52 ` Steve Kargl
  2010-09-03 20:51   ` Steve Kargl
  0 siblings, 1 reply; 8+ messages in thread
From: Steve Kargl @ 2010-09-03 19:52 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: fortran, gcc-patches

On Fri, Sep 03, 2010 at 07:44:36PM +0200, Tobias Burnus wrote:
> Steve Kargl wrote:
> > 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
> 
> OK, a simple check won't do. But I believe my test case is still invalid:
> 
>   character(len=len(str(1:a))+1) :: b
> 
> The issue is that "a" is not a string whose length is queried but that the
> value of "a" itself is used - which is undefined if "a" is INTENT(OUT).
> 
> 
> > Anyway, I'm confident that my original optional patch is correct.
> 
> I concur. Thus, go ahead with that part.
> 
> 
> > Inclusion of intent(out) seems to go against (7)(b)(iii) in that
> > the property being inquired about is the length of the string.
> 
> To quote only the relevant part of F2008's "7.1.11 Specification expression"
> (with cutting out irrelevant parts and adding a comment in brackets):
> 
> "A restricted expression is an expression in which each primary is
>  a specification inquiry [such as "LEN"] where each designator or function
>  argument is a restricted expression or a variable whose properties inquired
>  about are not defined by an expression that is not a restricted expression"
> 
> I think the standard is pretty clear:
> While "len(str)" and "str" are restricted expressions, "str(1:a)" is not;
> thus, one should allow len(str) - even if "str" is INTENT(OUT) - but one
> should reject "str(1:a)" - if "a" is INTENT(OUT).
> 

I may have a fix the intent(out) issue as well.  I testing it now.

-- 
Steve

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] fortran/45495 -- optional dummy args cannot not be in restricted expressions
  2010-09-03 19:52 ` Steve Kargl
@ 2010-09-03 20:51   ` Steve Kargl
  0 siblings, 0 replies; 8+ messages in thread
From: Steve Kargl @ 2010-09-03 20:51 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: fortran, gcc-patches

On Fri, Sep 03, 2010 at 12:13:39PM -0700, Steve Kargl wrote:
> 
> I may have a fix the intent(out) issue as well.  I testing it now.
> 

I take it back.  I intend to commit the OPTIONAL portion of
the patch and open a PR based on your code example.

-- 
Steve

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] fortran/45495 -- optional dummy args cannot not be in restricted expressions
  2010-09-03 18:10 ` H.J. Lu
@ 2010-09-03 18:35   ` Steve Kargl
  0 siblings, 0 replies; 8+ messages in thread
From: Steve Kargl @ 2010-09-03 18:35 UTC (permalink / raw)
  To: H.J. Lu; +Cc: fortran, gcc-patches

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.

-- 
Steve

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] fortran/45495 -- optional dummy args cannot not be in restricted expressions
  2010-09-02 21:45 Steve Kargl
  2010-09-03  6:36 ` Tobias Burnus
@ 2010-09-03 18:10 ` H.J. Lu
  2010-09-03 18:35   ` Steve Kargl
  1 sibling, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2010-09-03 18:10 UTC (permalink / raw)
  To: Steve Kargl; +Cc: fortran, gcc-patches

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)


-- 
H.J.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] fortran/45495 -- optional dummy args cannot not be in restricted expressions
  2010-09-03  6:36 ` Tobias Burnus
@ 2010-09-03 17:33   ` Steve Kargl
  0 siblings, 0 replies; 8+ messages in thread
From: Steve Kargl @ 2010-09-03 17:33 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: fortran, gcc-patches

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] fortran/45495 -- optional dummy args cannot not be in restricted expressions
  2010-09-02 21:45 Steve Kargl
@ 2010-09-03  6:36 ` Tobias Burnus
  2010-09-03 17:33   ` Steve Kargl
  2010-09-03 18:10 ` H.J. Lu
  1 sibling, 1 reply; 8+ messages in thread
From: Tobias Burnus @ 2010-09-03  6:36 UTC (permalink / raw)
  To: Steve Kargl; +Cc: fortran, gcc-patches

  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.
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] fortran/45495 -- optional dummy args cannot not be in restricted expressions
@ 2010-09-02 21:45 Steve Kargl
  2010-09-03  6:36 ` Tobias Burnus
  2010-09-03 18:10 ` H.J. Lu
  0 siblings, 2 replies; 8+ messages in thread
From: Steve Kargl @ 2010-09-02 21:45 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 984 bytes --]

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.

-- 
Steve

[-- Attachment #2: pr45495.diff --]
[-- Type: text/x-diff, Size: 1182 bytes --]

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;

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-09-03 20:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-03 17:46 [PATCH] fortran/45495 -- optional dummy args cannot not be in restricted expressions Tobias Burnus
2010-09-03 19:52 ` Steve Kargl
2010-09-03 20:51   ` Steve Kargl
  -- strict thread matches above, loose matches on Subject: below --
2010-09-02 21:45 Steve Kargl
2010-09-03  6:36 ` Tobias Burnus
2010-09-03 17:33   ` Steve Kargl
2010-09-03 18:10 ` H.J. Lu
2010-09-03 18:35   ` Steve Kargl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).