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

6b5f7a
From 3a023e34ad6f2aca23079f9306ab6a56c7448896 Mon Sep 17 00:00:00 2001
6b5f7a
From: Mark Eggleston <markeggleston@gcc.gnu.org>
6b5f7a
Date: Mon, 3 Feb 2020 09:18:37 +0000
6b5f7a
Subject: [PATCH 05/10] 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
6b5f7a
index 36326f77569..72194bda4a8 100644
ca6e07
--- a/gcc/fortran/decl.c
ca6e07
+++ b/gcc/fortran/decl.c
6b5f7a
@@ -2813,12 +2813,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
6b5f7a
index 0fea012b7b6..7c53be28a20 100644
ca6e07
--- a/gcc/fortran/lang.opt
ca6e07
+++ b/gcc/fortran/lang.opt
6b5f7a
@@ -489,6 +489,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
6b5f7a
index 8c79a0bd122..c1c7f0bb671 100644
ca6e07
--- a/gcc/fortran/options.c
ca6e07
+++ b/gcc/fortran/options.c
6b5f7a
@@ -79,6 +79,7 @@ set_dec_flags (int value)
6b5f7a
   SET_BITFLAG (flag_dec_char_conversions, value, value);
6b5f7a
   SET_BITFLAG (flag_dec_duplicates, 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