This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, fortran] PR30554 - ICE in mio_pointer_ref at module.c:1945


Paul Thomas wrote:
:ADDPATCH fortran:

I have been worrying at this one for a few minutes every day, since Tobias posted it. Since I had set myself the target of reforming modules and introducing sub-modules, over the next few months, I thought that there would be no hope of achieving these ambitions if I could not fix this bug :-)

Fortunately for my self-esteem, Tobias had posted the key clue by noticing that deleting the USE ATOMS in potential_energy cured the fault. Also, interchanging the USE statements does likewise. Thus, although the segfault occurs on writing the module, the problem is with reading the modules that it uses. Noting that it is a missing symtree that causes the segfault, we right away suspect the reading of the symtree entries from the module file.

It turns out that, since find_use_name_n returns NULL for a name that is excluded from an ONLY clause, no check is made to see if there is an existing symtree for this symbol. If this check is not done, the pointer_info gets marked as NEEDED but has no symtree attached to it. This is cured by checking if there is a symtree associated with the true_name and attaching that to the pointer_info. Note that the symbol cannot be ambiguous in this case because it did not appear in the ONLY clause.

The testcase is that of the reporter and is not modified, apart from being festooned with dejagnuery.

Bootstrapped and regtested on ia64/FC5 - OK for trunk and, after a week or two, for 4.2?

Paul


------------------------------------------------------------------------


2007-01-28 Paul Thomas <pault@gcc.gnu.org>

	PR fortran/30554
	* module.c (read_module): If a symbol is excluded by an ONLY
	clause, check to see if there is a symtree already loaded. If
	so, attach the symtree to the pointer_info.

2007-01-28 Paul Thomas <pault@gcc.gnu.org>

	PR fortran/30554
	* gfortran.dg/used_dummy_types_6.f90: New test.


------------------------------------------------------------------------


Index: gcc/fortran/module.c
===================================================================
*** gcc/fortran/module.c (revision 121234)
--- gcc/fortran/module.c (working copy)
*************** read_module (void)
*** 3394,3408 ****
/* Get the jth local name for this symbol. */
p = find_use_name_n (name, &j);
! /* Skip symtree nodes not in an ONLY clause. */
if (p == NULL)
! continue;
- /* Check for ambiguous symbols. */
st = gfc_find_symtree (gfc_current_ns->sym_root, p);
if (st != NULL)
{
if (st->n.sym != info->u.rsym.sym)
st->ambiguous = 1;
info->u.rsym.symtree = st;
--- 3394,3414 ----
/* Get the jth local name for this symbol. */
p = find_use_name_n (name, &j);
! /* Skip symtree nodes not in an ONLY clause, unless there
! is an existing symtree loaded from another USE. */
if (p == NULL)
! {
! st = gfc_find_symtree (gfc_current_ns->sym_root, name);
! if (st != NULL)
! info->u.rsym.symtree = st;
! continue;
! }
st = gfc_find_symtree (gfc_current_ns->sym_root, p);
if (st != NULL)
{
+ /* Check for ambiguous symbols. */
if (st->n.sym != info->u.rsym.sym)
st->ambiguous = 1;
info->u.rsym.symtree = st;
Index: gcc/testsuite/gfortran.dg/used_dummy_types_6.f90
===================================================================
*** gcc/testsuite/gfortran.dg/used_dummy_types_6.f90 (revision 0)
--- gcc/testsuite/gfortran.dg/used_dummy_types_6.f90 (revision 0)
***************
*** 0 ****
--- 1,25 ----
+ ! { dg-do compile }
+ ! Tests the fix for PR30554, the USE statements in potential_energy
+ ! would cause a segfault because the pointer_info for nfree coming
+ ! from constraint woul not find the existing symtree coming directly
+ ! from atom.
+ !
+ ! Contributed by Tobias Burnus <burnus@gcc.gnu.org>
+ + MODULE ATOMS
+ INTEGER :: NFREE = 0
+ END MODULE ATOMS
+ + MODULE CONSTRAINT
+ USE ATOMS, ONLY: NFREE
+ CONTAINS
+ SUBROUTINE ENERGY_CONSTRAINT ( HESSIAN )
+ REAL , DIMENSION(1:(3*NFREE*(3*NFREE+1))/2):: HESSIAN
+ END SUBROUTINE ENERGY_CONSTRAINT
+ END MODULE CONSTRAINT
+ + MODULE POTENTIAL_ENERGY
+ USE ATOMS
+ USE CONSTRAINT, ONLY : ENERGY_CONSTRAINT
+ END MODULE POTENTIAL_ENERGY
+ ! { dg-final { cleanup-modules "atoms constraint potential_energy" } }

This is OK for trunk and the usual wait for 4.2.


Jerry


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]