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

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