From 13b1afe4defcc3eeaa50fe10eb2f2768e95696ec Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Sun, 6 Jan 2019 12:48:58 +0000 Subject: [PATCH] re PR fortran/88658 (Intrinsic MAX1 returns a REAL result, should be INTEGER.) 2019-01-06 Thomas Koenig PR fortran/88658 * gfortran.h: Add macro gfc_real_4_kind * simplify.c (simplify_min_max): Special case for the types of AMAX0, AMIN0, MAX1 and MIN1, which actually change the types of their arguments. 2019-01-06 Thomas Koenig PR fortran/88658 * gfortran.dg/min_max_type_2.f90: New test. From-SVN: r267609 --- gcc/fortran/ChangeLog | 8 +++++++ gcc/fortran/gfortran.h | 1 + gcc/fortran/simplify.c | 24 +++++++++++++++++++- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gfortran.dg/min_max_type_2.f90 | 18 +++++++++++++++ 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/min_max_type_2.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 2b8da1dd919..cf869f8785a 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,11 @@ +2019-01-06 Thomas Koenig + + PR fortran/88658 + * gfortran.h: Add macro gfc_real_4_kind + * simplify.c (simplify_min_max): Special case for the types of + AMAX0, AMIN0, MAX1 and MIN1, which actually change the types of + their arguments. + 2019-01-05 Janus Weil PR fortran/88009 diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index fd8b3537253..0b281105fb4 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -2967,6 +2967,7 @@ extern int gfc_character_storage_size; #define gfc_logical_4_kind 4 #define gfc_integer_4_kind 4 +#define gfc_real_4_kind 4 /* symbol.c */ void gfc_clear_new_implicit (void); diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 22313901bd8..fdaf3cb4740 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -4963,6 +4963,8 @@ static gfc_expr * simplify_min_max (gfc_expr *expr, int sign) { gfc_actual_arglist *arg, *last, *extremum; + gfc_expr *tmp, *ret; + const char *fname; last = NULL; extremum = NULL; @@ -4995,7 +4997,27 @@ simplify_min_max (gfc_expr *expr, int sign) if (expr->value.function.actual->next != NULL) return NULL; - return gfc_copy_expr (expr->value.function.actual->expr); + /* Handle special cases of specific functions (min|max)1 and + a(min|max)0. */ + + tmp = expr->value.function.actual->expr; + fname = expr->value.function.isym->name; + + if ((tmp->ts.type != BT_INTEGER || tmp->ts.kind != gfc_integer_4_kind) + && (strcmp (fname, "min1") == 0 || strcmp (fname, "max1") == 0)) + { + ret = gfc_convert_constant (tmp, BT_INTEGER, gfc_integer_4_kind); + } + else if ((tmp->ts.type != BT_REAL || tmp->ts.kind != gfc_real_4_kind) + && (strcmp (fname, "amin0") == 0 || strcmp (fname, "amax0") == 0)) + { + ret = gfc_convert_constant (tmp, BT_REAL, gfc_real_4_kind); + } + else + ret = gfc_copy_expr (tmp); + + return ret; + } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f27b3a3e538..fcbbd7432ae 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-01-06 Thomas Koenig + + PR fortran/88658 + * gfortran.dg/min_max_type_2.f90: New test. + 2019-01-06 Jakub Jelinek PR c/88363 diff --git a/gcc/testsuite/gfortran.dg/min_max_type_2.f90 b/gcc/testsuite/gfortran.dg/min_max_type_2.f90 new file mode 100644 index 00000000000..e2b6d6745d9 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/min_max_type_2.f90 @@ -0,0 +1,18 @@ +! { dg-do run } +! PR 88658 - make sure the types for min1, max1, amax0 and amin0 are +! correct when simplified + +program main + real :: RVCOMP + character (len=12) :: line + integer :: n + + RVCOMP = MAX1(2.3, 3.1, 4.4) / 5 + if (rvcomp /= 0.) stop 1 + rvcomp = min1(2.3, 3.1, 5.1) / 5 + if (rvcomp /= 0.) stop 2 + write (unit=line, fmt='(F12.5)') amax0(42, 21, 7) + if (line /= ' 42.00000') stop 3 + write (unit=line, fmt='(F12.5)') amin0(42,21,7) + if (line /= ' 7.00000') stop 4 +end program main -- 2.30.2