This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libfortran/31726] minloc/maxloc: wrong results with empty array (F2003 only)
- From: "pault at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 21 Jun 2007 18:14:42 -0000
- Subject: [Bug libfortran/31726] minloc/maxloc: wrong results with empty array (F2003 only)
- References: <bug-31726-13648@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #7 from pault at gcc dot gnu dot org 2007-06-21 18:14 -------
This fixes Tobias' testcase of comment #4. Note that it is a diff relative to
the patch for 32298. I'll resubmit the latter in this new form.
Paul
Index: gcc/fortran/trans-intrinsic.c
===================================================================
*** gcc/fortran/trans-intrinsic.c (révision 125706)
--- gcc/fortran/trans-intrinsic.c (copie de travail)
*************** gfc_conv_intrinsic_minmaxloc (gfc_se * s
*** 1928,1933 ****
--- 1928,1934 ----
tree tmp;
tree elsetmp;
tree ifbody;
+ tree offset;
gfc_loopinfo loop;
gfc_actual_arglist *actual;
gfc_ss *arrayss;
*************** gfc_conv_intrinsic_minmaxloc (gfc_se * s
*** 2045,2059 ****
/* Assign the value to the limit... */
gfc_add_modify_expr (&ifblock, limit, arrayse.expr);
! /* Remember where we are. */
! gfc_add_modify_expr (&ifblock, pos, loop.loopvar[0]);
ifbody = gfc_finish_block (&ifblock);
! /* If it is a more extreme value or pos is still zero. */
! tmp = build2 (TRUTH_OR_EXPR, boolean_type_node,
! build2 (op, boolean_type_node, arrayse.expr, limit),
! build2 (EQ_EXPR, boolean_type_node, pos,
gfc_index_zero_node));
tmp = build3_v (COND_EXPR, tmp, ifbody, build_empty_stmt ());
gfc_add_expr_to_block (&block, tmp);
--- 2046,2068 ----
/* Assign the value to the limit... */
gfc_add_modify_expr (&ifblock, limit, arrayse.expr);
! /* Remember where we are. An offset must be added to the loop
! counter to obtain the required position. */
! if (loop.temp_dim)
! offset = build_int_cst (type, 1);
! else
! offset =fold_build2 (MINUS_EXPR, gfc_array_index_type,
! gfc_index_one_node, loop.from[0]);
! offset = gfc_evaluate_now (offset, &block);
!
! tmp = build2 (PLUS_EXPR, TREE_TYPE (pos),
! loop.loopvar[0], offset);
! gfc_add_modify_expr (&ifblock, pos, tmp);
ifbody = gfc_finish_block (&ifblock);
! /* If it is a more extreme value. */
! tmp = build2 (op, boolean_type_node, arrayse.expr, limit);
tmp = build3_v (COND_EXPR, tmp, ifbody, build_empty_stmt ());
gfc_add_expr_to_block (&block, tmp);
*************** gfc_conv_intrinsic_minmaxloc (gfc_se * s
*** 2098,2109 ****
}
gfc_cleanup_loop (&loop);
! /* Return a value in the range 1..SIZE(array). */
! tmp = fold_build2 (MINUS_EXPR, gfc_array_index_type, loop.from[0],
! gfc_index_one_node);
! tmp = fold_build2 (MINUS_EXPR, gfc_array_index_type, pos, tmp);
! /* And convert to the required type. */
! se->expr = convert (type, tmp);
}
static void
--- 2107,2113 ----
}
gfc_cleanup_loop (&loop);
! se->expr = convert (type, pos);
}
static void
--
pault at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |pault at gcc dot gnu dot org
|dot org |
Status|NEW |ASSIGNED
Last reconfirmed|2007-04-27 13:16:34 |2007-06-21 18:14:41
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31726