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

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