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

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