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

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