This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch, fortran] PR Detect same values in vector expression subscripts


Le 28/07/2013 14:57, Thomas Koenig a écrit :
> Hello world,
> 
> this patch yields an error for identical values in vector expression
> subscripts.  The algorithm is O(n**2) because
> 
> a) It would be impossible to detect a([i,i]) otherwise
> b) This is not likely to be a performance bottleneck because
>    people don't use large vector indices.
> 
> (as noted by the different comments in the PR).
> 
> Regression-tested.  OK for trunk?
> 
>     Thomas
> 

> 
> Index: expr.c
> ===================================================================
> --- expr.c	(Revision 200743)
> +++ expr.c	(Arbeitskopie)
> @@ -4922,5 +4924,54 @@ gfc_check_vardef_context (gfc_expr* e, bool pointe
>  	}
>      }
>  
> -  return true;
> +  /* Check for same value in vector expression subscript.  */
> +  retval = true;
> +
> +  if (e->rank > 0)
> +    for (ref = e->ref; ref != NULL; ref = ref->next)
> +      if (ref->type == REF_ARRAY && ref->u.ar.type == AR_SECTION)
> +	for (i = 0; i<e->rank; i++)
> +	  if (ref->u.ar.dimen_type[i] == DIMEN_VECTOR)

I think it should be:
> 	for (i = 0; i < GFC_MAX_DIMENSIONS; i++)

otherwise, I'm afraid it will silently disregard array references of the
form array(1, (/ ... /))
I haven't tested though.
Otherwise looks good.

Mikael


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]