[Patch, Fortran] Use -huge()-1 as most negative integer for maxval/maxloc (PR30512)
Tobias Burnus
burnus@net-b.de
Fri Feb 2 08:54:00 GMT 2007
Thomas Koenig wrote:
> This is OK, with a few minor nits:
>
I'm not sure I understand the nits correctly.
> On Thu, Feb 01, 2007 at 09:59:27AM +0100, Tobias Burnus wrote:
>
>> ===================================================================
>> --- gcc/fortran/trans-intrinsic.c (Revision 121416)
>> +++ gcc/fortran/trans-intrinsic.c (Arbeitskopie)
>> @@ -1984,11 +1984,16 @@
>> gcc_unreachable ();
>> }
>>
>> - /* Most negative(+HUGE) for maxval, most negative (-HUGE) for minval. */
>> + /* Most negative(-HUGE) for maxloc, most positiv (+HUGE) for minloc. */
>>
> This should read
>
>> - /* Most negative(-HUGE) for maxval, most positive (-HUGE) for minval. */
>> + /* Most negative(-HUGE) for maxval, most positive (+HUGE) for minval. */
>>
I think the way it is in my patch is commentwise correct. In my tree it
currently (with patch) reads as:
gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * expr, int op)
[...]
case BT_REAL:
tmp = gfc_conv_mpfr_to_tree (gfc_real_kinds[n].huge,
expr->ts.kind); [...]
case BT_INTEGER:
tmp = gfc_conv_mpz_to_tree (gfc_integer_kinds[n].huge, expr->ts.kind);
[...]
/* Most negative(-HUGE) for maxloc, most positiv (+HUGE) for minloc. */
if (op == GT_EXPR)
tmp = fold_build1 (NEGATE_EXPR, TREE_TYPE (tmp), tmp);
gfc_add_modify_expr (&se->pre, limit, tmp);
/* Most negative for BT_INTEGER is -HUGE-1. */
if (op == GT_EXPR && expr->ts.type == BT_INTEGER)
tmp = build2 (MINUS_EXPR, TREE_TYPE (tmp), tmp,
build_int_cst (type, 1));
gfc_conv_intrinsic_minmaxval (gfc_se * se, gfc_expr * expr, int op)
[...]
/* Most negative(-HUGE) for maxval, most positive (+HUGE) for minval. */
if (op == GT_EXPR)
tmp = fold_build1 (NEGATE_EXPR, TREE_TYPE (tmp), tmp);
/* Most negative for BT_INTEGER is -HUGE-1. */
if (op == GT_EXPR && expr->ts.type == BT_INTEGER)
tmp = build2 (MINUS_EXPR, TREE_TYPE (tmp), tmp,
build_int_cst (type, 1));
> and this
> /* Most negative(-HUGE-1) for maxval, most positive (+HUGE) for minval. */
>
While I agree that one could improve the wording, I think using
"(-HUGE-1)" is confusing for BT_REAL.
How about something like the following?
/* Most negative for maxloc, most positiv (+HUGE) for minloc.
Most negative is -HUGE for BT_REAL and -HUGE-1 for BT_INTEGER. */
if (op == GT_EXPR)
tmp = fold_build1 (NEGATE_EXPR, TREE_TYPE (tmp), tmp);
gfc_add_modify_expr (&se->pre, limit, tmp);
if (op == GT_EXPR && expr->ts.type == BT_INTEGER)
tmp = build2 (MINUS_EXPR, TREE_TYPE (tmp), tmp,
build_int_cst (type, 1));
Tobias
More information about the Gcc-patches
mailing list