and module name. This is used to construct unique names for the class
containers and vtab symbols. */
-static void
-get_unique_type_string (char *string, gfc_symbol *derived)
+static char *
+get_unique_type_string (gfc_symbol *derived)
{
const char *dt_name;
+ char *string;
+ size_t len;
if (derived->attr.unlimited_polymorphic)
dt_name = "STAR";
else
dt_name = gfc_dt_upper_string (derived->name);
+ len = strlen (dt_name) + 2;
if (derived->attr.unlimited_polymorphic)
- sprintf (string, "_%s", dt_name);
+ {
+ string = XNEWVEC (char, len);
+ sprintf (string, "_%s", dt_name);
+ }
else if (derived->module)
- sprintf (string, "%s_%s", derived->module, dt_name);
+ {
+ string = XNEWVEC (char, strlen (derived->module) + len);
+ sprintf (string, "%s_%s", derived->module, dt_name);
+ }
else if (derived->ns->proc_name)
- sprintf (string, "%s_%s", derived->ns->proc_name->name, dt_name);
+ {
+ string = XNEWVEC (char, strlen (derived->ns->proc_name->name) + len);
+ sprintf (string, "%s_%s", derived->ns->proc_name->name, dt_name);
+ }
else
- sprintf (string, "_%s", dt_name);
+ {
+ string = XNEWVEC (char, len);
+ sprintf (string, "_%s", dt_name);
+ }
+ return string;
}
get_unique_hashed_string (char *string, gfc_symbol *derived)
{
/* Provide sufficient space to hold "symbol.symbol_symbol". */
- char tmp[3*GFC_MAX_SYMBOL_LEN+3];
- get_unique_type_string (&tmp[0], derived);
- size_t len = strnlen (tmp, sizeof (tmp));
- gcc_assert (len < sizeof (tmp));
+ char *tmp;
+ tmp = get_unique_type_string (derived);
/* If string is too long, use hash value in hex representation (allow for
extra decoration, cf. gfc_build_class_symbol & gfc_find_derived_vtab).
We need space to for 15 characters "__class_" + symbol name + "_%d_%da",
}
else
strcpy (string, tmp);
+ free (tmp);
}
{
unsigned int hash = 0;
/* Provide sufficient space to hold "symbol.symbol_symbol". */
- char c[3*GFC_MAX_SYMBOL_LEN+3];
+ char *c;
int i, len;
- get_unique_type_string (&c[0], sym);
- len = strnlen (c, sizeof (c));
- gcc_assert ((size_t) len < sizeof (c));
+ c = get_unique_type_string (sym);
+ len = strlen (c);
for (i = 0; i < len; i++)
hash = (hash << 6) + (hash << 16) - hash + c[i];
+ free (c);
/* Return the hash but take the modulus for the sake of module read,
even though this slightly increases the chance of collision. */
return (hash % 100000000);
--- /dev/null
+! { dg-do compile }
+! { dg-options "-fsecond-underscore" }
+! PR fortran/95687 - ICE in get_unique_hashed_string, at fortran/class.c:508
+
+module m2345678901234567890123456789012345678901234567890123456789_123
+ interface
+ module subroutine s2345678901234567890123456789012345678901234567890123456789_123
+ end
+ end interface
+end
+submodule(m2345678901234567890123456789012345678901234567890123456789_123) &
+ n2345678901234567890123456789012345678901234567890123456789_123
+ type t2345678901234567890123456789012345678901234567890123456789_123 &
+ (a2345678901234567890123456789012345678901234567890123456789_123)
+ integer, kind :: a2345678901234567890123456789012345678901234567890123456789_123 = 4
+ end type
+ class(t2345678901234567890123456789012345678901234567890123456789_123(3)), pointer :: &
+ x2345678901234567890123456789012345678901234567890123456789_123
+end