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

237f7c
From 23b1fcb104c666429451ffaf936f8da5fcd3d43a Mon Sep 17 00:00:00 2001
237f7c
From: Mark Eggleston <markeggleston@gcc.gnu.org>
237f7c
Date: Fri, 22 Jan 2021 12:29:47 +0000
237f7c
Subject: [PATCH 01/10] Allow duplicate declarations.
237f7c
237f7c
Enabled by -fdec-duplicates and -fdec.
237f7c
237f7c
Some fixes by Jim MacArthur <jim.macarthur@codethink.co.uk>
237f7c
Addition of -fdec-duplicates by Mark Eggleston <mark.eggleston@codethink.com>
237f7c
---
237f7c
 gcc/fortran/lang.opt                          |  4 ++++
237f7c
 gcc/fortran/options.c                         |  1 +
237f7c
 gcc/fortran/symbol.c                          | 21 +++++++++++++++++--
237f7c
 .../gfortran.dg/duplicate_type_4.f90          | 13 ++++++++++++
237f7c
 .../gfortran.dg/duplicate_type_5.f90          | 13 ++++++++++++
237f7c
 .../gfortran.dg/duplicate_type_6.f90          | 13 ++++++++++++
237f7c
 .../gfortran.dg/duplicate_type_7.f90          | 13 ++++++++++++
237f7c
 .../gfortran.dg/duplicate_type_8.f90          | 12 +++++++++++
237f7c
 .../gfortran.dg/duplicate_type_9.f90          | 12 +++++++++++
237f7c
 9 files changed, 100 insertions(+), 2 deletions(-)
237f7c
 create mode 100644 gcc/testsuite/gfortran.dg/duplicate_type_4.f90
237f7c
 create mode 100644 gcc/testsuite/gfortran.dg/duplicate_type_5.f90
237f7c
 create mode 100644 gcc/testsuite/gfortran.dg/duplicate_type_6.f90
237f7c
 create mode 100644 gcc/testsuite/gfortran.dg/duplicate_type_7.f90
237f7c
 create mode 100644 gcc/testsuite/gfortran.dg/duplicate_type_8.f90
237f7c
 create mode 100644 gcc/testsuite/gfortran.dg/duplicate_type_9.f90
237f7c
237f7c
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
237f7c
index 2b1977c523b..52bd522051e 100644
237f7c
--- a/gcc/fortran/lang.opt
237f7c
+++ b/gcc/fortran/lang.opt
237f7c
@@ -469,6 +469,10 @@ Fortran Var(flag_dec_char_conversions)
237f7c
 Enable the use of character literals in assignments and data statements
237f7c
 for non-character variables.
237f7c
 
237f7c
+fdec-duplicates
237f7c
+Fortran Var(flag_dec_duplicates)
237f7c
+Allow varibles to be duplicated in the type specification matches.
237f7c
+
237f7c
 fdec-include
237f7c
 Fortran Var(flag_dec_include)
237f7c
 Enable legacy parsing of INCLUDE as statement.
237f7c
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
237f7c
index 3a0b98bf1ec..f19ba87f8a0 100644
237f7c
--- a/gcc/fortran/options.c
237f7c
+++ b/gcc/fortran/options.c
237f7c
@@ -77,6 +77,7 @@ set_dec_flags (int value)
237f7c
   SET_BITFLAG (flag_dec_format_defaults, value, value);
237f7c
   SET_BITFLAG (flag_dec_blank_format_item, value, value);
237f7c
   SET_BITFLAG (flag_dec_char_conversions, value, value);
237f7c
+  SET_BITFLAG (flag_dec_duplicates, value, value);
237f7c
 }
237f7c
 
237f7c
 /* Finalize DEC flags.  */
237f7c
diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
237f7c
index 3b988d1be22..9843175cc2a 100644
237f7c
--- a/gcc/fortran/symbol.c
237f7c
+++ b/gcc/fortran/symbol.c
237f7c
@@ -1995,6 +1995,8 @@ gfc_add_type (gfc_symbol *sym, gfc_typespec *ts, locus *where)
237f7c
   if (sym->attr.result && type == BT_UNKNOWN && sym->ns->proc_name)
237f7c
     type = sym->ns->proc_name->ts.type;
237f7c
 
237f7c
+  flavor = sym->attr.flavor;
237f7c
+
237f7c
   if (type != BT_UNKNOWN && !(sym->attr.function && sym->attr.implicit_type)
237f7c
       && !(gfc_state_stack->previous && gfc_state_stack->previous->previous
237f7c
 	   && gfc_state_stack->previous->previous->state == COMP_SUBMODULE)
237f7c
@@ -2007,6 +2009,23 @@ gfc_add_type (gfc_symbol *sym, gfc_typespec *ts, locus *where)
237f7c
       else if (sym->attr.function && sym->attr.result)
237f7c
 	gfc_error ("Symbol %qs at %L already has basic type of %s",
237f7c
 		   sym->ns->proc_name->name, where, gfc_basic_typename (type));
237f7c
+      else if (flag_dec_duplicates)
237f7c
+	{
237f7c
+	  /* Ignore temporaries and class/procedure names */
237f7c
+	  if (sym->ts.type == BT_DERIVED || sym->ts.type == BT_CLASS
237f7c
+	      || sym->ts.type == BT_PROCEDURE)
237f7c
+	    return false;
237f7c
+
237f7c
+	  if (gfc_compare_types (&sym->ts, ts)
237f7c
+	      && (flavor == FL_UNKNOWN || flavor == FL_VARIABLE
237f7c
+	      || flavor == FL_PROCEDURE))
237f7c
+	    {
237f7c
+	      return gfc_notify_std (GFC_STD_LEGACY,
237f7c
+				     "Symbol '%qs' at %L already has "
237f7c
+				     "basic type of %s", sym->name, where,
237f7c
+				     gfc_basic_typename (type));
237f7c
+	    }
237f7c
+	}
237f7c
       else
237f7c
 	gfc_error ("Symbol %qs at %L already has basic type of %s", sym->name,
237f7c
 		   where, gfc_basic_typename (type));
237f7c
@@ -2020,8 +2039,6 @@ gfc_add_type (gfc_symbol *sym, gfc_typespec *ts, locus *where)
237f7c
       return false;
237f7c
     }
237f7c
 
237f7c
-  flavor = sym->attr.flavor;
237f7c
-
237f7c
   if (flavor == FL_PROGRAM || flavor == FL_BLOCK_DATA || flavor == FL_MODULE
237f7c
       || flavor == FL_LABEL
237f7c
       || (flavor == FL_PROCEDURE && sym->attr.subroutine)
237f7c
diff --git a/gcc/testsuite/gfortran.dg/duplicate_type_4.f90 b/gcc/testsuite/gfortran.dg/duplicate_type_4.f90
237f7c
new file mode 100644
237f7c
index 00000000000..cdd29ea8846
237f7c
--- /dev/null
237f7c
+++ b/gcc/testsuite/gfortran.dg/duplicate_type_4.f90
237f7c
@@ -0,0 +1,13 @@
237f7c
+! { dg-do compile }
237f7c
+! { dg-options "-std=f95" }
237f7c
+
237f7c
+! PR fortran/30239
237f7c
+! Check for errors when a symbol gets declared a type twice, even if it
237f7c
+! is the same.
237f7c
+
237f7c
+INTEGER FUNCTION foo ()
237f7c
+  IMPLICIT NONE
237f7c
+  INTEGER :: x
237f7c
+  INTEGER :: x ! { dg-error "basic type of" }
237f7c
+  x = 42
237f7c
+END FUNCTION foo
237f7c
diff --git a/gcc/testsuite/gfortran.dg/duplicate_type_5.f90 b/gcc/testsuite/gfortran.dg/duplicate_type_5.f90
237f7c
new file mode 100644
237f7c
index 00000000000..00f931809aa
237f7c
--- /dev/null
237f7c
+++ b/gcc/testsuite/gfortran.dg/duplicate_type_5.f90
237f7c
@@ -0,0 +1,13 @@
237f7c
+! { dg-do run }
237f7c
+! { dg-options "-fdec" }
237f7c
+!
237f7c
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
237f7c
+!
237f7c
+
237f7c
+program test
237f7c
+  implicit none
237f7c
+  integer :: x
237f7c
+  integer :: x
237f7c
+  x = 42
237f7c
+  if (x /= 42) stop 1
237f7c
+end program test
237f7c
diff --git a/gcc/testsuite/gfortran.dg/duplicate_type_6.f90 b/gcc/testsuite/gfortran.dg/duplicate_type_6.f90
237f7c
new file mode 100644
237f7c
index 00000000000..f0df27e323c
237f7c
--- /dev/null
237f7c
+++ b/gcc/testsuite/gfortran.dg/duplicate_type_6.f90
237f7c
@@ -0,0 +1,13 @@
237f7c
+! { dg-do run }
237f7c
+! { dg-options "-std=legacy -fdec-duplicates" }
237f7c
+!
237f7c
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
237f7c
+!
237f7c
+
237f7c
+program test
237f7c
+  implicit none
237f7c
+  integer :: x
237f7c
+  integer :: x
237f7c
+  x = 42
237f7c
+  if (x /= 42) stop 1
237f7c
+end program test
237f7c
diff --git a/gcc/testsuite/gfortran.dg/duplicate_type_7.f90 b/gcc/testsuite/gfortran.dg/duplicate_type_7.f90
237f7c
new file mode 100644
237f7c
index 00000000000..f32472ff586
237f7c
--- /dev/null
237f7c
+++ b/gcc/testsuite/gfortran.dg/duplicate_type_7.f90
237f7c
@@ -0,0 +1,13 @@
237f7c
+! { dg-do run }
237f7c
+! { dg-options "-fdec-duplicates" }
237f7c
+!
237f7c
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
237f7c
+!
237f7c
+
237f7c
+program test
237f7c
+  implicit none
237f7c
+  integer :: x
237f7c
+  integer :: x! { dg-warning "Legacy Extension" }
237f7c
+  x = 42
237f7c
+  if (x /= 42) stop 1
237f7c
+end program test
237f7c
diff --git a/gcc/testsuite/gfortran.dg/duplicate_type_8.f90 b/gcc/testsuite/gfortran.dg/duplicate_type_8.f90
237f7c
new file mode 100644
237f7c
index 00000000000..23c94add179
237f7c
--- /dev/null
237f7c
+++ b/gcc/testsuite/gfortran.dg/duplicate_type_8.f90
237f7c
@@ -0,0 +1,12 @@
237f7c
+! { dg-do compile }
237f7c
+! { dg-options "-fdec -fno-dec-duplicates" }
237f7c
+!
237f7c
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
237f7c
+!
237f7c
+
237f7c
+integer function foo ()
237f7c
+  implicit none
237f7c
+  integer :: x
237f7c
+  integer :: x ! { dg-error "basic type of" }
237f7c
+  x = 42
237f7c
+end function foo
237f7c
diff --git a/gcc/testsuite/gfortran.dg/duplicate_type_9.f90 b/gcc/testsuite/gfortran.dg/duplicate_type_9.f90
237f7c
new file mode 100644
237f7c
index 00000000000..d5edee4d8ee
237f7c
--- /dev/null
237f7c
+++ b/gcc/testsuite/gfortran.dg/duplicate_type_9.f90
237f7c
@@ -0,0 +1,12 @@
237f7c
+! { dg-do compile }
237f7c
+! { dg-options "-fdec-duplicates -fno-dec-duplicates" }
237f7c
+!
237f7c
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
237f7c
+!
237f7c
+
237f7c
+integer function foo ()
237f7c
+  implicit none
237f7c
+  integer :: x
237f7c
+  integer :: x ! { dg-error "basic type of" }
237f7c
+  x = 42
237f7c
+end function foo
237f7c
-- 
237f7c
2.27.0
237f7c