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

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