Patchwork [Fortran,OOP] PR 56266: ICE on invalid in gfc_match_varspec

login
register
mail settings
Submitter Mikael Morin
Date April 15, 2013, 5:36 p.m.
Message ID <516C3AA0.4020302@sfr.fr>
Download mbox | patch
Permalink /patch/236662/
State New
Headers show

Comments

Mikael Morin - April 15, 2013, 5:36 p.m.
Le 13/04/2013 17:44, Mikael Morin a écrit :
> Indeed, that's invalid:
> 
And then, the call to gfc_match_varspec shouldn't be there in the first
place.  I'll test the following later.
Janus Weil - April 15, 2013, 7 p.m.
>> Indeed, that's invalid:
>>
> And then, the call to gfc_match_varspec shouldn't be there in the first
> place.  I'll test the following later.

It seems like the parts you're removing have essentially been there
since day zero. Would be interesting to know if (and where) your patch
fails.

Cheers,
Janus
Janus Weil - April 16, 2013, 11:41 a.m.
Hi Mikael,

>> And then, the call to gfc_match_varspec shouldn't be there in the first
>> place.  I'll test the following later.
>
> It seems like the parts you're removing have essentially been there
> since day zero. Would be interesting to know if (and where) your patch
> fails.

actually I just tried it myself, and I did not see any failures in the
testsuite. So in fact it seems like it might be ok to remove it.
However, one should carefully check the standard, in order to make
sure that this is really invalid in all cases, and that the
"gfc_match_varspec" is not needed for some corner case, which is not
covered by the testsuite.

As the comment says which the patch is removing, the gfc_match_varspec
should be relevant for cases like this:

print *,char_func()(1:3)
print *,array_func()(2)
print *,derived_type_func()%comp

Are we sure that all of these are actually invalid? (At least they are
rejected by gfortran.) Or are there other cases which would be valid?

Cheers,
Janus
Tobias Burnus - April 16, 2013, 11:48 a.m.
Janus Weil wrote:
> As the comment says which the patch is removing, the gfc_match_varspec
> should be relevant for cases like this:
>
> print *,char_func()(1:3)
> print *,array_func()(2)
> print *,derived_type_func()%comp
>
> Are we sure that all of these are actually invalid? (At least they are
> rejected by gfortran.) Or are there other cases which would be valid?

They are all invalid. The only exception is that a function itself is 
regarded as variable (if it returns a pointer):

    f() = 5

That's a new Fortran 2008 feature, which caused quite some trouble with 
user-defined operators, e.g. something like:

   123 .foo. 5 = ...

where "123" could be an argument (binary operator) or a label (+plus 
unary operator). (When we implement it, we should do some careful 
interpretation-request reading.)

However, I think that doesn't affect the code you are removing. 
(Disclaimer: I haven't looked at the actual patch.)

Tobias

Patch

Index: primary.c
===================================================================
--- primary.c	(révision 197949)
+++ primary.c	(copie de travail)
@@ -1954,11 +1954,10 @@  gfc_match_varspec (gfc_expr *primary, int equiv_fl
 
 	  gcc_assert (!tail || !tail->next);
 
-	  if (!(primary->expr_type == EXPR_VARIABLE
-		|| (primary->expr_type == EXPR_STRUCTURE
-		    && primary->symtree && primary->symtree->n.sym
-		    && primary->symtree->n.sym->attr.flavor)))
-	    return MATCH_ERROR;
+	  gcc_assert (primary->expr_type == EXPR_VARIABLE
+		      || (primary->expr_type == EXPR_STRUCTURE
+		          && primary->symtree && primary->symtree->n.sym
+		          && primary->symtree->n.sym->attr.flavor));
 
 	  if (tbp->n.tb->is_generic)
 	    tbp_sym = NULL;
@@ -3102,18 +3101,8 @@  gfc_match_rvalue (gfc_expr **result)
 	gfc_error ("Missing argument list in function '%s' at %C", sym->name);
 
       if (m != MATCH_YES)
-	{
-	  m = MATCH_ERROR;
-	  break;
-	}
+	m = MATCH_ERROR;
 
-      /* If our new function returns a character, array or structure
-	 type, it might have subsequent references.  */
-
-      m = gfc_match_varspec (e, 0, false, true);
-      if (m == MATCH_NO)
-	m = MATCH_YES;
-
       break;
 
     generic_function: