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

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