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

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