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

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