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

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