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

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