This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Patch] PR c/7490
- From: Philippe Trebuchet <Philippe dot Trebuchet at sophia dot inria dot fr>
- To: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- Cc: Richard Henderson <rth at redhat dot com>, gcc-patches at gcc dot gnu dot org, ebotcazou at libertysurf dot fr
- Date: Tue, 10 Dec 2002 02:58:22 +0100
- Subject: Re: [Patch] PR c/7490
- Organization: Tres Tres Peu
- References: <200211261349.gAQDnJrZ019890@charybde.inria.fr> <20021126181907.GD29756@redhat.com> <3DF4D48D.EA939ED@sophia.inria.fr> <m3ptsb3xe2.fsf@uniton.integrable-solutions.net>
Gabriel Dos Reis wrote:
>
> Philippe Trebuchet <Philippe.Trebuchet@sophia.inria.fr> writes:
>
[...]
> I think this isn't the right approach. In essence, what you're trying
> to do is in no way different from what we do for names used in
> class-definitions in cc1plus:
>
> (1) record potential nested fuunctions that need some processing
> at the end of the binding level
> (2) at the end of the scope check to see whether those functions
> recorded in (1) meet the semantics requirements.
>
> Forget about RTL.
>
> -- Gaby
OK after a little change I split my patch in two:
-one small modif in c-common.c to handle aliases as they should have(I
fix the check about decl_context)
-one other in c-decl.c where I check for undefined auto nested functions
in finish_function. I do it perhaps awkwardly, I run across all local
names and check each local declaration. The check is perform before the
optimiser in ran on the function.
Is this like this you wanted it?
Index: gcc/c-common.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.392
diff -c -p -3 -r1.392 c-common.c
*** gcc/c-common.c 1 Dec 2002 17:51:43 -0000 1.392
--- gcc/c-common.c 10 Dec 2002 01:46:14 -0000
*************** handle_alias_attribute (node, name, args
*** 5831,5837 ****
"`%s' defined both normally and as an alias");
*no_add_attrs = true;
}
! else if (decl_function_context (decl) == 0)
{
tree id;
--- 5831,5839 ----
"`%s' defined both normally and as an alias");
*no_add_attrs = true;
}
! else if (current_function_decl == 0)
! /* decl_function_context (decl) == 0 is always true
! * it is pushdecl that sets up DECL_CONTEXT usefully */
{
tree id;
Index: gcc/c-decl.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.355
diff -c -p -3 -r1.355 c-decl.c
*** gcc/c-decl.c 26 Nov 2002 17:36:14 -0000 1.355
--- gcc/c-decl.c 10 Dec 2002 01:46:14 -0000
*************** finish_function (nested, can_defer_p)
*** 6326,6332 ****
int nested;
int can_defer_p;
{
! tree fndecl = current_function_decl;
#if 0
/* This caused &foo to be of type ptr-to-const-function which then
--- 6326,6332 ----
int nested;
int can_defer_p;
{
! tree fndecl = current_function_decl,function_body;
#if 0
/* This caused &foo to be of type ptr-to-const-function which then
*************** finish_function (nested, can_defer_p)
*** 6389,6400 ****
CFUN. Do so explicitly. */
free_after_compilation (cfun);
cfun = NULL;
!
if (! nested)
{
/* Generate RTL for the body of this function. */
c_expand_body (fndecl, nested, can_defer_p);
!
/* Let the error reporting routines know that we're outside a
function. For a nested function, this value is used in
c_pop_function_context and then reset via pop_function_context. */
--- 6389,6423 ----
CFUN. Do so explicitly. */
free_after_compilation (cfun);
cfun = NULL;
! function_body= COMPOUND_BODY(DECL_SAVED_TREE(fndecl));
! if (function_body!=NULL)
! {
! tree block=SCOPE_STMT_BLOCK(function_body);
! if (block !=NULL)
! {
! tree fn;
! for ( fn = BLOCK_VARS(block);
! fn != NULL;
! fn = TREE_CHAIN (fn))
! {
! if (TREE_CODE (fn) == FUNCTION_DECL
! && DECL_CONTEXT (fn) == current_function_decl
! && (DECL_INITIAL(fn) == 0 ||
! DECL_INITIAL (fn) ==error_mark_node))
! {
! error("no definition for auto nested function `%s'",
! IDENTIFIER_POINTER (DECL_NAME (fn)));
! DECL_INITIAL(fndecl)=0;
! return ;
! }
! }
! }
! }
if (! nested)
{
/* Generate RTL for the body of this function. */
c_expand_body (fndecl, nested, can_defer_p);
!
/* Let the error reporting routines know that we're outside a
function. For a nested function, this value is used in
c_pop_function_context and then reset via pop_function_context. */
--
Philippe