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

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