Blame SOURCES/0009-Allow-old-style-initializers-in-derived-types.patch

9805c9
From 772fea9acdac79164f3496f54ef4f63dd2562a0c Mon Sep 17 00:00:00 2001
9805c9
From: Jim MacArthur <jim.macarthur@codethink.co.uk>
9805c9
Date: Thu, 4 Feb 2016 16:00:30 +0000
9805c9
Subject: [PATCH 09/16] Allow old-style initializers in derived types
9805c9
9805c9
This allows simple declarations in derived types and structures, such as:
9805c9
    LOGICAL*1      NIL      /0/
9805c9
Only single value expressions are allowed at the moment.
9805c9
9805c9
Use -fdec-old-init to enable. Also enabled by -fdec.
9805c9
---
9805c9
 gcc/fortran/decl.c                                 | 27 ++++++++++++++++++----
9805c9
 gcc/fortran/lang.opt                               |  4 ++++
9805c9
 gcc/fortran/options.c                              |  1 +
9805c9
 .../dec_derived_types_initialised_old_style_1.f    | 25 ++++++++++++++++++++
9805c9
 .../dec_derived_types_initialised_old_style_2.f    | 25 ++++++++++++++++++++
9805c9
 .../dec_derived_types_initialised_old_style_3.f    | 26 +++++++++++++++++++++
9805c9
 6 files changed, 103 insertions(+), 5 deletions(-)
9805c9
 create mode 100644 gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_1.f
9805c9
 create mode 100644 gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_2.f
9805c9
 create mode 100644 gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_3.f
9805c9
9805c9
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
9805c9
index 66f1094aa3d..cdf161a7efa 100644
9805c9
--- a/gcc/fortran/decl.c
9805c9
+++ b/gcc/fortran/decl.c
9805c9
@@ -2739,12 +2739,29 @@ variable_decl (int elem)
9805c9
          but not components of derived types.  */
9805c9
       else if (gfc_current_state () == COMP_DERIVED)
9805c9
 	{
9805c9
-	  gfc_error ("Invalid old style initialization for derived type "
9805c9
-		     "component at %C");
9805c9
-	  m = MATCH_ERROR;
9805c9
-	  goto cleanup;
9805c9
+	  if (flag_dec_old_init)
9805c9
+	    {
9805c9
+	      /* Attempt to match an old-style initializer which is a simple
9805c9
+		 integer or character expression; this will not work with
9805c9
+		 multiple values. */
9805c9
+	      m = gfc_match_init_expr (&initializer);
9805c9
+	      if (m == MATCH_ERROR)
9805c9
+		goto cleanup;
9805c9
+	      else if (m == MATCH_YES)
9805c9
+		{
9805c9
+		  m = gfc_match ("/");
9805c9
+		  if (m != MATCH_YES)
9805c9
+		    goto cleanup;
9805c9
+		}
9805c9
+	    }
9805c9
+	  else
9805c9
+	    {
9805c9
+	      gfc_error ("Invalid old style initialization for derived type "
9805c9
+			 "component at %C");
9805c9
+	      m = MATCH_ERROR;
9805c9
+	      goto cleanup;
9805c9
+	    }
9805c9
 	}
9805c9
-
9805c9
       /* For structure components, read the initializer as a special
9805c9
          expression and let the rest of this function apply the initializer
9805c9
          as usual.  */
9805c9
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
9805c9
index 772cf5e81f1..610d91b6cfd 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-old-init
9805c9
+Fortran Var(flag_dec_old_init)
9805c9
+Enable support for old style initializers in derived types.
9805c9
+
9805c9
 fdec-structure
9805c9
 Fortran Var(flag_dec_structure)
9805c9
 Enable support for DEC STRUCTURE/RECORD.
9805c9
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
9805c9
index e0ef03e6cc5..0aa16825980 100644
9805c9
--- a/gcc/fortran/options.c
9805c9
+++ b/gcc/fortran/options.c
9805c9
@@ -80,6 +80,7 @@ set_dec_flags (int value)
9805c9
   SET_BITFLAG (flag_dec_comparisons, value, 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
 }
9805c9
 
9805c9
 /* Finalize DEC flags.  */
9805c9
diff --git a/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_1.f b/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_1.f
9805c9
new file mode 100644
9805c9
index 00000000000..eac4f9bfcf1
9805c9
--- /dev/null
9805c9
+++ b/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_1.f
9805c9
@@ -0,0 +1,25 @@
9805c9
+! { dg-do run }
9805c9
+! { dg-options "-fdec" }
9805c9
+!
9805c9
+! Test old style initializers in derived types
9805c9
+!
9805c9
+! Contributed by Jim MacArthur <jim.macarthur@codethink.co.uk>
9805c9
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
9805c9
+!
9805c9
+        PROGRAM spec_in_var
9805c9
+          TYPE STRUCT1
9805c9
+            INTEGER*4      ID       /8/
9805c9
+            INTEGER*4      TYPE     /5/
9805c9
+            INTEGER*8      DEFVAL   /0/
9805c9
+            CHARACTER*(5)  NAME     /'tests'/
9805c9
+            LOGICAL*1      NIL      /0/
9805c9
+          END TYPE STRUCT1
9805c9
+
9805c9
+          TYPE (STRUCT1) SINST
9805c9
+
9805c9
+          IF(SINST%ID.NE.8) STOP 1
9805c9
+          IF(SINST%TYPE.NE.5) STOP 2
9805c9
+          IF(SINST%DEFVAL.NE.0) STOP 3
9805c9
+          IF(SINST%NAME.NE.'tests') STOP 4
9805c9
+          IF(SINST%NIL) STOP 5
9805c9
+        END
9805c9
diff --git a/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_2.f b/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_2.f
9805c9
new file mode 100644
9805c9
index 00000000000..d904c8b2974
9805c9
--- /dev/null
9805c9
+++ b/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_2.f
9805c9
@@ -0,0 +1,25 @@
9805c9
+! { dg-do run }
9805c9
+! { dg-options "-std=legacy -fdec-old-init" }
9805c9
+!
9805c9
+! Test old style initializers in derived types
9805c9
+!
9805c9
+! Contributed by Jim MacArthur <jim.macarthur@codethink.co.uk>
9805c9
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
9805c9
+!
9805c9
+        PROGRAM spec_in_var
9805c9
+          TYPE STRUCT1
9805c9
+            INTEGER*4      ID       /8/
9805c9
+            INTEGER*4      TYPE     /5/
9805c9
+            INTEGER*8      DEFVAL   /0/
9805c9
+            CHARACTER*(5)  NAME     /'tests'/
9805c9
+            LOGICAL*1      NIL      /0/
9805c9
+          END TYPE STRUCT1
9805c9
+
9805c9
+          TYPE (STRUCT1) SINST
9805c9
+
9805c9
+          IF(SINST%ID.NE.8) STOP 1
9805c9
+          IF(SINST%TYPE.NE.5) STOP 2
9805c9
+          IF(SINST%DEFVAL.NE.0) STOP 3
9805c9
+          IF(SINST%NAME.NE.'tests') STOP 4
9805c9
+          IF(SINST%NIL) STOP 5
9805c9
+        END
9805c9
diff --git a/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_3.f b/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_3.f
9805c9
new file mode 100644
9805c9
index 00000000000..58c2b4b66cf
9805c9
--- /dev/null
9805c9
+++ b/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_3.f
9805c9
@@ -0,0 +1,26 @@
9805c9
+! { dg-do compile }
9805c9
+! { dg-options "-std=legacy -fdec -fno-dec-old-init" }
9805c9
+!
9805c9
+! Test old style initializers in derived types
9805c9
+!
9805c9
+! Contributed by Jim MacArthur <jim.macarthur@codethink.co.uk>
9805c9
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
9805c9
+!
9805c9
+
9805c9
+        PROGRAM spec_in_var
9805c9
+          TYPE STRUCT1
9805c9
+            INTEGER*4      ID       /8/ ! { dg-error "Invalid old style initialization" }
9805c9
+            INTEGER*4      TYPE     /5/ ! { dg-error "Invalid old style initialization" }
9805c9
+            INTEGER*8      DEFVAL   /0/ ! { dg-error "Invalid old style initialization" }
9805c9
+            CHARACTER*(5)  NAME     /'tests'/ ! { dg-error "Invalid old style initialization" }
9805c9
+            LOGICAL*1      NIL      /0/ ! { dg-error "Invalid old style initialization" }
9805c9
+          END TYPE STRUCT1
9805c9
+
9805c9
+          TYPE (STRUCT1) SINST
9805c9
+
9805c9
+          IF(SINST%ID.NE.8) STOP 1 ! { dg-error "'id' at \\(1\\) is not a member" }
9805c9
+          IF(SINST%TYPE.NE.5) STOP 2 ! { dg-error "'type' at \\(1\\) is not a member" }
9805c9
+          IF(SINST%DEFVAL.NE.0) STOP 3  ! { dg-error "'defval' at \\(1\\) is not a member" }
9805c9
+          IF(SINST%NAME.NE.'tests') STOP 4 ! { dg-error "'name' at \\(1\\) is not a member" }
9805c9
+          IF(SINST%NIL) STOP 5 ! { dg-error "'nil' at \\(1\\) is not a member" }
9805c9
+        END
9805c9
-- 
9805c9
2.11.0
9805c9