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

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