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

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