This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [3.4 PATCH] Fix inline nested functions (PR middle-end/15345, c/16450)
On Tue, Jul 20, 2004 at 03:30:53PM -0400, Jason Merrill wrote:
> >>>+ || (cgraph_n_nodes > 0 && cgraph_node (decl)->origin))
> >>
> >>decl_function_context (decl) is the canonical way to test for nested.
> >>
> > Just to be clear, in C++, with:
> >
> > void f() { struct S { void g() { } }; };
> >
> > the "g" function will have a non-NULL decl_function_context, but is not
> > "nested" in the sense of GNU C nested functions; for example, "g" cannot
> > refer to automatic variables in "f".
>
> It's not nested in the sense of needing a static chain, but it is nested in
> the sense of being within the scope of f, which I think is what cgraph
> wants to check.
Actually, it is not nested in the cgraph sense.
cgraph nesting is:
if (DECL_CONTEXT (decl) && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL)
{
node->origin = cgraph_node (DECL_CONTEXT (decl));
node->next_nested = node->origin->nested;
node->origin->nested = node;
}
return node;
and so using decl_function_context (decl) in toplev.c would do the wrong thing
IMHO.
void f()
{
struct S { void g() { } } s;
s.g();
}
(gdb) p debug_tree(order[1]->decl)
<function_decl 0x2a980e90d0 g
type <method_type 0x2a980e9000
type <void_type 0x2a97f07820 void VOID
align 8 symtab 0 alias set -1
pointer_to_this <pointer_type 0x2a97f078f0>>
TI
size <integer_cst 0x2a97f03060 constant 128>
unit size <integer_cst 0x2a97f03930 constant 16>
align 128 symtab 0 alias set -1 method basetype <record_type 0x2a980dcb60 S>
arg-types <tree_list 0x2a980e4030 value <pointer_type 0x2a980dcc30>
chain <tree_list 0x2a97f164e0 tree_2 value <void_type 0x2a97f07820 void>>>
pointer_to_this <pointer_type 0x2a980eb270>>
used nothrow static inline no-static-chain defer-output decl_5 QI file h.C line 3
context <record_type 0x2a980dcb60 S>
arguments <parm_decl 0x2a980e9270 this
type <pointer_type 0x2a980e91a0 type <record_type 0x2a980dcb60 S>
readonly unsigned DI
size <integer_cst 0x2a97f039c0 constant 64>
unit size <integer_cst 0x2a97f03a80 constant 8>
align 64 symtab 0 alias set -1>
readonly unsigned DI file h.C line 3 size <integer_cst 0x2a97f039c0 64> unit size <integer_cst 0x2a97f03a80 8>
align 64 context <function_decl 0x2a980e90d0 g> initial <pointer_type 0x2a980e91a0> arg-type <pointer_type 0x2a980e91a0>>
result <result_decl 0x2a980eadd0 type <void_type 0x2a97f07820 void>
VOID file h.C line 3
align 8 context <function_decl 0x2a980e90d0 g>> initial <block 0x2a980e33c0>
pending-inline-info 0x2a980eb0d0
saved-insns 0x2a980dee00 chain <function_decl 0x2a980ea270 operator=>>
$6 = void
(gdb) p order[1]->origin
$7 = (struct cgraph_node *) 0x0
Jakub