This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix integer maxloc
- From: Tobias Burnus <burnus at net-b dot de>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org
- Date: Fri, 03 Jul 2009 20:27:40 +0200
- Subject: Re: [PATCH] Fix integer maxloc
- References: <20090703153207.GW4462@tyan-ft48-01.lab.bos.redhat.com>
Jakub Jelinek wrote:
> While gfc_conv_intrinsic_minmaxval computes limit = -HUGE-1 for
> BT_INTEGER maxloc correctly, gfc_conv_intrinsic_minmaxloc does not, although
> it computes -HUGE - 1, it assigns it to limit already when it is -HUGE.
>
> Ok for trunk/4.4?
>
OK thanks for the patch!
Tobias
> 2009-07-03 Jakub Jelinek <jakub@redhat.com>
>
> * trans-intrinsic.c (gfc_conv_intrinsic_minmaxloc): For integer
> maxloc initialize limit to -huge-1 rather than just -huge.
>
> * gfortran.dg/maxloc_1.f90: New test.
>
> --- gcc/fortran/trans-intrinsic.c.jj 2009-06-30 13:10:18.000000000 +0200
> +++ gcc/fortran/trans-intrinsic.c 2009-07-03 17:09:02.000000000 +0200
> @@ -2190,12 +2190,12 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * s
> possible value is HUGE in both cases. */
> if (op == GT_EXPR)
> tmp = fold_build1 (NEGATE_EXPR, TREE_TYPE (tmp), tmp);
> - gfc_add_modify (&se->pre, limit, tmp);
> -
> if (op == GT_EXPR && expr->ts.type == BT_INTEGER)
> tmp = fold_build2 (MINUS_EXPR, TREE_TYPE (tmp), tmp,
> build_int_cst (type, 1));
>
> + gfc_add_modify (&se->pre, limit, tmp);
> +
> /* Initialize the scalarizer. */
> gfc_init_loopinfo (&loop);
> gfc_add_ss_to_loop (&loop, arrayss);
> --- gcc/testsuite/gfortran.dg/maxloc_1.f90.jj 2009-07-03 17:18:56.000000000 +0200
> +++ gcc/testsuite/gfortran.dg/maxloc_1.f90 2009-07-03 17:26:02.000000000 +0200
> @@ -0,0 +1,14 @@
> +! { dg-do run }
> + integer :: a(3), n
> + a(1) = -huge(n)
> + a(2) = -huge(n)
> + a(3) = -huge(n)
> + a(1) = a(1) - 1
> + a(2) = a(2) - 1
> + a(3) = a(3) - 1
> + n = maxloc (a, dim = 1)
> + if (n .ne. 1) call abort
> + a(2) = -huge(n)
> + n = maxloc (a, dim = 1)
> + if (n .ne. 2) call abort
> +end
>
> Jakub
>
>