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

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