This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[PATCH] Fix integer maxloc


Hi!

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?

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


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