From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23480 invoked by alias); 9 Nov 2007 12:44:24 -0000 Received: (qmail 23429 invoked by alias); 9 Nov 2007 12:44:14 -0000 Date: Fri, 09 Nov 2007 12:44:00 -0000 Message-ID: <20071109124414.23428.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug fortran/30285] gfortran excessive memory usage with COMMON blocks in modules In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "Tobias dot Schlueter at physik dot uni-muenchen dot de" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-11/txt/msg00784.txt.bz2 ------- 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