|
|
237f7c |
From 786869fd62813e80da9b6545a295d53c36275c19 Mon Sep 17 00:00:00 2001
|
|
|
237f7c |
From: Mark Eggleston <markeggleston@gcc.gnu.org>
|
|
|
237f7c |
Date: Fri, 22 Jan 2021 13:12:14 +0000
|
|
|
237f7c |
Subject: [PATCH 06/10] Allow string length and kind to be specified on a per
|
|
|
237f7c |
variable basis.
|
|
|
237f7c |
|
|
|
237f7c |
This allows kind/length to be mixed with array specification in
|
|
|
237f7c |
declarations.
|
|
|
237f7c |
|
|
|
237f7c |
e.g.
|
|
|
237f7c |
|
|
|
237f7c |
INTEGER*4 x*2, y*8
|
|
|
237f7c |
CHARACTER names*20(10)
|
|
|
237f7c |
REAL v(100)*8, vv*4(50)
|
|
|
237f7c |
|
|
|
237f7c |
The per-variable size overrides the kind or length specified for the type.
|
|
|
237f7c |
|
|
|
237f7c |
Use -fdec-override-kind to enable. Also enabled by -fdec.
|
|
|
237f7c |
|
|
|
237f7c |
Note: this feature is a merger of two previously separate features.
|
|
|
237f7c |
|
|
|
237f7c |
Now accepts named constants as kind parameters:
|
|
|
237f7c |
|
|
|
237f7c |
INTEGER A
|
|
|
237f7c |
PARAMETER (A=2)
|
|
|
237f7c |
INTEGER B*(A)
|
|
|
237f7c |
|
|
|
237f7c |
Contributed by Mark Eggleston <mark.eggleston@codethink.com>
|
|
|
237f7c |
|
|
|
237f7c |
Now rejects invalid kind parameters and prints error messages:
|
|
|
237f7c |
|
|
|
237f7c |
INTEGER X*3
|
|
|
237f7c |
|
|
|
237f7c |
caused an internal compiler error.
|
|
|
237f7c |
|
|
|
237f7c |
Contributed by Mark Eggleston <mark.eggleston@codethink.com>
|
|
|
237f7c |
---
|
|
|
237f7c |
gcc/fortran/decl.c | 156 ++++++++++++++----
|
|
|
237f7c |
gcc/fortran/lang.opt | 4 +
|
|
|
237f7c |
gcc/fortran/options.c | 1 +
|
|
|
237f7c |
.../dec_mixed_char_array_declaration_1.f | 13 ++
|
|
|
237f7c |
.../dec_mixed_char_array_declaration_2.f | 13 ++
|
|
|
237f7c |
.../dec_mixed_char_array_declaration_3.f | 13 ++
|
|
|
237f7c |
.../gfortran.dg/dec_spec_in_variable_1.f | 31 ++++
|
|
|
237f7c |
.../gfortran.dg/dec_spec_in_variable_2.f | 31 ++++
|
|
|
237f7c |
.../gfortran.dg/dec_spec_in_variable_3.f | 31 ++++
|
|
|
237f7c |
.../gfortran.dg/dec_spec_in_variable_4.f | 14 ++
|
|
|
237f7c |
.../gfortran.dg/dec_spec_in_variable_5.f | 19 +++
|
|
|
237f7c |
.../gfortran.dg/dec_spec_in_variable_6.f | 19 +++
|
|
|
237f7c |
.../gfortran.dg/dec_spec_in_variable_7.f | 15 ++
|
|
|
237f7c |
.../gfortran.dg/dec_spec_in_variable_8.f | 14 ++
|
|
|
237f7c |
14 files changed, 340 insertions(+), 34 deletions(-)
|
|
|
237f7c |
create mode 100644 gcc/testsuite/gfortran.dg/dec_mixed_char_array_declaration_1.f
|
|
|
237f7c |
create mode 100644 gcc/testsuite/gfortran.dg/dec_mixed_char_array_declaration_2.f
|
|
|
237f7c |
create mode 100644 gcc/testsuite/gfortran.dg/dec_mixed_char_array_declaration_3.f
|
|
|
237f7c |
create mode 100644 gcc/testsuite/gfortran.dg/dec_spec_in_variable_1.f
|
|
|
237f7c |
create mode 100644 gcc/testsuite/gfortran.dg/dec_spec_in_variable_2.f
|
|
|
237f7c |
create mode 100644 gcc/testsuite/gfortran.dg/dec_spec_in_variable_3.f
|
|
|
237f7c |
create mode 100644 gcc/testsuite/gfortran.dg/dec_spec_in_variable_4.f
|
|
|
237f7c |
create mode 100644 gcc/testsuite/gfortran.dg/dec_spec_in_variable_5.f
|
|
|
237f7c |
create mode 100644 gcc/testsuite/gfortran.dg/dec_spec_in_variable_6.f
|
|
|
237f7c |
create mode 100644 gcc/testsuite/gfortran.dg/dec_spec_in_variable_7.f
|
|
|
237f7c |
create mode 100644 gcc/testsuite/gfortran.dg/dec_spec_in_variable_8.f
|
|
|
237f7c |
|
|
|
237f7c |
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
|
|
|
237f7c |
index 5c8c1b7981b..f7dc9d8263d 100644
|
|
|
237f7c |
--- a/gcc/fortran/decl.c
|
|
|
237f7c |
+++ b/gcc/fortran/decl.c
|
|
|
237f7c |
@@ -1213,6 +1213,54 @@ syntax:
|
|
|
237f7c |
return MATCH_ERROR;
|
|
|
237f7c |
}
|
|
|
237f7c |
|
|
|
237f7c |
+/* This matches the nonstandard kind given after a variable name, like:
|
|
|
237f7c |
+ INTEGER x*2, y*4
|
|
|
237f7c |
+ The per-variable kind will override any kind given in the type
|
|
|
237f7c |
+ declaration.
|
|
|
237f7c |
+*/
|
|
|
237f7c |
+
|
|
|
237f7c |
+static match
|
|
|
237f7c |
+match_per_symbol_kind (int *length)
|
|
|
237f7c |
+{
|
|
|
237f7c |
+ match m;
|
|
|
237f7c |
+ gfc_expr *expr = NULL;
|
|
|
237f7c |
+
|
|
|
237f7c |
+ m = gfc_match_char ('*');
|
|
|
237f7c |
+ if (m != MATCH_YES)
|
|
|
237f7c |
+ return m;
|
|
|
237f7c |
+
|
|
|
237f7c |
+ m = gfc_match_small_literal_int (length, NULL);
|
|
|
237f7c |
+ if (m == MATCH_YES || m == MATCH_ERROR)
|
|
|
237f7c |
+ return m;
|
|
|
237f7c |
+
|
|
|
237f7c |
+ if (gfc_match_char ('(') == MATCH_NO)
|
|
|
237f7c |
+ return MATCH_ERROR;
|
|
|
237f7c |
+
|
|
|
237f7c |
+ m = gfc_match_expr (&expr;;
|
|
|
237f7c |
+ if (m == MATCH_YES)
|
|
|
237f7c |
+ {
|
|
|
237f7c |
+ m = MATCH_ERROR; // Assume error
|
|
|
237f7c |
+ if (gfc_expr_check_typed (expr, gfc_current_ns, false))
|
|
|
237f7c |
+ {
|
|
|
237f7c |
+ if ((expr->expr_type == EXPR_CONSTANT)
|
|
|
237f7c |
+ && (expr->ts.type == BT_INTEGER))
|
|
|
237f7c |
+ {
|
|
|
237f7c |
+ *length = mpz_get_si(expr->value.integer);
|
|
|
237f7c |
+ m = MATCH_YES;
|
|
|
237f7c |
+ }
|
|
|
237f7c |
+ }
|
|
|
237f7c |
+
|
|
|
237f7c |
+ if (m == MATCH_YES)
|
|
|
237f7c |
+ {
|
|
|
237f7c |
+ if (gfc_match_char (')') == MATCH_NO)
|
|
|
237f7c |
+ m = MATCH_ERROR;
|
|
|
237f7c |
+ }
|
|
|
237f7c |
+ }
|
|
|
237f7c |
+
|
|
|
237f7c |
+ if (expr != NULL)
|
|
|
237f7c |
+ gfc_free_expr (expr);
|
|
|
237f7c |
+ return m;
|
|
|
237f7c |
+}
|
|
|
237f7c |
|
|
|
237f7c |
/* Special subroutine for finding a symbol. Check if the name is found
|
|
|
237f7c |
in the current name space. If not, and we're compiling a function or
|
|
|
237f7c |
@@ -2443,6 +2491,35 @@ check_function_name (char *name)
|
|
|
237f7c |
}
|
|
|
237f7c |
|
|
|
237f7c |
|
|
|
237f7c |
+static match
|
|
|
237f7c |
+match_character_length_clause (gfc_charlen **cl, bool *cl_deferred, int elem)
|
|
|
237f7c |
+{
|
|
|
237f7c |
+ gfc_expr* char_len;
|
|
|
237f7c |
+ char_len = NULL;
|
|
|
237f7c |
+
|
|
|
237f7c |
+ match m = match_char_length (&char_len, cl_deferred, false);
|
|
|
237f7c |
+ if (m == MATCH_YES)
|
|
|
237f7c |
+ {
|
|
|
237f7c |
+ *cl = gfc_new_charlen (gfc_current_ns, NULL);
|
|
|
237f7c |
+ (*cl)->length = char_len;
|
|
|
237f7c |
+ }
|
|
|
237f7c |
+ else if (m == MATCH_NO)
|
|
|
237f7c |
+ {
|
|
|
237f7c |
+ if (elem > 1
|
|
|
237f7c |
+ && (current_ts.u.cl->length == NULL
|
|
|
237f7c |
+ || current_ts.u.cl->length->expr_type != EXPR_CONSTANT))
|
|
|
237f7c |
+ {
|
|
|
237f7c |
+ *cl = gfc_new_charlen (gfc_current_ns, NULL);
|
|
|
237f7c |
+ (*cl)->length = gfc_copy_expr (current_ts.u.cl->length);
|
|
|
237f7c |
+ }
|
|
|
237f7c |
+ else
|
|
|
237f7c |
+ *cl = current_ts.u.cl;
|
|
|
237f7c |
+
|
|
|
237f7c |
+ *cl_deferred = current_ts.deferred;
|
|
|
237f7c |
+ }
|
|
|
237f7c |
+ return m;
|
|
|
237f7c |
+}
|
|
|
237f7c |
+
|
|
|
237f7c |
/* Match a variable name with an optional initializer. When this
|
|
|
237f7c |
subroutine is called, a variable is expected to be parsed next.
|
|
|
237f7c |
Depending on what is happening at the moment, updates either the
|
|
|
237f7c |
@@ -2453,7 +2530,7 @@ variable_decl (int elem)
|
|
|
237f7c |
{
|
|
|
237f7c |
char name[GFC_MAX_SYMBOL_LEN + 1];
|
|
|
237f7c |
static unsigned int fill_id = 0;
|
|
|
237f7c |
- gfc_expr *initializer, *char_len;
|
|
|
237f7c |
+ gfc_expr *initializer;
|
|
|
237f7c |
gfc_array_spec *as;
|
|
|
237f7c |
gfc_array_spec *cp_as; /* Extra copy for Cray Pointees. */
|
|
|
237f7c |
gfc_charlen *cl;
|
|
|
237f7c |
@@ -2462,11 +2539,15 @@ variable_decl (int elem)
|
|
|
237f7c |
match m;
|
|
|
237f7c |
bool t;
|
|
|
237f7c |
gfc_symbol *sym;
|
|
|
237f7c |
+ match cl_match;
|
|
|
237f7c |
+ match kind_match;
|
|
|
237f7c |
+ int overridden_kind;
|
|
|
237f7c |
char c;
|
|
|
237f7c |
|
|
|
237f7c |
initializer = NULL;
|
|
|
237f7c |
as = NULL;
|
|
|
237f7c |
cp_as = NULL;
|
|
|
237f7c |
+ kind_match = MATCH_NO;
|
|
|
237f7c |
|
|
|
237f7c |
/* When we get here, we've just matched a list of attributes and
|
|
|
237f7c |
maybe a type and a double colon. The next thing we expect to see
|
|
|
237f7c |
@@ -2519,6 +2600,28 @@ variable_decl (int elem)
|
|
|
237f7c |
|
|
|
237f7c |
var_locus = gfc_current_locus;
|
|
|
237f7c |
|
|
|
237f7c |
+
|
|
|
237f7c |
+ cl = NULL;
|
|
|
237f7c |
+ cl_deferred = false;
|
|
|
237f7c |
+ cl_match = MATCH_NO;
|
|
|
237f7c |
+
|
|
|
237f7c |
+ /* Check for a character length clause before an array clause */
|
|
|
237f7c |
+ if (flag_dec_override_kind)
|
|
|
237f7c |
+ {
|
|
|
237f7c |
+ if (current_ts.type == BT_CHARACTER)
|
|
|
237f7c |
+ {
|
|
|
237f7c |
+ cl_match = match_character_length_clause (&cl, &cl_deferred, elem);
|
|
|
237f7c |
+ if (cl_match == MATCH_ERROR)
|
|
|
237f7c |
+ goto cleanup;
|
|
|
237f7c |
+ }
|
|
|
237f7c |
+ else
|
|
|
237f7c |
+ {
|
|
|
237f7c |
+ kind_match = match_per_symbol_kind (&overridden_kind);
|
|
|
237f7c |
+ if (kind_match == MATCH_ERROR)
|
|
|
237f7c |
+ goto cleanup;
|
|
|
237f7c |
+ }
|
|
|
237f7c |
+ }
|
|
|
237f7c |
+
|
|
|
237f7c |
/* Now we could see the optional array spec. or character length. */
|
|
|
237f7c |
m = gfc_match_array_spec (&as, true, true);
|
|
|
237f7c |
if (m == MATCH_ERROR)
|
|
|
237f7c |
@@ -2667,40 +2770,12 @@ variable_decl (int elem)
|
|
|
237f7c |
}
|
|
|
237f7c |
}
|
|
|
237f7c |
|
|
|
237f7c |
- char_len = NULL;
|
|
|
237f7c |
- cl = NULL;
|
|
|
237f7c |
- cl_deferred = false;
|
|
|
237f7c |
-
|
|
|
237f7c |
- if (current_ts.type == BT_CHARACTER)
|
|
|
237f7c |
+ /* Second chance for a character length clause */
|
|
|
237f7c |
+ if (cl_match == MATCH_NO && current_ts.type == BT_CHARACTER)
|
|
|
237f7c |
{
|
|
|
237f7c |
- switch (match_char_length (&char_len, &cl_deferred, false))
|
|
|
237f7c |
- {
|
|
|
237f7c |
- case MATCH_YES:
|
|
|
237f7c |
- cl = gfc_new_charlen (gfc_current_ns, NULL);
|
|
|
237f7c |
-
|
|
|
237f7c |
- cl->length = char_len;
|
|
|
237f7c |
- break;
|
|
|
237f7c |
-
|
|
|
237f7c |
- /* Non-constant lengths need to be copied after the first
|
|
|
237f7c |
- element. Also copy assumed lengths. */
|
|
|
237f7c |
- case MATCH_NO:
|
|
|
237f7c |
- if (elem > 1
|
|
|
237f7c |
- && (current_ts.u.cl->length == NULL
|
|
|
237f7c |
- || current_ts.u.cl->length->expr_type != EXPR_CONSTANT))
|
|
|
237f7c |
- {
|
|
|
237f7c |
- cl = gfc_new_charlen (gfc_current_ns, NULL);
|
|
|
237f7c |
- cl->length = gfc_copy_expr (current_ts.u.cl->length);
|
|
|
237f7c |
- }
|
|
|
237f7c |
- else
|
|
|
237f7c |
- cl = current_ts.u.cl;
|
|
|
237f7c |
-
|
|
|
237f7c |
- cl_deferred = current_ts.deferred;
|
|
|
237f7c |
-
|
|
|
237f7c |
- break;
|
|
|
237f7c |
-
|
|
|
237f7c |
- case MATCH_ERROR:
|
|
|
237f7c |
- goto cleanup;
|
|
|
237f7c |
- }
|
|
|
237f7c |
+ m = match_character_length_clause (&cl, &cl_deferred, elem);
|
|
|
237f7c |
+ if (m == MATCH_ERROR)
|
|
|
237f7c |
+ goto cleanup;
|
|
|
237f7c |
}
|
|
|
237f7c |
|
|
|
237f7c |
/* The dummy arguments and result of the abreviated form of MODULE
|
|
|
237f7c |
@@ -2802,6 +2877,19 @@ variable_decl (int elem)
|
|
|
237f7c |
goto cleanup;
|
|
|
237f7c |
}
|
|
|
237f7c |
|
|
|
237f7c |
+ if (kind_match == MATCH_YES)
|
|
|
237f7c |
+ {
|
|
|
237f7c |
+ gfc_find_symbol (name, gfc_current_ns, 1, &sym);
|
|
|
237f7c |
+ /* sym *must* be found at this point */
|
|
|
237f7c |
+ sym->ts.kind = overridden_kind;
|
|
|
237f7c |
+ if (gfc_validate_kind (sym->ts.type, sym->ts.kind, true) < 0)
|
|
|
237f7c |
+ {
|
|
|
237f7c |
+ gfc_error ("Kind %d not supported for type %s at %C",
|
|
|
237f7c |
+ sym->ts.kind, gfc_basic_typename (sym->ts.type));
|
|
|
237f7c |
+ return MATCH_ERROR;
|
|
|
237f7c |
+ }
|
|
|
237f7c |
+ }
|
|
|
237f7c |
+
|
|
|
237f7c |
if (!check_function_name (name))
|
|
|
237f7c |
{
|
|
|
237f7c |
m = MATCH_ERROR;
|
|
|
237f7c |
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
|
|
|
237f7c |
index 25cc948699b..4a269ebb22d 100644
|
|
|
237f7c |
--- a/gcc/fortran/lang.opt
|
|
|
237f7c |
+++ b/gcc/fortran/lang.opt
|
|
|
237f7c |
@@ -493,6 +493,10 @@ fdec-non-integer-index
|
|
|
237f7c |
Fortran Var(flag_dec_non_integer_index)
|
|
|
237f7c |
Enable support for non-integer substring indexes.
|
|
|
237f7c |
|
|
|
237f7c |
+fdec-override-kind
|
|
|
237f7c |
+Fortran Var(flag_dec_override_kind)
|
|
|
237f7c |
+Enable support for per variable kind specification.
|
|
|
237f7c |
+
|
|
|
237f7c |
fdec-old-init
|
|
|
237f7c |
Fortran Var(flag_dec_old_init)
|
|
|
237f7c |
Enable support for old style initializers in derived types.
|
|
|
237f7c |
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
|
|
|
237f7c |
index d6bd36c3a8a..edbab483b36 100644
|
|
|
237f7c |
--- a/gcc/fortran/options.c
|
|
|
237f7c |
+++ b/gcc/fortran/options.c
|
|
|
237f7c |
@@ -80,6 +80,7 @@ set_dec_flags (int value)
|
|
|
237f7c |
SET_BITFLAG (flag_dec_duplicates, value, value);
|
|
|
237f7c |
SET_BITFLAG (flag_dec_non_integer_index, value, value);
|
|
|
237f7c |
SET_BITFLAG (flag_dec_old_init, value, value);
|
|
|
237f7c |
+ SET_BITFLAG (flag_dec_override_kind, value, value);
|
|
|
237f7c |
}
|
|
|
237f7c |
|
|
|
237f7c |
/* Finalize DEC flags. */
|
|
|
237f7c |
diff --git a/gcc/testsuite/gfortran.dg/dec_mixed_char_array_declaration_1.f b/gcc/testsuite/gfortran.dg/dec_mixed_char_array_declaration_1.f
|
|
|
237f7c |
new file mode 100644
|
|
|
237f7c |
index 00000000000..706ea4112a4
|
|
|
237f7c |
--- /dev/null
|
|
|
237f7c |
+++ b/gcc/testsuite/gfortran.dg/dec_mixed_char_array_declaration_1.f
|
|
|
237f7c |
@@ -0,0 +1,13 @@
|
|
|
237f7c |
+! { dg-do run }
|
|
|
237f7c |
+! { dg-options "-fdec" }
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Test character declaration with mixed string length and array specification
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Contributed by Jim MacArthur <jim.macarthur@codethink.co.uk>
|
|
|
237f7c |
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
|
|
|
237f7c |
+!
|
|
|
237f7c |
+ PROGRAM character_declaration
|
|
|
237f7c |
+ CHARACTER ASPEC_SLENGTH*2 (5) /'01','02','03','04','05'/
|
|
|
237f7c |
+ CHARACTER SLENGTH_ASPEC(5)*2 /'01','02','03','04','05'/
|
|
|
237f7c |
+ if (ASPEC_SLENGTH(3).NE.SLENGTH_ASPEC(3)) STOP 1
|
|
|
237f7c |
+ END
|
|
|
237f7c |
diff --git a/gcc/testsuite/gfortran.dg/dec_mixed_char_array_declaration_2.f b/gcc/testsuite/gfortran.dg/dec_mixed_char_array_declaration_2.f
|
|
|
237f7c |
new file mode 100644
|
|
|
237f7c |
index 00000000000..26d2acf01de
|
|
|
237f7c |
--- /dev/null
|
|
|
237f7c |
+++ b/gcc/testsuite/gfortran.dg/dec_mixed_char_array_declaration_2.f
|
|
|
237f7c |
@@ -0,0 +1,13 @@
|
|
|
237f7c |
+! { dg-do run }
|
|
|
237f7c |
+! { dg-options "-fdec-override-kind" }
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Test character declaration with mixed string length and array specification
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Contributed by Jim MacArthur <jim.macarthur@codethink.co.uk>
|
|
|
237f7c |
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
|
|
|
237f7c |
+!
|
|
|
237f7c |
+ PROGRAM character_declaration
|
|
|
237f7c |
+ CHARACTER ASPEC_SLENGTH*2 (5) /'01','02','03','04','05'/
|
|
|
237f7c |
+ CHARACTER SLENGTH_ASPEC(5)*2 /'01','02','03','04','05'/
|
|
|
237f7c |
+ if (ASPEC_SLENGTH(3).NE.SLENGTH_ASPEC(3)) STOP 1
|
|
|
237f7c |
+ END
|
|
|
237f7c |
diff --git a/gcc/testsuite/gfortran.dg/dec_mixed_char_array_declaration_3.f b/gcc/testsuite/gfortran.dg/dec_mixed_char_array_declaration_3.f
|
|
|
237f7c |
new file mode 100644
|
|
|
237f7c |
index 00000000000..76e4f0bdb93
|
|
|
237f7c |
--- /dev/null
|
|
|
237f7c |
+++ b/gcc/testsuite/gfortran.dg/dec_mixed_char_array_declaration_3.f
|
|
|
237f7c |
@@ -0,0 +1,13 @@
|
|
|
237f7c |
+! { dg-do compile }
|
|
|
237f7c |
+! { dg-options "-fdec-override-kind -fno-dec-override-kind" }
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Test character declaration with mixed string length and array specification
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Contributed by Jim MacArthur <jim.macarthur@codethink.co.uk>
|
|
|
237f7c |
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
|
|
|
237f7c |
+!
|
|
|
237f7c |
+ PROGRAM character_declaration
|
|
|
237f7c |
+ CHARACTER ASPEC_SLENGTH*2 (5) /'01','02','03','04','05'/ ! { dg-error "Syntax error" }
|
|
|
237f7c |
+ CHARACTER SLENGTH_ASPEC(5)*2 /'01','02','03','04','05'/
|
|
|
237f7c |
+ if (ASPEC_SLENGTH(3).NE.SLENGTH_ASPEC(3)) STOP 1 ! { dg-error " Operands of comparison operator" }
|
|
|
237f7c |
+ END
|
|
|
237f7c |
diff --git a/gcc/testsuite/gfortran.dg/dec_spec_in_variable_1.f b/gcc/testsuite/gfortran.dg/dec_spec_in_variable_1.f
|
|
|
237f7c |
new file mode 100644
|
|
|
237f7c |
index 00000000000..edd0f5874b7
|
|
|
237f7c |
--- /dev/null
|
|
|
237f7c |
+++ b/gcc/testsuite/gfortran.dg/dec_spec_in_variable_1.f
|
|
|
237f7c |
@@ -0,0 +1,31 @@
|
|
|
237f7c |
+! { dg-do run }
|
|
|
237f7c |
+! { dg-options "-fdec" }
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Test kind specification in variable not in type
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Contributed by Mark Eggleston <mark.eggleston@codethink.com>
|
|
|
237f7c |
+!
|
|
|
237f7c |
+ program spec_in_var
|
|
|
237f7c |
+ integer*8 ai*1, bi*4, ci
|
|
|
237f7c |
+ real*4 ar*4, br*8, cr
|
|
|
237f7c |
+
|
|
|
237f7c |
+ ai = 1
|
|
|
237f7c |
+ ar = 1.0
|
|
|
237f7c |
+ bi = 2
|
|
|
237f7c |
+ br = 2.0
|
|
|
237f7c |
+ ci = 3
|
|
|
237f7c |
+ cr = 3.0
|
|
|
237f7c |
+
|
|
|
237f7c |
+ if (ai .ne. 1) stop 1
|
|
|
237f7c |
+ if (abs(ar - 1.0) > 1.0D-6) stop 2
|
|
|
237f7c |
+ if (bi .ne. 2) stop 3
|
|
|
237f7c |
+ if (abs(br - 2.0) > 1.0D-6) stop 4
|
|
|
237f7c |
+ if (ci .ne. 3) stop 5
|
|
|
237f7c |
+ if (abs(cr - 3.0) > 1.0D-6) stop 6
|
|
|
237f7c |
+ if (kind(ai) .ne. 1) stop 7
|
|
|
237f7c |
+ if (kind(ar) .ne. 4) stop 8
|
|
|
237f7c |
+ if (kind(bi) .ne. 4) stop 9
|
|
|
237f7c |
+ if (kind(br) .ne. 8) stop 10
|
|
|
237f7c |
+ if (kind(ci) .ne. 8) stop 11
|
|
|
237f7c |
+ if (kind(cr) .ne. 4) stop 12
|
|
|
237f7c |
+ end
|
|
|
237f7c |
diff --git a/gcc/testsuite/gfortran.dg/dec_spec_in_variable_2.f b/gcc/testsuite/gfortran.dg/dec_spec_in_variable_2.f
|
|
|
237f7c |
new file mode 100644
|
|
|
237f7c |
index 00000000000..bfaba584dbb
|
|
|
237f7c |
--- /dev/null
|
|
|
237f7c |
+++ b/gcc/testsuite/gfortran.dg/dec_spec_in_variable_2.f
|
|
|
237f7c |
@@ -0,0 +1,31 @@
|
|
|
237f7c |
+! { dg-do run }
|
|
|
237f7c |
+! { dg-options "-fdec-override-kind" }
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Test kind specification in variable not in type
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Contributed by Mark Eggleston <mark.eggleston@codethink.com>
|
|
|
237f7c |
+!
|
|
|
237f7c |
+ program spec_in_var
|
|
|
237f7c |
+ integer*8 ai*1, bi*4, ci
|
|
|
237f7c |
+ real*4 ar*4, br*8, cr
|
|
|
237f7c |
+
|
|
|
237f7c |
+ ai = 1
|
|
|
237f7c |
+ ar = 1.0
|
|
|
237f7c |
+ bi = 2
|
|
|
237f7c |
+ br = 2.0
|
|
|
237f7c |
+ ci = 3
|
|
|
237f7c |
+ cr = 3.0
|
|
|
237f7c |
+
|
|
|
237f7c |
+ if (ai .ne. 1) stop 1
|
|
|
237f7c |
+ if (abs(ar - 1.0) > 1.0D-6) stop 2
|
|
|
237f7c |
+ if (bi .ne. 2) stop 3
|
|
|
237f7c |
+ if (abs(br - 2.0) > 1.0D-6) stop 4
|
|
|
237f7c |
+ if (ci .ne. 3) stop 5
|
|
|
237f7c |
+ if (abs(cr - 3.0) > 1.0D-6) stop 6
|
|
|
237f7c |
+ if (kind(ai) .ne. 1) stop 7
|
|
|
237f7c |
+ if (kind(ar) .ne. 4) stop 8
|
|
|
237f7c |
+ if (kind(bi) .ne. 4) stop 9
|
|
|
237f7c |
+ if (kind(br) .ne. 8) stop 10
|
|
|
237f7c |
+ if (kind(ci) .ne. 8) stop 11
|
|
|
237f7c |
+ if (kind(cr) .ne. 4) stop 12
|
|
|
237f7c |
+ end
|
|
|
237f7c |
diff --git a/gcc/testsuite/gfortran.dg/dec_spec_in_variable_3.f b/gcc/testsuite/gfortran.dg/dec_spec_in_variable_3.f
|
|
|
237f7c |
new file mode 100644
|
|
|
237f7c |
index 00000000000..5ff434e7466
|
|
|
237f7c |
--- /dev/null
|
|
|
237f7c |
+++ b/gcc/testsuite/gfortran.dg/dec_spec_in_variable_3.f
|
|
|
237f7c |
@@ -0,0 +1,31 @@
|
|
|
237f7c |
+! { dg-do compile }
|
|
|
237f7c |
+! { dg-options "-fdec -fno-dec-override-kind" }
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Test kind specification in variable not in type
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Contributed by Mark Eggleston <mark.eggleston@codethink.com>
|
|
|
237f7c |
+!
|
|
|
237f7c |
+ program spec_in_var
|
|
|
237f7c |
+ integer*8 ai*1, bi*4, ci ! { dg-error "Syntax error" }
|
|
|
237f7c |
+ real*4 ar*4, br*8, cr ! { dg-error "Syntax error" }
|
|
|
237f7c |
+
|
|
|
237f7c |
+ ai = 1
|
|
|
237f7c |
+ ar = 1.0
|
|
|
237f7c |
+ bi = 2
|
|
|
237f7c |
+ br = 2.0
|
|
|
237f7c |
+ ci = 3
|
|
|
237f7c |
+ cr = 3.0
|
|
|
237f7c |
+
|
|
|
237f7c |
+ if (ai .ne. 1) stop 1
|
|
|
237f7c |
+ if (abs(ar - 1.0) > 1.0D-6) stop 2
|
|
|
237f7c |
+ if (bi .ne. 2) stop 3
|
|
|
237f7c |
+ if (abs(br - 2.0) > 1.0D-6) stop 4
|
|
|
237f7c |
+ if (ci .ne. 3) stop 5
|
|
|
237f7c |
+ if (abs(cr - 3.0) > 1.0D-6) stop 6
|
|
|
237f7c |
+ if (kind(ai) .ne. 1) stop 7
|
|
|
237f7c |
+ if (kind(ar) .ne. 4) stop 8
|
|
|
237f7c |
+ if (kind(bi) .ne. 4) stop 9
|
|
|
237f7c |
+ if (kind(br) .ne. 8) stop 10
|
|
|
237f7c |
+ if (kind(ci) .ne. 8) stop 11
|
|
|
237f7c |
+ if (kind(cr) .ne. 4) stop 12
|
|
|
237f7c |
+ end
|
|
|
237f7c |
diff --git a/gcc/testsuite/gfortran.dg/dec_spec_in_variable_4.f b/gcc/testsuite/gfortran.dg/dec_spec_in_variable_4.f
|
|
|
237f7c |
new file mode 100644
|
|
|
237f7c |
index 00000000000..c01980e8b9d
|
|
|
237f7c |
--- /dev/null
|
|
|
237f7c |
+++ b/gcc/testsuite/gfortran.dg/dec_spec_in_variable_4.f
|
|
|
237f7c |
@@ -0,0 +1,14 @@
|
|
|
237f7c |
+! { dg-do compile }
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Test kind specification in variable not in type. The per variable
|
|
|
237f7c |
+! kind specification is not enabled so these should fail
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Contributed by Mark Eggleston <mark.eggleston@codethink.com>
|
|
|
237f7c |
+!
|
|
|
237f7c |
+ program spec_in_var
|
|
|
237f7c |
+ integer a
|
|
|
237f7c |
+ parameter(a=2)
|
|
|
237f7c |
+ integer b*(a) ! { dg-error "Syntax error" }
|
|
|
237f7c |
+ real c*(8) ! { dg-error "Syntax error" }
|
|
|
237f7c |
+ logical d*1_1 ! { dg-error "Syntax error" }
|
|
|
237f7c |
+ end
|
|
|
237f7c |
diff --git a/gcc/testsuite/gfortran.dg/dec_spec_in_variable_5.f b/gcc/testsuite/gfortran.dg/dec_spec_in_variable_5.f
|
|
|
237f7c |
new file mode 100644
|
|
|
237f7c |
index 00000000000..e2f39da3f4f
|
|
|
237f7c |
--- /dev/null
|
|
|
237f7c |
+++ b/gcc/testsuite/gfortran.dg/dec_spec_in_variable_5.f
|
|
|
237f7c |
@@ -0,0 +1,19 @@
|
|
|
237f7c |
+! { dg-do run }
|
|
|
237f7c |
+! { dg-options "-fdec-override-kind" }
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Test kind specification in variable not in type
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Contributed by Mark Eggleston <mark.eggleston@codethink.com>
|
|
|
237f7c |
+!
|
|
|
237f7c |
+ program spec_in_var
|
|
|
237f7c |
+ integer a
|
|
|
237f7c |
+ parameter(a=2)
|
|
|
237f7c |
+ integer b*(a)
|
|
|
237f7c |
+ real c*(8)
|
|
|
237f7c |
+ logical d*(1_1)
|
|
|
237f7c |
+ character e*(a)
|
|
|
237f7c |
+ if (kind(b).ne.2) stop 1
|
|
|
237f7c |
+ if (kind(c).ne.8) stop 2
|
|
|
237f7c |
+ if (kind(d).ne.1) stop 3
|
|
|
237f7c |
+ if (len(e).ne.2) stop 4
|
|
|
237f7c |
+ end
|
|
|
237f7c |
diff --git a/gcc/testsuite/gfortran.dg/dec_spec_in_variable_6.f b/gcc/testsuite/gfortran.dg/dec_spec_in_variable_6.f
|
|
|
237f7c |
new file mode 100644
|
|
|
237f7c |
index 00000000000..569747874e3
|
|
|
237f7c |
--- /dev/null
|
|
|
237f7c |
+++ b/gcc/testsuite/gfortran.dg/dec_spec_in_variable_6.f
|
|
|
237f7c |
@@ -0,0 +1,19 @@
|
|
|
237f7c |
+! { dg-do run }
|
|
|
237f7c |
+! { dg-options "-fdec" }
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Test kind specification in variable not in type
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Contributed by Mark Eggleston <mark.eggleston@codethink.com>
|
|
|
237f7c |
+!
|
|
|
237f7c |
+ program spec_in_var
|
|
|
237f7c |
+ integer a
|
|
|
237f7c |
+ parameter(a=2)
|
|
|
237f7c |
+ integer b*(a)
|
|
|
237f7c |
+ real c*(8)
|
|
|
237f7c |
+ logical d*(1_1)
|
|
|
237f7c |
+ character e*(a)
|
|
|
237f7c |
+ if (kind(b).ne.2) stop 1
|
|
|
237f7c |
+ if (kind(c).ne.8) stop 2
|
|
|
237f7c |
+ if (kind(d).ne.1) stop 3
|
|
|
237f7c |
+ if (len(e).ne.2) stop 4
|
|
|
237f7c |
+ end
|
|
|
237f7c |
diff --git a/gcc/testsuite/gfortran.dg/dec_spec_in_variable_7.f b/gcc/testsuite/gfortran.dg/dec_spec_in_variable_7.f
|
|
|
237f7c |
new file mode 100644
|
|
|
237f7c |
index 00000000000..b975bfd15c5
|
|
|
237f7c |
--- /dev/null
|
|
|
237f7c |
+++ b/gcc/testsuite/gfortran.dg/dec_spec_in_variable_7.f
|
|
|
237f7c |
@@ -0,0 +1,15 @@
|
|
|
237f7c |
+! { dg-do compile }
|
|
|
237f7c |
+! { dg-options "-fdec -fno-dec-override-kind" }
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Test kind specification in variable not in type as the per variable
|
|
|
237f7c |
+! kind specification is not enables these should fail
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Contributed by Mark Eggleston <mark.eggleston@codethink.com>
|
|
|
237f7c |
+!
|
|
|
237f7c |
+ program spec_in_var
|
|
|
237f7c |
+ integer a
|
|
|
237f7c |
+ parameter(a=2)
|
|
|
237f7c |
+ integer b*(a) ! { dg-error "Syntax error" }
|
|
|
237f7c |
+ real c*(8) ! { dg-error "Syntax error" }
|
|
|
237f7c |
+ logical d*1_1 ! { dg-error "Syntax error" }
|
|
|
237f7c |
+ end
|
|
|
237f7c |
diff --git a/gcc/testsuite/gfortran.dg/dec_spec_in_variable_8.f b/gcc/testsuite/gfortran.dg/dec_spec_in_variable_8.f
|
|
|
237f7c |
new file mode 100644
|
|
|
237f7c |
index 00000000000..85732e0bd85
|
|
|
237f7c |
--- /dev/null
|
|
|
237f7c |
+++ b/gcc/testsuite/gfortran.dg/dec_spec_in_variable_8.f
|
|
|
237f7c |
@@ -0,0 +1,14 @@
|
|
|
237f7c |
+! { dg-do compile }
|
|
|
237f7c |
+! { dg-options "-fdec" }
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Check that invalid kind values are rejected.
|
|
|
237f7c |
+!
|
|
|
237f7c |
+! Contributed by Mark Eggleston <mark.eggleston@codethink.com>
|
|
|
237f7c |
+!
|
|
|
237f7c |
+ program spec_in_var
|
|
|
237f7c |
+ integer a
|
|
|
237f7c |
+ parameter(a=3)
|
|
|
237f7c |
+ integer b*(a) ! { dg-error "Kind 3 not supported" }
|
|
|
237f7c |
+ real c*(78) ! { dg-error "Kind 78 not supported" }
|
|
|
237f7c |
+ logical d*(*) ! { dg-error "Invalid character" }
|
|
|
237f7c |
+ end
|
|
|
237f7c |
--
|
|
|
237f7c |
2.27.0
|
|
|
237f7c |
|