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