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]

[patch, fortran] PR35994 [4.3/4.4 regression] MAXLOC and MINLOC off by one with mask


Hi,

Starting from FX original patch given in the PR which did not quite work and applying some intuitive logic, I arrived at the following patch which solves the problem,

I will commit as obvious or at least invoke the mutually understood clause. It is certainly simple.

Regression tested on x86-64. Two new test cases.

Jerry

2008-04-23  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
	    Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>

	PR fortran/35994
	* trans-instrinsic.c (gfc_conv_intrinsic_minmaxloc): Correctly adjust
	loop counter offset.
Index: trans-intrinsic.c
===================================================================
--- trans-intrinsic.c	(revision 134614)
+++ trans-intrinsic.c	(working copy)
@@ -2171,11 +2171,12 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * s
 
   /* Remember where we are.  An offset must be added to the loop
      counter to obtain the required position.  */
-  if (loop.temp_dim)
-    tmp = build_int_cst (gfc_array_index_type, 1);
+  if (loop.from[0])
+    tmp = fold_build2 (MINUS_EXPR, gfc_array_index_type,
+		       gfc_index_one_node, loop.from[0]);
   else
-    tmp =fold_build2 (MINUS_EXPR, gfc_array_index_type,
-			 gfc_index_one_node, loop.from[0]);
+    tmp = build_int_cst (gfc_array_index_type, 1);
+  
   gfc_add_modify_expr (&block, offset, tmp);
 
   tmp = fold_build2 (PLUS_EXPR, TREE_TYPE (pos),
! { dg-do run }
! PR35994 [4.3/4.4 regression] MAXLOC and MINLOC off by one with mask
program GA4076
  REAL DDA(100)
  dda = (/(J1,J1=1,100)/)
  IDS = MAXLOC(DDA,1)
  if (ids.ne.100) call abort  !expect 100
  
  IDS = MAXLOC(DDA,1, (/(J1,J1=1,100)/) > 50)
  if (ids.ne.100) call abort  !expect 100

  IDS = minLOC(DDA,1)
  if (ids.ne.1) call abort  !expect 1

  IDS = MinLOC(DDA,1, (/(J1,J1=1,100)/) > 50)
  if (ids.ne.51) call abort !expect 51

END
! { dg-do run }
! PR35994 [4.3/4.4 regression] MAXLOC and MINLOC off by one with mask
  REAL DDA(5:104)
  dda = (/(J1,J1=1,100)/)

  IDS = MAXLOC(DDA,1)
  if (ids.ne.100) call abort  !expect 100
  IDS = MAXLOC(DDA,1, (/(J1,J1=1,100)/) > 50)
  if (ids.ne.100) call abort  !expect 100

  END

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