------- Comment #15 from Tobias dot Schlueter at physik dot uni-muenchen dot de 2007-11-09 12:44 ------- Subject: Re: gfortran excessive memory usage with COMMON blocks in modules
fxcoudert at gcc dot gnu dot org wrote: > Because in that case, mod2.mod already has two copies of the common: > > (('mpipriv' 2 0 0 'mpipriv') ('mpipriv' 2 0 0 'mpipriv')) > > and I don't think that's desirable. I think that the module loading is > actually > wrong here: the code in gfc_get_common (match.c) takes special care to > duplicate this common name by creating a unique name for it. While I believe > that mangling is necessary, the mangled name shouldn't be unique but simply > prefixed, so that of the same name are merged, while prevented to clash with > the namespace of the use'ing procedure. I wrote this code originally, and I agree with your analysis. > Index: match.c > =================================================================== > --- match.c (revision 129869) > +++ match.c (working copy) > @@ -2608,23 +2608,19 @@ gfc_common_head * > gfc_get_common (const char *name, int from_module) > { > gfc_symtree *st; > - static int serial = 0; > - char mangled_name[GFC_MAX_SYMBOL_LEN + 1]; > + char mangled_name[GFC_MAX_SYMBOL_LEN + 12]; Should be + 13 (need one char for '\0'). > + /* A use associated common block is only needed to correctly layout > + the variables it contains. */ > + snprintf (mangled_name, GFC_MAX_SYMBOL_LEN, "_frommodule_%s", name); GFC_MAX_SYMBOL_LEN + 12, otherwise you could create ambiguities with really long common names. Previously this wasn't possible due to the serial number. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30285