Hi Andre,
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.
We're really talking micro-optimizations here, but well ... ;-)
In the attached patch, I have replaced this with alloca. I was going
to use a VLA originally, but apparently C++ doesn't like that, at least
not in the version that we use within C++.
I think this is the right idiom for a throw-away variable like this.
I also found 15 instances of alloca in fortran, so it is OK to use.
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,
I don't think this would have mattered for an array of char
(these are usually not aligned). However, a pointer using alloca
should be aligned, so this could be used.
So, here's the new version.
OK for all trunk and 5?
2016-02-03 Thomas Koenig <tkoe...@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 <tkoe...@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,30 @@ build_sym (const char *name, gfc_charlen *cl, bool
{
symbol_attribute attr;
gfc_symbol *sym;
+ int nlen;
+ char *u_name;
+ 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 = (char *) alloca (nlen + 1);
+ strncpy (u_name, name, nlen + 1);
+ u_name[0] = TOUPPER(u_name[0]);
+
+ 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