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

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