Message ID | 56B3CAA1.8090807@netcologne.de |
---|---|
State | New |
Headers | show |
Hi Thomas, please note: This is not a review. I don't have the privileges to do so. In preventing memory clutter I like to advise the use of: char u_name[GFC_MAX_SYMBOL_LEN + 1]; and safe us all the dynamic memory allocation/free. Furthermore, how about switching: strncpy (u_name, name, nlen+ 1); u_name[0] = TOUPPER(u_name[0]); that way strncpy() can use its full power and copy aligned data using longs, vector instructions or whatever. At least it has the potential. with (u_)name+1 we always have an uneven start address and I doubt strncpy can use an optimized copy algorithm. I know, that now we copy one byte twice, but that shouldn't really matter. Besides my ideas above the patch and test looks ok to me (I didn't do a regtest though). Regards, Andre On Thu, 4 Feb 2016 23:03:13 +0100 Thomas Koenig <tkoenig@netcologne.de> wrote: > 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