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

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