This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, Fortran] Fix PR 60526, variable name has already been declared as a type
- From: Thomas Koenig <tkoenig at netcologne dot de>
- To: "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 4 Feb 2016 23:03:13 +0100
- Subject: [patch, Fortran] Fix PR 60526, variable name has already been declared as a type
- Authentication-results: sourceware.org; auth=none
Hello world,
For a type 'foo', we use a symtree 'Foo'. This led to accept-invalid
when a variable name was already declared as a type. This rather
self-explanatory patch fixes that.
Regression-tested. OK for trunk and 5? (Do we still care about 4.9?)
Regards
Thomas
2016-02-03 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/60526
* decl.c (build_sym): If the name has already been defined as a
type, issue error and return false.
2016-02-03 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/60526
* gfortran.dg/type_decl_4.f90: New test.
Index: decl.c
===================================================================
--- decl.c (Revision 232864)
+++ decl.c (Arbeitskopie)
@@ -1215,10 +1215,32 @@ build_sym (const char *name, gfc_charlen *cl, bool
{
symbol_attribute attr;
gfc_symbol *sym;
+ char *u_name;
+ int nlen;
+ gfc_symtree *st;
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. */
+
+ nlen = strlen(name);
+
+ u_name = XCNEWVEC(char, nlen+1);
+ u_name[0] = TOUPPER(name[0]);
+ strncpy (u_name+1, name+1, nlen);
+
+ st = gfc_find_symtree (gfc_current_ns->sym_root, u_name);
+ free (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
! { 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