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

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