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

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