[Bug libfortran/31726] minloc/maxloc: wrong results with empty array (F2003 only)

burnus at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Fri Apr 27 14:59:00 GMT 2007



------- Comment #3 from burnus at gcc dot gnu dot org  2007-04-27 15:59 -------
Patch. Dump looks ok. Needs some testcases plus checking of the library
version.

Index: trans-intrinsic.c
===================================================================
--- trans-intrinsic.c   (Revision 124216)
+++ trans-intrinsic.c   (Arbeitskopie)
@@ -2007,10 +2007,10 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * s

   gcc_assert (loop.dimen == 1);

-  /* Initialize the position to zero, following Fortran 2003.  We are free
-     to do this because Fortran 95 allows the result of an entirely false
-     mask to be processor dependent.  */
-  gfc_add_modify_expr (&loop.pre, pos, gfc_index_zero_node);
+  /* For zero-sized arrays or if the mask is .false. for every element,
+     zero needs to be returned according to the Fortran 2003 standard.
+     As this number is always incremented by one, it is initialized to -1.  */
+  gfc_add_modify_expr (&loop.pre, pos, build_int_cst (TREE_TYPE(pos), -1));

   gfc_mark_ss_chain_used (arrayss, 1);
   if (maskss)
@@ -2084,7 +2084,7 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * s
         the pos variable the same way as above.  */

       gfc_init_block (&elseblock);
-      gfc_add_modify_expr (&elseblock, pos, gfc_index_zero_node);
+      gfc_add_modify_expr (&elseblock, pos, build_int_cst (TREE_TYPE(pos),
-1));
       elsetmp = gfc_finish_block (&elseblock);

       tmp = build3_v (COND_EXPR, maskse.expr, tmp, elsetmp);


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31726



More information about the Gcc-bugs mailing list