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

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