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

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