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

9805c9
From 96563a652406d3c8471d75e6527ba634fa013400 Mon Sep 17 00:00:00 2001
9805c9
From: Jim MacArthur <jim.macarthur@codethink.co.uk>
9805c9
Date: Mon, 5 Oct 2015 14:05:03 +0100
9805c9
Subject: [PATCH 08/16] Allow non-integer substring indexes
9805c9
9805c9
Use -fdec-non-integer-index compiler flag to enable. Also enabled by -fdec.
9805c9
---
9805c9
 gcc/fortran/lang.opt                                 |  4 ++++
9805c9
 gcc/fortran/options.c                                |  1 +
9805c9
 gcc/fortran/resolve.c                                | 20 ++++++++++++++++++++
9805c9
 .../dec_not_integer_substring_indexes_1.f            | 18 ++++++++++++++++++
9805c9
 .../dec_not_integer_substring_indexes_2.f            | 18 ++++++++++++++++++
9805c9
 .../dec_not_integer_substring_indexes_3.f            | 18 ++++++++++++++++++
9805c9
 6 files changed, 79 insertions(+)
9805c9
 create mode 100644 gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes_1.f
9805c9
 create mode 100644 gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes_2.f
9805c9
 create mode 100644 gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes_3.f
9805c9
9805c9
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
9805c9
index 3d8aaeaaf44..772cf5e81f1 100644
9805c9
--- a/gcc/fortran/lang.opt
9805c9
+++ b/gcc/fortran/lang.opt
9805c9
@@ -474,6 +474,10 @@ fdec-math
9805c9
 Fortran Var(flag_dec_math)
9805c9
 Enable legacy math intrinsics for compatibility.
9805c9
 
9805c9
+fdec-non-integer-index
9805c9
+Fortran Var(flag_dec_non_integer_index)
9805c9
+Enable support for non-integer substring indexes.
9805c9
+
9805c9
 fdec-structure
9805c9
 Fortran Var(flag_dec_structure)
9805c9
 Enable support for DEC STRUCTURE/RECORD.
9805c9
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
9805c9
index a8c2cf71c3b..e0ef03e6cc5 100644
9805c9
--- a/gcc/fortran/options.c
9805c9
+++ b/gcc/fortran/options.c
9805c9
@@ -79,6 +79,7 @@ set_dec_flags (int value)
9805c9
   SET_BITFLAG (flag_dec_char_conversions, value, value);
9805c9
   SET_BITFLAG (flag_dec_comparisons, value, value);
9805c9
   SET_BITFLAG (flag_dec_blank_format_item, value, value);
9805c9
+  SET_BITFLAG (flag_dec_non_integer_index, value, value);
9805c9
 }
9805c9
 
9805c9
 /* Finalize DEC flags.  */
9805c9
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
9805c9
index c8b6333874b..04679d3a15d 100644
9805c9
--- a/gcc/fortran/resolve.c
9805c9
+++ b/gcc/fortran/resolve.c
9805c9
@@ -4992,6 +4992,16 @@ resolve_substring (gfc_ref *ref, bool *equal_length)
9805c9
       if (!gfc_resolve_expr (ref->u.ss.start))
9805c9
 	return false;
9805c9
 
9805c9
+      /* In legacy mode, allow non-integer string indexes by converting */
9805c9
+      if (flag_dec_non_integer_index && ref->u.ss.start->ts.type != BT_INTEGER
9805c9
+	  && gfc_numeric_ts (&ref->u.ss.start->ts))
9805c9
+	{
9805c9
+	  gfc_typespec t;
9805c9
+	  t.type = BT_INTEGER;
9805c9
+	  t.kind = ref->u.ss.start->ts.kind;
9805c9
+	  gfc_convert_type_warn (ref->u.ss.start, &t, 2, 1);
9805c9
+	}
9805c9
+
9805c9
       if (ref->u.ss.start->ts.type != BT_INTEGER)
9805c9
 	{
9805c9
 	  gfc_error ("Substring start index at %L must be of type INTEGER",
9805c9
@@ -5021,6 +5031,16 @@ resolve_substring (gfc_ref *ref, bool *equal_length)
9805c9
       if (!gfc_resolve_expr (ref->u.ss.end))
9805c9
 	return false;
9805c9
 
9805c9
+      /* Non-integer string index endings, as for start */
9805c9
+      if (flag_dec_non_integer_index && ref->u.ss.end->ts.type != BT_INTEGER
9805c9
+	  && gfc_numeric_ts (&ref->u.ss.end->ts))
9805c9
+	{
9805c9
+	  gfc_typespec t;
9805c9
+	  t.type = BT_INTEGER;
9805c9
+	  t.kind = ref->u.ss.end->ts.kind;
9805c9
+	  gfc_convert_type_warn (ref->u.ss.end, &t, 2, 1);
9805c9
+	}
9805c9
+
9805c9
       if (ref->u.ss.end->ts.type != BT_INTEGER)
9805c9
 	{
9805c9
 	  gfc_error ("Substring end index at %L must be of type INTEGER",
9805c9
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
9805c9
new file mode 100644
9805c9
index 00000000000..0be28abaa4b
9805c9
--- /dev/null
9805c9
+++ b/gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes_1.f
9805c9
@@ -0,0 +1,18 @@
9805c9
+! { dg-do run }
9805c9
+! { dg-options "-fdec" }
9805c9
+!
9805c9
+! Test not integer substring indexes
9805c9
+!
9805c9
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
9805c9
+!
9805c9
+        PROGRAM not_integer_substring_indexes
9805c9
+          CHARACTER*5 st/'Tests'/
9805c9
+          REAL ir/1.0/
9805c9
+          REAL ir2/4.0/
9805c9
+
9805c9
+          if (st(ir:4).ne.'Test') stop 1
9805c9
+          if (st(1:ir2).ne.'Test') stop 2
9805c9
+          if (st(1.0:4).ne.'Test') stop 3
9805c9
+          if (st(1:4.0).ne.'Test') stop 4
9805c9
+          if (st(2.5:4).ne.'est') stop 5
9805c9
+        END
9805c9
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
9805c9
new file mode 100644
9805c9
index 00000000000..3cf05296d0c
9805c9
--- /dev/null
9805c9
+++ b/gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes_2.f
9805c9
@@ -0,0 +1,18 @@
9805c9
+! { dg-do run }
9805c9
+! { dg-options "-fdec-non-integer-index" }
9805c9
+!
9805c9
+! Test not integer substring indexes
9805c9
+!
9805c9
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
9805c9
+!
9805c9
+        PROGRAM not_integer_substring_indexes
9805c9
+          CHARACTER*5 st/'Tests'/
9805c9
+          REAL ir/1.0/
9805c9
+          REAL ir2/4.0/
9805c9
+
9805c9
+          if (st(ir:4).ne.'Test') stop 1
9805c9
+          if (st(1:ir2).ne.'Test') stop 2
9805c9
+          if (st(1.0:4).ne.'Test') stop 3
9805c9
+          if (st(1:4.0).ne.'Test') stop 4
9805c9
+          if (st(2.5:4).ne.'est') stop 5
9805c9
+        END
9805c9
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
9805c9
new file mode 100644
9805c9
index 00000000000..703de995897
9805c9
--- /dev/null
9805c9
+++ b/gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes_3.f
9805c9
@@ -0,0 +1,18 @@
9805c9
+! { dg-do compile }
9805c9
+! { dg-options "-fdec -fno-dec-non-integer-index" }
9805c9
+!
9805c9
+! Test not integer substring indexes
9805c9
+!
9805c9
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
9805c9
+!
9805c9
+        PROGRAM not_integer_substring_indexes
9805c9
+          CHARACTER*5 st/'Tests'/
9805c9
+          REAL ir/1.0/
9805c9
+          REAL ir2/4.0/
9805c9
+
9805c9
+          if (st(ir:4).ne.'Test') stop 1 ! { dg-error "Substring start index" }
9805c9
+          if (st(1:ir2).ne.'Test') stop 2 ! { dg-error "Substring end index" }
9805c9
+          if (st(1.0:4).ne.'Test') stop 3 ! { dg-error "Substring start index" }
9805c9
+          if (st(1:4.0).ne.'Test') stop 4 ! { dg-error "Substring end index" }
9805c9
+          if (st(2.5:4).ne.'est') stop 5 ! { dg-error "Substring start index" }
9805c9
+        END
9805c9
-- 
9805c9
2.11.0
9805c9