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

3db796
From a6e02ad7b8b66823629a9703af4662b8b4037e2b Mon Sep 17 00:00:00 2001
3db796
From: Jim MacArthur <jim.macarthur@codethink.co.uk>
3db796
Date: Mon, 5 Oct 2015 14:05:03 +0100
3db796
Subject: [PATCH 08/23] Allow non-integer substring indexes
3db796
3db796
This feature is enabled by the `-std=extra-legacy` compiler flag.
3db796
---
3db796
6068c7
commit 9f05bda69f21d7a7c17b58ff0b6392bfd1a06bae
6068c7
Author: Jim MacArthur <jim.macarthur@codethink.co.uk>
6068c7
Date:   Mon Oct 5 14:05:03 2015 +0100
6068c7
6068c7
    Allow non-integer substring indexes
6068c7
    
6068c7
    This feature is enabled by the `-std=extra-legacy` compiler flag.
6068c7
    
6068c7
    Test written by: Francisco Redondo Marchena <francisco.marchena@codethink.co.uk>
3db796
3db796
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
6068c7
index 84a4827a1b7..667cc5073e3 100644
3db796
--- a/gcc/fortran/resolve.c
3db796
+++ b/gcc/fortran/resolve.c
3db796
@@ -4680,6 +4680,17 @@ resolve_substring (gfc_ref *ref)
3db796
       if (!gfc_resolve_expr (ref->u.ss.start))
3db796
 	return false;
3db796
 
3db796
+      /* In legacy mode, allow non-integer string indexes by converting */
3db796
+      if ((gfc_option.allow_std & GFC_STD_EXTRA_LEGACY)
3db796
+	  && ref->u.ss.start->ts.type != BT_INTEGER
3db796
+	  && gfc_numeric_ts (&ref->u.ss.start->ts))
3db796
+	{
3db796
+	  gfc_typespec t;
3db796
+	  t.type = BT_INTEGER;
3db796
+	  t.kind = ref->u.ss.start->ts.kind;
3db796
+	  gfc_convert_type_warn (ref->u.ss.start, &t, 2, 1);
3db796
+	}
3db796
+
3db796
       if (ref->u.ss.start->ts.type != BT_INTEGER)
3db796
 	{
3db796
 	  gfc_error ("Substring start index at %L must be of type INTEGER",
3db796
@@ -4709,6 +4720,17 @@ resolve_substring (gfc_ref *ref)
3db796
       if (!gfc_resolve_expr (ref->u.ss.end))
3db796
 	return false;
3db796
 
3db796
+      /* Non-integer string index endings, as for start */
3db796
+      if ((gfc_option.allow_std & GFC_STD_EXTRA_LEGACY)
3db796
+	  && ref->u.ss.end->ts.type != BT_INTEGER
3db796
+	  && gfc_numeric_ts (&ref->u.ss.end->ts))
3db796
+	{
3db796
+	  gfc_typespec t;
3db796
+	  t.type = BT_INTEGER;
3db796
+	  t.kind = ref->u.ss.end->ts.kind;
3db796
+	  gfc_convert_type_warn (ref->u.ss.end, &t, 2, 1);
3db796
+	}
3db796
+
3db796
       if (ref->u.ss.end->ts.type != BT_INTEGER)
3db796
 	{
3db796
 	  gfc_error ("Substring end index at %L must be of type INTEGER",
6068c7
diff --git a/gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes.f b/gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes.f
6068c7
new file mode 100644
6068c7
index 00000000000..8f5c8eb3c0e
6068c7
--- /dev/null
6068c7
+++ b/gcc/testsuite/gfortran.dg/dec_not_integer_substring_indexes.f
6068c7
@@ -0,0 +1,17 @@
6068c7
+! { dg-do compile }
6068c7
+! { dg-options "-std=extra-legacy" }
6068c7
+!
6068c7
+! Test not integer substring indexes
6068c7
+!
6068c7
+        PROGRAM not_integer_substring_indexes
6068c7
+          CHARACTER*5 st/'Tests'/
6068c7
+          CHARACTER*4 st2
6068c7
+          REAL ir/1.0/
6068c7
+          REAL ir2/4.0/
6068c7
+
6068c7
+          st2 = st(ir:4)
6068c7
+          st2 = st(1:ir2)
6068c7
+          st2 = st(1.0:4)
6068c7
+          st2 = st(1:4.0)
6068c7
+          st2 = st(1.5:4)
6068c7
+        END