Blame SOURCES/0001-Allow-duplicate-declarations.patch

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