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

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