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

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