type-bound procedures, use association, and rogue namespaces
Steve Kargl
sgk@troutmask.apl.washington.edu
Thu Jun 13 19:55:00 GMT 2019
So, I've taken a look at PR 89647, and it seems that
the mechanism for resolving type-bound procedures does
not know about USE association. In resolve.c,
resolve_typebound_procedure() at lines 13540 (or so)
we have a type-bound entity, but its symbol has not
been resolved. I've added this bit of code (sorry
about whitespace)
if (!proc->resolved
&& proc->attr.function == 0 && proc->attr.subroutine == 0)
{
gfc_symbol *tmp;
gfc_find_symbol (proc->name, gfc_current_ns->parent, 1, &tmp);
proc = tmp;
}
which actually finds the USE associated symbol. With Ian's
code and setting a breakpoint in gdb
(gdb) b resolve.c:13545
Breakpoint 1 at 0x85c618: file ../../gccx/gcc/fortran/resolve.c, line 13545.
(gdb) run a.f90
Starting program: /safe/sgk/work/x/libexec/gcc/x86_64-unknown-freebsd13.0/10.0.0/f951 a.f90
Breakpoint 1, resolve_typebound_procedure (stree=0x2023feb10)
at ../../gccx/gcc/fortran/resolve.c:13545
13545 proc = tmp;
(gdb) p stree->n.tb->u.specific->n.sym
$1 = (gfc_symbol *) 0x202eceb00
(gdb) p proc
$2 = (gfc_symbol *) 0x202eceb00
(gdb) p tmp
$3 = (gfc_symbol *) 0x202ecdf00
(gdb) call debug(proc)
|| symbol: 'true'
type spec : (UNKNOWN 0)
attributes: (PROCEDURE )
(gdb) call debug(tmp)
|| symbol: 'true'
type spec : (LOGICAL 4)
attributes: (PROCEDURE MODULE-PROC USE-ASSOC(m1) FUNCTION IMPLICIT_PURE)
result: b
Doing the assignment 'proc = tmp' get me pass the first hurdle.
Unfortnately, one needs to do something like
stree->n.tb->u.specific->n.sym = tmp;
as well, but this leads to an ICE (possibly from freeing the symbol
twice).
I've tried the obvious modification of adding 'resolve_symbol (proc)'
as the first statement in the above block of code. This, indeed,
resolves the symbol but it puts it in the namespace of the local
scope of the function. It does not find the USE associated symbol
(i.e., tmp). I also looked for a gfc_copy_sym (proc, tmp) function,
but came up empty. So, how does one update a symbol and get it
recognized as USE associated?
--
Steve
More information about the Fortran
mailing list