Blame SOURCES/0009-Add-the-SEQUENCE-attribute-by-default-if-it-s-not.patch

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