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

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