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

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