Blame SOURCES/0004-Allow-non-integer-substring-indexes.patch

840c13
From e61c233e6af3c392f5ac7d3f927b3fa8a55c6076 Mon Sep 17 00:00:00 2001
840c13
From: Mark Eggleston <markeggleston@gcc.gnu.org>
840c13
Date: Mon, 3 Feb 2020 09:11:38 +0000
840c13
Subject: [PATCH 04/10] Allow non-integer substring indexes
0714f1
0714f1
Use -fdec-non-integer-index compiler flag to enable. Also enabled by -fdec.
0714f1
---
0714f1
 gcc/fortran/lang.opt                                 |  4 ++++
0714f1
 gcc/fortran/options.c                                |  1 +
0714f1
 gcc/fortran/resolve.c                                | 20 ++++++++++++++++++++
0714f1
 .../dec_not_integer_substring_indexes_1.f            | 18 ++++++++++++++++++
0714f1
 .../dec_not_integer_substring_indexes_2.f            | 18 ++++++++++++++++++
0714f1
 .../dec_not_integer_substring_indexes_3.f            | 18 ++++++++++++++++++
0714f1
 6 files changed, 79 insertions(+)
0714f1
 create mode 100644 gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes_1.f
0714f1
 create mode 100644 gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes_2.f
0714f1
 create mode 100644 gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes_3.f
0714f1
0714f1
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
840c13
index 5257da74b06..0fea012b7b6 100644
0714f1
--- a/gcc/fortran/lang.opt
0714f1
+++ b/gcc/fortran/lang.opt
840c13
@@ -485,6 +485,10 @@ fdec-math
0714f1
 Fortran Var(flag_dec_math)
0714f1
 Enable legacy math intrinsics for compatibility.
0714f1
 
0714f1
+fdec-non-integer-index
0714f1
+Fortran Var(flag_dec_non_integer_index)
0714f1
+Enable support for non-integer substring indexes.
0714f1
+
0714f1
 fdec-structure
0714f1
 Fortran Var(flag_dec_structure)
0714f1
 Enable support for DEC STRUCTURE/RECORD.
0714f1
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
840c13
index 75181ca6442..8c79a0bd122 100644
0714f1
--- a/gcc/fortran/options.c
0714f1
+++ b/gcc/fortran/options.c
840c13
@@ -78,6 +78,7 @@ set_dec_flags (int value)
0714f1
   SET_BITFLAG (flag_dec_blank_format_item, value, value);
840c13
   SET_BITFLAG (flag_dec_char_conversions, value, value);
840c13
   SET_BITFLAG (flag_dec_duplicates, value, value);
0714f1
+  SET_BITFLAG (flag_dec_non_integer_index, value, value);
0714f1
 }
0714f1
 
0714f1
 /* Finalize DEC flags.  */
0714f1
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
840c13
index 6e70eaf8812..044eed22c76 100644
0714f1
--- a/gcc/fortran/resolve.c
0714f1
+++ b/gcc/fortran/resolve.c
840c13
@@ -5087,6 +5087,16 @@ resolve_substring (gfc_ref *ref, bool *equal_length)
0714f1
       if (!gfc_resolve_expr (ref->u.ss.start))
0714f1
 	return false;
0714f1
 
0714f1
+      /* In legacy mode, allow non-integer string indexes by converting */
0714f1
+      if (flag_dec_non_integer_index && ref->u.ss.start->ts.type != BT_INTEGER
0714f1
+	  && gfc_numeric_ts (&ref->u.ss.start->ts))
0714f1
+	{
0714f1
+	  gfc_typespec t;
0714f1
+	  t.type = BT_INTEGER;
0714f1
+	  t.kind = ref->u.ss.start->ts.kind;
0714f1
+	  gfc_convert_type_warn (ref->u.ss.start, &t, 2, 1);
0714f1
+	}
0714f1
+
0714f1
       if (ref->u.ss.start->ts.type != BT_INTEGER)
0714f1
 	{
0714f1
 	  gfc_error ("Substring start index at %L must be of type INTEGER",
840c13
@@ -5116,6 +5126,16 @@ resolve_substring (gfc_ref *ref, bool *equal_length)
0714f1
       if (!gfc_resolve_expr (ref->u.ss.end))
0714f1
 	return false;
0714f1
 
0714f1
+      /* Non-integer string index endings, as for start */
0714f1
+      if (flag_dec_non_integer_index && ref->u.ss.end->ts.type != BT_INTEGER
0714f1
+	  && gfc_numeric_ts (&ref->u.ss.end->ts))
0714f1
+	{
0714f1
+	  gfc_typespec t;
0714f1
+	  t.type = BT_INTEGER;
0714f1
+	  t.kind = ref->u.ss.end->ts.kind;
0714f1
+	  gfc_convert_type_warn (ref->u.ss.end, &t, 2, 1);
0714f1
+	}
0714f1
+
0714f1
       if (ref->u.ss.end->ts.type != BT_INTEGER)
0714f1
 	{
0714f1
 	  gfc_error ("Substring end index at %L must be of type INTEGER",
0714f1
diff --git a/gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes_1.f b/gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes_1.f
0714f1
new file mode 100644
0714f1
index 00000000000..0be28abaa4b
0714f1
--- /dev/null
0714f1
+++ b/gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes_1.f
0714f1
@@ -0,0 +1,18 @@
0714f1
+! { dg-do run }
0714f1
+! { dg-options "-fdec" }
0714f1
+!
0714f1
+! Test not integer substring indexes
0714f1
+!
0714f1
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
0714f1
+!
0714f1
+        PROGRAM not_integer_substring_indexes
0714f1
+          CHARACTER*5 st/'Tests'/
0714f1
+          REAL ir/1.0/
0714f1
+          REAL ir2/4.0/
0714f1
+
0714f1
+          if (st(ir:4).ne.'Test') stop 1
0714f1
+          if (st(1:ir2).ne.'Test') stop 2
0714f1
+          if (st(1.0:4).ne.'Test') stop 3
0714f1
+          if (st(1:4.0).ne.'Test') stop 4
0714f1
+          if (st(2.5:4).ne.'est') stop 5
0714f1
+        END
0714f1
diff --git a/gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes_2.f b/gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes_2.f
0714f1
new file mode 100644
0714f1
index 00000000000..3cf05296d0c
0714f1
--- /dev/null
0714f1
+++ b/gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes_2.f
0714f1
@@ -0,0 +1,18 @@
0714f1
+! { dg-do run }
0714f1
+! { dg-options "-fdec-non-integer-index" }
0714f1
+!
0714f1
+! Test not integer substring indexes
0714f1
+!
0714f1
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
0714f1
+!
0714f1
+        PROGRAM not_integer_substring_indexes
0714f1
+          CHARACTER*5 st/'Tests'/
0714f1
+          REAL ir/1.0/
0714f1
+          REAL ir2/4.0/
0714f1
+
0714f1
+          if (st(ir:4).ne.'Test') stop 1
0714f1
+          if (st(1:ir2).ne.'Test') stop 2
0714f1
+          if (st(1.0:4).ne.'Test') stop 3
0714f1
+          if (st(1:4.0).ne.'Test') stop 4
0714f1
+          if (st(2.5:4).ne.'est') stop 5
0714f1
+        END
0714f1
diff --git a/gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes_3.f b/gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes_3.f
0714f1
new file mode 100644
0714f1
index 00000000000..703de995897
0714f1
--- /dev/null
0714f1
+++ b/gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes_3.f
0714f1
@@ -0,0 +1,18 @@
0714f1
+! { dg-do compile }
0714f1
+! { dg-options "-fdec -fno-dec-non-integer-index" }
0714f1
+!
0714f1
+! Test not integer substring indexes
0714f1
+!
0714f1
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
0714f1
+!
0714f1
+        PROGRAM not_integer_substring_indexes
0714f1
+          CHARACTER*5 st/'Tests'/
0714f1
+          REAL ir/1.0/
0714f1
+          REAL ir2/4.0/
0714f1
+
0714f1
+          if (st(ir:4).ne.'Test') stop 1 ! { dg-error "Substring start index" }
0714f1
+          if (st(1:ir2).ne.'Test') stop 2 ! { dg-error "Substring end index" }
0714f1
+          if (st(1.0:4).ne.'Test') stop 3 ! { dg-error "Substring start index" }
0714f1
+          if (st(1:4.0).ne.'Test') stop 4 ! { dg-error "Substring end index" }
0714f1
+          if (st(2.5:4).ne.'est') stop 5 ! { dg-error "Substring start index" }
0714f1
+        END
0714f1
-- 
0714f1
2.11.0
0714f1