re PR fortran/83316 (ICE: minval/maxval and characters)
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 9 Dec 2017 08:37:17 +0000 (08:37 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 9 Dec 2017 08:37:17 +0000 (08:37 +0000)
2017-12-09  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/83316
* arith.c (gfc_character2character): New function.
* arith.h: Add prototype.
* simplify.c (gfc_convert_constant): Handle character type.

2017-12-09  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/83316
* gfortran.dg/minval_char_5.f90: New test.

From-SVN: r255522

gcc/fortran/ChangeLog
gcc/fortran/arith.c
gcc/fortran/arith.h
gcc/fortran/simplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/minval_char_5.f90 [new file with mode: 0644]

index b48bac45e16960c57c9918d8604afd51c0a2514a..a2be75ab4b34718a437cd26b4b85b197515fc2fd 100644 (file)
@@ -1,3 +1,10 @@
+2017-12-09  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/83316
+       * arith.c (gfc_character2character): New function.
+       * arith.h: Add prototype.
+       * simplify.c (gfc_convert_constant): Handle character type.
+
 2017-12-07  Martin Sebor  <msebor@redhat.com>
 
        PR c/81544
index 3c75895e2efd1f9254b94dc112554f99514b7b4e..267306713f9d061c1df20900be2609e7bf4fe8a0 100644 (file)
@@ -2514,6 +2514,18 @@ gfc_int2log (gfc_expr *src, int kind)
   return result;
 }
 
+/* Convert character to character. We only use wide strings internally,
+   so we only set the kind.  */
+
+gfc_expr *
+gfc_character2character (gfc_expr *src, int kind)
+{
+  gfc_expr *result;
+  result = gfc_copy_expr (src);
+  result->ts.kind = kind;
+
+  return result;
+}
 
 /* Helper function to set the representation in a Hollerith conversion.  
    This assumes that the ts.type and ts.kind of the result have already
index 9c623a42ab5a579dff88e1fd1478c7526f93630f..db042cc765177f15d60abd80cd11b919ee59f81f 100644 (file)
@@ -82,6 +82,7 @@ gfc_expr *gfc_hollerith2real (gfc_expr *, int);
 gfc_expr *gfc_hollerith2complex (gfc_expr *, int);
 gfc_expr *gfc_hollerith2character (gfc_expr *, int);
 gfc_expr *gfc_hollerith2logical (gfc_expr *, int);
+gfc_expr *gfc_character2character (gfc_expr *, int);
 
 #endif /* GFC_ARITH_H  */
 
index c7b7e1a8297c2e26df995c84f3cc098aad8cc5fe..f11ea42c29252168cae72b3d4bc4dcf6f49cf316 100644 (file)
@@ -7130,6 +7130,13 @@ gfc_convert_constant (gfc_expr *e, bt type, int kind)
        }
       break;
 
+    case BT_CHARACTER:
+      if (type == BT_CHARACTER)
+       f = gfc_character2character;
+      else
+       goto oops;
+      break;
+
     default:
     oops:
       gfc_internal_error ("gfc_convert_constant(): Unexpected type");
index cd6c927138ba0801ea62bbced08341a94210799f..99842f0622aff7184db76c760893ff2c8b006f74 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-09  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/83316
+       * gfortran.dg/minval_char_5.f90: New test.
+
 2017-12-08  Jakub Jelinek  <jakub@redhat.com>
 
        PR rtl-optimization/83317
diff --git a/gcc/testsuite/gfortran.dg/minval_char_5.f90 b/gcc/testsuite/gfortran.dg/minval_char_5.f90
new file mode 100644 (file)
index 0000000..5af344d
--- /dev/null
@@ -0,0 +1,18 @@
+! { dg-do  run }
+! PR fortran/83316 - this used to ICE
+program tminmaxval
+  implicit none
+
+  character(len=*), parameter :: b = "a"
+  character(len=*), parameter :: e = "c"
+  character(len=*), parameter :: s(3) = (/"a", "b", "c"/)
+
+  if (minval(s) /= b) then
+    call abort
+  end if
+  
+  if (maxval(s) /= e) then
+    call abort
+  end if
+
+end program tminmaxval