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