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

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