]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran - fix conversion to result type for the min/max intrinsic
authorHarald Anlauf <anlauf@gmx.de>
Fri, 18 Jun 2021 17:34:15 +0000 (19:34 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Sat, 19 Jun 2021 18:13:18 +0000 (20:13 +0200)
gcc/fortran/ChangeLog:

PR fortran/100283
PR fortran/101123
* trans-intrinsic.c (gfc_conv_intrinsic_minmax): Unconditionally
convert result of min/max to result type.

gcc/testsuite/ChangeLog:

PR fortran/100283
PR fortran/101123
* gfortran.dg/min0_max0_1.f90: New test.
* gfortran.dg/min0_max0_2.f90: New test.

(cherry picked from commit 6fc543396345900f460c9fa7121239cb1ebbc3a3)

gcc/fortran/trans-intrinsic.c
gcc/testsuite/gfortran.dg/min0_max0_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/min0_max0_2.f90 [new file with mode: 0644]

index 2c094f326e62652e32f39fed1fe2bfdee080c443..c67a9fca46fb0442eadc34274a2f9f75e8e75edf 100644 (file)
@@ -4157,10 +4157,7 @@ gfc_conv_intrinsic_minmax (gfc_se * se, gfc_expr * expr, enum tree_code op)
                        build_empty_stmt (input_location));
       gfc_add_expr_to_block (&se->pre, tmp);
     }
-  if (TREE_CODE (type) == INTEGER_TYPE)
-    se->expr = fold_build1_loc (input_location, FIX_TRUNC_EXPR, type, mvar);
-  else
-    se->expr = convert (type, mvar);
+  se->expr = convert (type, mvar);
 }
 
 
diff --git a/gcc/testsuite/gfortran.dg/min0_max0_1.f90 b/gcc/testsuite/gfortran.dg/min0_max0_1.f90
new file mode 100644 (file)
index 0000000..118b0f0
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! { dg-options "-std=gnu" }
+! PR fortran/100283
+
+subroutine s ()
+  integer(kind=8) :: i,j,k
+  i = min0 (j,k)
+  i = max0 (-127_8, min0 (j,127_8))
+end subroutine s
diff --git a/gcc/testsuite/gfortran.dg/min0_max0_2.f90 b/gcc/testsuite/gfortran.dg/min0_max0_2.f90
new file mode 100644 (file)
index 0000000..3fe4fcd
--- /dev/null
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! { dg-options "-fdefault-integer-8 -std=gnu" }
+! PR fortran/101123
+
+SUBROUTINE TEST
+  IMPLICIT INTEGER*4 (I-N)
+  MAXMN=MAX0(M,N)
+  MINMN=MIN0(M,0_4)
+  MAXRS=MAX1(R,S)
+END SUBROUTINE TEST