Blame SOURCES/gcc11-fortran-fdec-old-init.patch

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