Blame SOURCES/0006-Allow-string-length-and-kind-to-be-specified-on-a-pe.patch

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