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