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

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