Blame SOURCES/0002-Allow-duplicate-declarations.patch

0714f1
From dd2c3c5e8e8370d6e08a87b7122b8fbe4ddf7dde Mon Sep 17 00:00:00 2001
0714f1
From: Mark Doffman <mark.doffman@codethink.co.uk>
0714f1
Date: Tue, 23 Jun 2015 22:59:08 +0000
0714f1
Subject: [PATCH 02/16] Allow duplicate declarations.
0714f1
0714f1
Enabled by -fdec-duplicates and -fdec.
0714f1
0714f1
Some fixes by Jim MacArthur <jim.macarthur@codethink.co.uk>
0714f1
Addition of -fdec-duplicates by Mark Eggleston <mark.eggleston@codethink.com>
0714f1
---
0714f1
 gcc/fortran/lang.opt                           |  4 ++++
0714f1
 gcc/fortran/options.c                          |  1 +
0714f1
 gcc/fortran/symbol.c                           | 23 ++++++++++++++++++++---
0714f1
 gcc/testsuite/gfortran.dg/duplicate_type_4.f90 | 13 +++++++++++++
0714f1
 gcc/testsuite/gfortran.dg/duplicate_type_5.f90 | 13 +++++++++++++
0714f1
 gcc/testsuite/gfortran.dg/duplicate_type_6.f90 | 13 +++++++++++++
0714f1
 gcc/testsuite/gfortran.dg/duplicate_type_7.f90 | 13 +++++++++++++
0714f1
 gcc/testsuite/gfortran.dg/duplicate_type_8.f90 | 12 ++++++++++++
0714f1
 gcc/testsuite/gfortran.dg/duplicate_type_9.f90 | 12 ++++++++++++
0714f1
 9 files changed, 101 insertions(+), 3 deletions(-)
0714f1
 create mode 100644 gcc/testsuite/gfortran.dg/duplicate_type_4.f90
0714f1
 create mode 100644 gcc/testsuite/gfortran.dg/duplicate_type_5.f90
0714f1
 create mode 100644 gcc/testsuite/gfortran.dg/duplicate_type_6.f90
0714f1
 create mode 100644 gcc/testsuite/gfortran.dg/duplicate_type_7.f90
0714f1
 create mode 100644 gcc/testsuite/gfortran.dg/duplicate_type_8.f90
0714f1
 create mode 100644 gcc/testsuite/gfortran.dg/duplicate_type_9.f90
0714f1
0714f1
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
0714f1
index 26e82601b62..491d81ccaa5 100644
0714f1
--- a/gcc/fortran/lang.opt
0714f1
+++ b/gcc/fortran/lang.opt
0714f1
@@ -440,6 +440,10 @@ fdec
0714f1
 Fortran Var(flag_dec)
0714f1
 Enable all DEC language extensions.
0714f1
 
0714f1
+fdec-duplicates
0714f1
+Fortran Var(flag_dec_duplicates)
0714f1
+Allow varibles to be duplicated in the type specification matches.
0714f1
+
0714f1
 fdec-include
0714f1
 Fortran Var(flag_dec_include)
0714f1
 Enable legacy parsing of INCLUDE as statement.
0714f1
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
0714f1
index 4f91486e977..f93db8b6d7c 100644
0714f1
--- a/gcc/fortran/options.c
0714f1
+++ b/gcc/fortran/options.c
0714f1
@@ -75,6 +75,7 @@ set_dec_flags (int value)
0714f1
   SET_BITFLAG (flag_dec_math, value, value);
0714f1
   SET_BITFLAG (flag_dec_include, value, value);
0714f1
   SET_BITFLAG (flag_dec_format_defaults, value, value);
0714f1
+  SET_BITFLAG (flag_dec_duplicates, value, value);
0714f1
 }
0714f1
 
0714f1
 /* Finalize DEC flags.  */
0714f1
diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
0714f1
index ec753229a98..4247b5b60c8 100644
0714f1
--- a/gcc/fortran/symbol.c
0714f1
+++ b/gcc/fortran/symbol.c
0714f1
@@ -1995,6 +1995,8 @@ gfc_add_type (gfc_symbol *sym, gfc_typespec *ts, locus *where)
0714f1
   if (sym->attr.result && type == BT_UNKNOWN && sym->ns->proc_name)
0714f1
     type = sym->ns->proc_name->ts.type;
0714f1
 
0714f1
+  flavor = sym->attr.flavor;
0714f1
+
0714f1
   if (type != BT_UNKNOWN && !(sym->attr.function && sym->attr.implicit_type)
0714f1
       && !(gfc_state_stack->previous && gfc_state_stack->previous->previous
0714f1
 	   && gfc_state_stack->previous->previous->state == COMP_SUBMODULE)
0714f1
@@ -2004,9 +2006,26 @@ gfc_add_type (gfc_symbol *sym, gfc_typespec *ts, locus *where)
0714f1
 	gfc_error ("Symbol %qs at %L conflicts with symbol from module %qs, "
0714f1
 		   "use-associated at %L", sym->name, where, sym->module,
0714f1
 		   &sym->declared_at);
0714f1
+      else if (flag_dec_duplicates)
0714f1
+	{
0714f1
+	  /* Ignore temporaries and class/procedure names */
0714f1
+	  if (sym->ts.type == BT_DERIVED || sym->ts.type == BT_CLASS
0714f1
+	      || sym->ts.type == BT_PROCEDURE)
0714f1
+	    return false;
0714f1
+
0714f1
+	  if (gfc_compare_types (&sym->ts, ts)
0714f1
+	      && (flavor == FL_UNKNOWN || flavor == FL_VARIABLE
0714f1
+	      || flavor == FL_PROCEDURE))
0714f1
+	    {
0714f1
+	      return gfc_notify_std (GFC_STD_LEGACY,
0714f1
+				     "Symbol '%qs' at %L already has "
0714f1
+				     "basic type of %s", sym->name, where,
0714f1
+				     gfc_basic_typename (type));
0714f1
+	    }
0714f1
+	}
0714f1
       else
0714f1
 	gfc_error ("Symbol %qs at %L already has basic type of %s", sym->name,
0714f1
-		 where, gfc_basic_typename (type));
0714f1
+		   where, gfc_basic_typename (type));
0714f1
       return false;
0714f1
     }
0714f1
 
0714f1
@@ -2017,8 +2036,6 @@ gfc_add_type (gfc_symbol *sym, gfc_typespec *ts, locus *where)
0714f1
       return false;
0714f1
     }
0714f1
 
0714f1
-  flavor = sym->attr.flavor;
0714f1
-
0714f1
   if (flavor == FL_PROGRAM || flavor == FL_BLOCK_DATA || flavor == FL_MODULE
0714f1
       || flavor == FL_LABEL
0714f1
       || (flavor == FL_PROCEDURE && sym->attr.subroutine)
0714f1
diff --git a/gcc/testsuite/gfortran.dg/duplicate_type_4.f90 b/gcc/testsuite/gfortran.dg/duplicate_type_4.f90
0714f1
new file mode 100644
0714f1
index 00000000000..cdd29ea8846
0714f1
--- /dev/null
0714f1
+++ b/gcc/testsuite/gfortran.dg/duplicate_type_4.f90
0714f1
@@ -0,0 +1,13 @@
0714f1
+! { dg-do compile }
0714f1
+! { dg-options "-std=f95" }
0714f1
+
0714f1
+! PR fortran/30239
0714f1
+! Check for errors when a symbol gets declared a type twice, even if it
0714f1
+! is the same.
0714f1
+
0714f1
+INTEGER FUNCTION foo ()
0714f1
+  IMPLICIT NONE
0714f1
+  INTEGER :: x
0714f1
+  INTEGER :: x ! { dg-error "basic type of" }
0714f1
+  x = 42
0714f1
+END FUNCTION foo
0714f1
diff --git a/gcc/testsuite/gfortran.dg/duplicate_type_5.f90 b/gcc/testsuite/gfortran.dg/duplicate_type_5.f90
0714f1
new file mode 100644
0714f1
index 00000000000..00f931809aa
0714f1
--- /dev/null
0714f1
+++ b/gcc/testsuite/gfortran.dg/duplicate_type_5.f90
0714f1
@@ -0,0 +1,13 @@
0714f1
+! { dg-do run }
0714f1
+! { dg-options "-fdec" }
0714f1
+!
0714f1
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
0714f1
+!
0714f1
+
0714f1
+program test
0714f1
+  implicit none
0714f1
+  integer :: x
0714f1
+  integer :: x
0714f1
+  x = 42
0714f1
+  if (x /= 42) stop 1
0714f1
+end program test
0714f1
diff --git a/gcc/testsuite/gfortran.dg/duplicate_type_6.f90 b/gcc/testsuite/gfortran.dg/duplicate_type_6.f90
0714f1
new file mode 100644
0714f1
index 00000000000..f0df27e323c
0714f1
--- /dev/null
0714f1
+++ b/gcc/testsuite/gfortran.dg/duplicate_type_6.f90
0714f1
@@ -0,0 +1,13 @@
0714f1
+! { dg-do run }
0714f1
+! { dg-options "-std=legacy -fdec-duplicates" }
0714f1
+!
0714f1
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
0714f1
+!
0714f1
+
0714f1
+program test
0714f1
+  implicit none
0714f1
+  integer :: x
0714f1
+  integer :: x
0714f1
+  x = 42
0714f1
+  if (x /= 42) stop 1
0714f1
+end program test
0714f1
diff --git a/gcc/testsuite/gfortran.dg/duplicate_type_7.f90 b/gcc/testsuite/gfortran.dg/duplicate_type_7.f90
0714f1
new file mode 100644
0714f1
index 00000000000..f32472ff586
0714f1
--- /dev/null
0714f1
+++ b/gcc/testsuite/gfortran.dg/duplicate_type_7.f90
0714f1
@@ -0,0 +1,13 @@
0714f1
+! { dg-do run }
0714f1
+! { dg-options "-fdec-duplicates" }
0714f1
+!
0714f1
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
0714f1
+!
0714f1
+
0714f1
+program test
0714f1
+  implicit none
0714f1
+  integer :: x
0714f1
+  integer :: x! { dg-warning "Legacy Extension" }
0714f1
+  x = 42
0714f1
+  if (x /= 42) stop 1
0714f1
+end program test
0714f1
diff --git a/gcc/testsuite/gfortran.dg/duplicate_type_8.f90 b/gcc/testsuite/gfortran.dg/duplicate_type_8.f90
0714f1
new file mode 100644
0714f1
index 00000000000..23c94add179
0714f1
--- /dev/null
0714f1
+++ b/gcc/testsuite/gfortran.dg/duplicate_type_8.f90
0714f1
@@ -0,0 +1,12 @@
0714f1
+! { dg-do compile }
0714f1
+! { dg-options "-fdec -fno-dec-duplicates" }
0714f1
+!
0714f1
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
0714f1
+!
0714f1
+
0714f1
+integer function foo ()
0714f1
+  implicit none
0714f1
+  integer :: x
0714f1
+  integer :: x ! { dg-error "basic type of" }
0714f1
+  x = 42
0714f1
+end function foo
0714f1
diff --git a/gcc/testsuite/gfortran.dg/duplicate_type_9.f90 b/gcc/testsuite/gfortran.dg/duplicate_type_9.f90
0714f1
new file mode 100644
0714f1
index 00000000000..d5edee4d8ee
0714f1
--- /dev/null
0714f1
+++ b/gcc/testsuite/gfortran.dg/duplicate_type_9.f90
0714f1
@@ -0,0 +1,12 @@
0714f1
+! { dg-do compile }
0714f1
+! { dg-options "-fdec-duplicates -fno-dec-duplicates" }
0714f1
+!
0714f1
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
0714f1
+!
0714f1
+
0714f1
+integer function foo ()
0714f1
+  implicit none
0714f1
+  integer :: x
0714f1
+  integer :: x ! { dg-error "basic type of" }
0714f1
+  x = 42
0714f1
+end function foo
0714f1
-- 
0714f1
2.11.0
0714f1