This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch, fortran] PR Detect same values in vector expression subscripts
- From: Mikael Morin <mikael dot morin at sfr dot fr>
- To: Thomas Koenig <tkoenig at netcologne dot de>
- Cc: "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 28 Jul 2013 18:35:57 +0200
- Subject: Re: [patch, fortran] PR Detect same values in vector expression subscripts
- References: <51F5154C dot 20604 at netcologne dot de>
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