Blame SOURCES/gcc11-fortran-fdec-sequence.patch

237f7c
From bb76446db10c21860a4e19569ce3e350d8a2b59f Mon Sep 17 00:00:00 2001
237f7c
From: Mark Eggleston <markeggleston@gcc.gnu.org>
237f7c
Date: Fri, 22 Jan 2021 15:00:44 +0000
237f7c
Subject: [PATCH 09/10] Add the SEQUENCE attribute by default if it's not
237f7c
 present.
237f7c
237f7c
Use -fdec-sequence to enable this feature. Also enabled by -fdec.
237f7c
---
237f7c
 gcc/fortran/lang.opt                          |  4 ++
237f7c
 gcc/fortran/options.c                         |  1 +
237f7c
 gcc/fortran/resolve.c                         | 13 ++++-
237f7c
 ...dd_SEQUENCE_to_COMMON_block_by_default_1.f | 57 +++++++++++++++++++
237f7c
 ...dd_SEQUENCE_to_COMMON_block_by_default_2.f | 57 +++++++++++++++++++
237f7c
 ...dd_SEQUENCE_to_COMMON_block_by_default_3.f | 57 +++++++++++++++++++
237f7c
 6 files changed, 186 insertions(+), 3 deletions(-)
237f7c
 create mode 100644 gcc/testsuite/gfortran.dg/dec_add_SEQUENCE_to_COMMON_block_by_default_1.f
237f7c
 create mode 100644 gcc/testsuite/gfortran.dg/dec_add_SEQUENCE_to_COMMON_block_by_default_2.f
237f7c
 create mode 100644 gcc/testsuite/gfortran.dg/dec_add_SEQUENCE_to_COMMON_block_by_default_3.f
237f7c
237f7c
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
237f7c
index 4ca2f93f2df..019c798cf09 100644
237f7c
--- a/gcc/fortran/lang.opt
237f7c
+++ b/gcc/fortran/lang.opt
237f7c
@@ -509,6 +509,10 @@ fdec-promotion
237f7c
 Fortran Var(flag_dec_promotion)
237f7c
 Add support for type promotion in intrinsic arguments.
237f7c
 
237f7c
+fdec-sequence
237f7c
+Fortran Var(flag_dec_sequence)
237f7c
+Add the SEQUENCE attribute by default if it's not present.
237f7c
+
237f7c
 fdec-structure
237f7c
 Fortran Var(flag_dec_structure)
237f7c
 Enable support for DEC STRUCTURE/RECORD.
237f7c
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
237f7c
index 15079c7e95a..050f56fdc25 100644
237f7c
--- a/gcc/fortran/options.c
237f7c
+++ b/gcc/fortran/options.c
237f7c
@@ -83,6 +83,7 @@ set_dec_flags (int value)
237f7c
   SET_BITFLAG (flag_dec_override_kind, value, value);
237f7c
   SET_BITFLAG (flag_dec_non_logical_if, value, value);
237f7c
   SET_BITFLAG (flag_dec_promotion, value, value);
237f7c
+  SET_BITFLAG (flag_dec_sequence, value, value);
237f7c
 }
237f7c
 
237f7c
 /* Finalize DEC flags.  */
237f7c
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
237f7c
index 07dd039f3bf..fe7d0cc5944 100644
237f7c
--- a/gcc/fortran/resolve.c
237f7c
+++ b/gcc/fortran/resolve.c
237f7c
@@ -978,9 +978,16 @@ resolve_common_vars (gfc_common_head *common_block, bool named_common)
237f7c
 
237f7c
       if (!(csym->ts.u.derived->attr.sequence
237f7c
 	    || csym->ts.u.derived->attr.is_bind_c))
237f7c
-	gfc_error_now ("Derived type variable %qs in COMMON at %L "
237f7c
-		       "has neither the SEQUENCE nor the BIND(C) "
237f7c
-		       "attribute", csym->name, &csym->declared_at);
237f7c
+	{
237f7c
+	  if (flag_dec_sequence)
237f7c
+	    /* Assume sequence. */
237f7c
+	    csym->ts.u.derived->attr.sequence = 1;
237f7c
+	  else
237f7c
+	    gfc_error_now ("Derived type variable '%s' in COMMON at %L "
237f7c
+			   "has neither the SEQUENCE nor the BIND(C) "
237f7c
+			   "attribute", csym->name, &csym->declared_at);
237f7c
+	}
237f7c
+
237f7c
       if (csym->ts.u.derived->attr.alloc_comp)
237f7c
 	gfc_error_now ("Derived type variable %qs in COMMON at %L "
237f7c
 		       "has an ultimate component that is "
237f7c
diff --git a/gcc/testsuite/gfortran.dg/dec_add_SEQUENCE_to_COMMON_block_by_default_1.f b/gcc/testsuite/gfortran.dg/dec_add_SEQUENCE_to_COMMON_block_by_default_1.f
237f7c
new file mode 100644
237f7c
index 00000000000..fe7b39625eb
237f7c
--- /dev/null
237f7c
+++ b/gcc/testsuite/gfortran.dg/dec_add_SEQUENCE_to_COMMON_block_by_default_1.f
237f7c
@@ -0,0 +1,57 @@
237f7c
+! { dg-do run }
237f7c
+! { dg-options "-fdec" }
237f7c
+!
237f7c
+! Test add default SEQUENCE attribute derived types appearing in
237f7c
+! COMMON blocks and EQUIVALENCE statements.
237f7c
+!
237f7c
+! Contributed by Francisco Redondo Marchena <francisco.marchena@codethink.co.uk>
237f7c
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
237f7c
+!
237f7c
+        MODULE SEQ
237f7c
+          TYPE STRUCT1
237f7c
+            INTEGER*4     ID
237f7c
+            INTEGER*4     TYPE
237f7c
+            INTEGER*8     DEFVAL
237f7c
+            CHARACTER*(4) NAME
237f7c
+            LOGICAL*1     NIL
237f7c
+          END TYPE STRUCT1
237f7c
+        END MODULE
237f7c
+
237f7c
+        SUBROUTINE A
237f7c
+          USE SEQ
237f7c
+          TYPE (STRUCT1) S
237f7c
+          COMMON /BLOCK1/ S
237f7c
+          IF (S%ID.NE.5) STOP 1
237f7c
+          IF (S%TYPE.NE.1000) STOP 2
237f7c
+          IF (S%DEFVAL.NE.-99) STOP 3
237f7c
+          IF (S%NAME.NE."JANE") STOP 4
237f7c
+          IF (S%NIL.NEQV..FALSE.) STOP 5
237f7c
+        END SUBROUTINE
237f7c
+
237f7c
+        PROGRAM sequence_att_common
237f7c
+          USE SEQ
237f7c
+          IMPLICIT NONE
237f7c
+          TYPE (STRUCT1) S1
237f7c
+          TYPE (STRUCT1) S2
237f7c
+          TYPE (STRUCT1) S3
237f7c
+
237f7c
+          EQUIVALENCE (S1,S2)
237f7c
+          COMMON /BLOCK1/ S3
237f7c
+
237f7c
+          S1%ID = 5
237f7c
+          S1%TYPE = 1000
237f7c
+          S1%DEFVAL = -99
237f7c
+          S1%NAME = "JANE"
237f7c
+          S1%NIL = .FALSE.
237f7c
+
237f7c
+          IF (S2%ID.NE.5) STOP 1
237f7c
+          IF (S2%TYPE.NE.1000) STOP 2
237f7c
+          IF (S2%DEFVAL.NE.-99) STOP 3
237f7c
+          IF (S2%NAME.NE."JANE") STOP 4
237f7c
+          IF (S2%NIL.NEQV..FALSE.) STOP 5
237f7c
+
237f7c
+          S3 = S1
237f7c
+
237f7c
+          CALL A
237f7c
+          
237f7c
+        END
237f7c
diff --git a/gcc/testsuite/gfortran.dg/dec_add_SEQUENCE_to_COMMON_block_by_default_2.f b/gcc/testsuite/gfortran.dg/dec_add_SEQUENCE_to_COMMON_block_by_default_2.f
237f7c
new file mode 100644
237f7c
index 00000000000..83512f0f3a2
237f7c
--- /dev/null
237f7c
+++ b/gcc/testsuite/gfortran.dg/dec_add_SEQUENCE_to_COMMON_block_by_default_2.f
237f7c
@@ -0,0 +1,57 @@
237f7c
+! { dg-do run }
237f7c
+! { dg-options "-fdec-sequence" }
237f7c
+!
237f7c
+! Test add default SEQUENCE attribute derived types appearing in
237f7c
+! COMMON blocks and EQUIVALENCE statements.
237f7c
+!
237f7c
+! Contributed by Francisco Redondo Marchena <francisco.marchena@codethink.co.uk>
237f7c
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
237f7c
+!
237f7c
+        MODULE SEQ
237f7c
+          TYPE STRUCT1
237f7c
+            INTEGER*4     ID
237f7c
+            INTEGER*4     TYPE
237f7c
+            INTEGER*8     DEFVAL
237f7c
+            CHARACTER*(4) NAME
237f7c
+            LOGICAL*1     NIL
237f7c
+          END TYPE STRUCT1
237f7c
+        END MODULE
237f7c
+
237f7c
+        SUBROUTINE A
237f7c
+          USE SEQ
237f7c
+          TYPE (STRUCT1) S
237f7c
+          COMMON /BLOCK1/ S
237f7c
+          IF (S%ID.NE.5) STOP 1
237f7c
+          IF (S%TYPE.NE.1000) STOP 2
237f7c
+          IF (S%DEFVAL.NE.-99) STOP 3
237f7c
+          IF (S%NAME.NE."JANE") STOP 4
237f7c
+          IF (S%NIL.NEQV..FALSE.) STOP 5
237f7c
+        END SUBROUTINE
237f7c
+
237f7c
+        PROGRAM sequence_att_common
237f7c
+          USE SEQ
237f7c
+          IMPLICIT NONE
237f7c
+          TYPE (STRUCT1) S1
237f7c
+          TYPE (STRUCT1) S2
237f7c
+          TYPE (STRUCT1) S3
237f7c
+
237f7c
+          EQUIVALENCE (S1,S2)
237f7c
+          COMMON /BLOCK1/ S3
237f7c
+
237f7c
+          S1%ID = 5
237f7c
+          S1%TYPE = 1000
237f7c
+          S1%DEFVAL = -99
237f7c
+          S1%NAME = "JANE"
237f7c
+          S1%NIL = .FALSE.
237f7c
+
237f7c
+          IF (S2%ID.NE.5) STOP 1
237f7c
+          IF (S2%TYPE.NE.1000) STOP 2
237f7c
+          IF (S2%DEFVAL.NE.-99) STOP 3
237f7c
+          IF (S2%NAME.NE."JANE") STOP 4
237f7c
+          IF (S2%NIL.NEQV..FALSE.) STOP 5
237f7c
+
237f7c
+          S3 = S1
237f7c
+
237f7c
+          CALL A
237f7c
+          
237f7c
+        END
237f7c
diff --git a/gcc/testsuite/gfortran.dg/dec_add_SEQUENCE_to_COMMON_block_by_default_3.f b/gcc/testsuite/gfortran.dg/dec_add_SEQUENCE_to_COMMON_block_by_default_3.f
237f7c
new file mode 100644
237f7c
index 00000000000..26cd59f9090
237f7c
--- /dev/null
237f7c
+++ b/gcc/testsuite/gfortran.dg/dec_add_SEQUENCE_to_COMMON_block_by_default_3.f
237f7c
@@ -0,0 +1,57 @@
237f7c
+! { dg-do compile }
237f7c
+! { dg-options "-fdec -fno-dec-sequence" }
237f7c
+!
237f7c
+! Test add default SEQUENCE attribute derived types appearing in
237f7c
+! COMMON blocks and EQUIVALENCE statements.
237f7c
+!
237f7c
+! Contributed by Francisco Redondo Marchena <francisco.marchena@codethink.co.uk>
237f7c
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
237f7c
+!
237f7c
+        MODULE SEQ
237f7c
+          TYPE STRUCT1
237f7c
+            INTEGER*4     ID
237f7c
+            INTEGER*4     TYPE
237f7c
+            INTEGER*8     DEFVAL
237f7c
+            CHARACTER*(4) NAME
237f7c
+            LOGICAL*1     NIL
237f7c
+          END TYPE STRUCT1
237f7c
+        END MODULE
237f7c
+
237f7c
+        SUBROUTINE A
237f7c
+          USE SEQ
237f7c
+          TYPE (STRUCT1) S ! { dg-error "Derived type variable" }
237f7c
+          COMMON /BLOCK1/ S
237f7c
+          IF (S%ID.NE.5) STOP 1
237f7c
+          IF (S%TYPE.NE.1000) STOP 2
237f7c
+          IF (S%DEFVAL.NE.-99) STOP 3
237f7c
+          IF (S%NAME.NE."JANE") STOP 4
237f7c
+          IF (S%NIL.NEQV..FALSE.) STOP 5
237f7c
+        END SUBROUTINE
237f7c
+
237f7c
+        PROGRAM sequence_att_common
237f7c
+          USE SEQ
237f7c
+          IMPLICIT NONE
237f7c
+          TYPE (STRUCT1) S1
237f7c
+          TYPE (STRUCT1) S2
237f7c
+          TYPE (STRUCT1) S3 ! { dg-error "Derived type variable" }
237f7c
+
237f7c
+          EQUIVALENCE (S1,S2) ! { dg-error "Derived type variable" }
237f7c
+          COMMON /BLOCK1/ S3
237f7c
+
237f7c
+          S1%ID = 5
237f7c
+          S1%TYPE = 1000
237f7c
+          S1%DEFVAL = -99
237f7c
+          S1%NAME = "JANE"
237f7c
+          S1%NIL = .FALSE.
237f7c
+
237f7c
+          IF (S2%ID.NE.5) STOP 1
237f7c
+          IF (S2%TYPE.NE.1000) STOP 2
237f7c
+          IF (S2%DEFVAL.NE.-99) STOP 3
237f7c
+          IF (S2%NAME.NE."JANE") STOP 4
237f7c
+          IF (S2%NIL.NEQV..FALSE.) STOP 5
237f7c
+
237f7c
+          S3 = S1
237f7c
+
237f7c
+          CALL A
237f7c
+          
237f7c
+        END
237f7c
-- 
237f7c
2.27.0
237f7c