public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [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
* 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

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-02 21:45 [PATCH] fortran/45495 -- optional dummy args cannot not be in restricted expressions 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
2010-09-03 17:46 Tobias Burnus
2010-09-03 19:52 ` Steve Kargl
2010-09-03 20:51   ` 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).