https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96613

--- Comment #7 from anlauf at gcc dot gnu.org ---
(In reply to Steve Kargl from comment #6)
> To fix, the above, you'll need to look at iresolve.c
> 
> static void
> gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
> {
>   gfc_actual_arglist *a;
> 
>   f->ts.type = args->expr->ts.type;
>   f->ts.kind = args->expr->ts.kind;
> 
> and re-do the conversion stuff.  AFAICT, type conversion is
> not handled correctly.  The largest kind is found regardless
> of the type and this kind with the type of first argument is
> used to to do conversion.

I played around with other potential testcases.  So far it seems
sufficient to just "fix" the simplification:

diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index eb8b2afeb29..074b50c2e68 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -4924,6 +4924,8 @@ min_max_choose (gfc_expr *arg, gfc_expr *extremum, int
sign, bool back_val)
   switch (arg->ts.type)
     {
       case BT_INTEGER:
+       if (extremum->ts.kind < arg->ts.kind)
+         extremum->ts.kind = arg->ts.kind;
        ret = mpz_cmp (arg->value.integer,
                       extremum->value.integer) * sign;
        if (ret > 0)
@@ -4931,6 +4933,8 @@ min_max_choose (gfc_expr *arg, gfc_expr *extremum, int
sign, bool back_val)
        break;

       case BT_REAL:
+       if (extremum->ts.kind < arg->ts.kind)
+         extremum->ts.kind = arg->ts.kind;
        if (mpfr_nan_p (extremum->value.real))
          {
            ret = 1;

Not fully regtested though.

Reply via email to