aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Koenig <tkoenig@gcc.gnu.org>2016-02-14 17:08:44 +0000
committerThomas Koenig <tkoenig@gcc.gnu.org>2016-02-14 17:08:44 +0000
commit1e6025b653fcfbdc34d40ea96bf2336faf0806dd (patch)
treebdbc1c289400224e3b9eb7abffb3b3882b394840
parentd33082792f5c74b212dd44f62aaabf223a692d25 (diff)
downloadgcc-1e6025b653fcfbdc34d40ea96bf2336faf0806dd.zip
gcc-1e6025b653fcfbdc34d40ea96bf2336faf0806dd.tar.gz
gcc-1e6025b653fcfbdc34d40ea96bf2336faf0806dd.tar.bz2
re PR fortran/60526 (Accepts-invalid: Variable name same as type name)
2016-02-14 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/60526 * decl.c (build_sym): If the name has already been defined as a type, it has a symtree with an upper case letter at the beginning. If such a symtree exists, issue an error and exit. Don't do this if there is no corresponding upper case letter. 2016-02-14 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/60526 * gfortran.dg/type_decl_4.f90: Reinstated. From-SVN: r233413
-rw-r--r--gcc/fortran/ChangeLog8
-rw-r--r--gcc/fortran/decl.c28
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/type_decl_4.f907
4 files changed, 48 insertions, 0 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index aa4a028..453e72a 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,6 +1,14 @@
2016-02-14 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/60526
+ * decl.c (build_sym): If the name has already been defined as a
+ type, it has a symtree with an upper case letter at the beginning.
+ If such a symtree exists, issue an error and exit. Don't do
+ this if there is no corresponding upper case letter.
+
+2016-02-14 Thomas Koenig <tkoenig@gcc.gnu.org>
+
+ PR fortran/60526
PR bootstrap/69816
* decl.c (build_sym): Reverted previous patch.
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index df81369..d3ddda2 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -1215,10 +1215,38 @@ build_sym (const char *name, gfc_charlen *cl, bool cl_deferred,
{
symbol_attribute attr;
gfc_symbol *sym;
+ int upper;
if (gfc_get_symbol (name, NULL, &sym))
return false;
+ /* Check if the name has already been defined as a type. The
+ first letter of the symtree will be in upper case then. Of
+ course, this is only necessary if the upper case letter is
+ actually different. */
+
+ upper = TOUPPER(name[0]);
+ if (upper != name[0])
+ {
+ char u_name[GFC_MAX_SYMBOL_LEN + 1];
+ gfc_symtree *st;
+ int nlen;
+
+ nlen = strlen(name);
+ gcc_assert (nlen <= GFC_MAX_SYMBOL_LEN);
+ strncpy (u_name, name, nlen + 1);
+ u_name[0] = upper;
+
+ st = gfc_find_symtree (gfc_current_ns->sym_root, u_name);
+
+ if (st != 0)
+ {
+ gfc_error ("Symbol %qs at %C also declared as a type at %L", name,
+ &st->n.sym->declared_at);
+ return false;
+ }
+ }
+
/* Start updating the symbol table. Add basic type attribute if present. */
if (current_ts.type != BT_UNKNOWN
&& (sym->attr.implicit_type == 0
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f7fd0be..9dfdc76 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2016-02-14 Thomas Koenig <tkoenig@gcc.gnu.org>
+
+ PR fortran/60526
+ * gfortran.dg/type_decl_4.f90: Reinstated.
+
2016-02-14 John David Anglin <danglin@gcc.gnu.org>
PR fortran/68746
diff --git a/gcc/testsuite/gfortran.dg/type_decl_4.f90 b/gcc/testsuite/gfortran.dg/type_decl_4.f90
new file mode 100644
index 0000000..5c3ddb8
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/type_decl_4.f90
@@ -0,0 +1,7 @@
+! { dg-do compile }
+program main
+ type Xx ! { dg-error "Symbol 'xx' at .1. also declared as a type at .2." }
+ end type Xx
+ real :: Xx ! { dg-error "Symbol 'xx' at .1. also declared as a type at .2." }
+
+end program main