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