Blame SOURCES/gcc11-fortran-fdec-override-kind.patch

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