trans-intrinsic.c (gfc_conv_intrinsic_minmaxloc): For integer maxloc initialize limit...
authorJakub Jelinek <jakub@redhat.com>
Sat, 4 Jul 2009 17:20:46 +0000 (19:20 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 4 Jul 2009 17:20:46 +0000 (19:20 +0200)
* 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.

From-SVN: r149236

gcc/fortran/ChangeLog
gcc/fortran/trans-intrinsic.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/maxloc_1.f90 [new file with mode: 0644]

index c1093455c71e5afc2066d2cdfb7267f990854170..6b66cbd89be85ca54e11fbe064fbeae6c3cf693f 100644 (file)
@@ -1,3 +1,8 @@
+2009-07-04  Jakub Jelinek  <jakub@redhat.com>
+
+       * trans-intrinsic.c (gfc_conv_intrinsic_minmaxloc): For integer
+       maxloc initialize limit to -huge-1 rather than just -huge.
+
 2009-07-04  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/40593
index 21694e41b36fb71dc428b7a2db44f08b0832b849..dd3b3cdff7b4dfbe1d3fcbdde230afda8b878fde 100644 (file)
@@ -2190,12 +2190,12 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * expr, enum tree_code op)
      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);
index 18f515c5bb2b81bcfa8999a17e20337552ef9e70..1582c882dac496b0069aacf66e8e8f2cf2fabe3e 100644 (file)
@@ -1,3 +1,7 @@
+2009-07-04  Jakub Jelinek  <jakub@redhat.com>
+
+       * gfortran.dg/maxloc_1.f90: New test.
+
 2009-07-04  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/40593
diff --git a/gcc/testsuite/gfortran.dg/maxloc_1.f90 b/gcc/testsuite/gfortran.dg/maxloc_1.f90
new file mode 100644 (file)
index 0000000..41115ed
--- /dev/null
@@ -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