This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[RFC/PATCH] Fix 17807, ICE for undefined local function
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 4 Oct 2004 13:56:32 -0400
- Subject: [RFC/PATCH] Fix 17807, ICE for undefined local function
The problem here is that we assume that nested functions are always
declared which is not true. I added the code to tree-nested.c to
error on this case and to get the correct error recovery here too.
I don't know if this is the correct place to put this error but it
was the easiest place to put it and have it not ICE.
OK? Bootstrapped and tested on powerpc-darwin with no regressions.
Thanks,
Andrew Pinski
Testcase:
int main(void)
{
auto int bar(int);
bar(5);
}
------
int main(void)
{
int foo(int a)
{
auto int bar(int);
bar(5);
}
}
ChangeLog:
* tree-nested.c (create_nesting_tree): Error out if we find
a nested function is not defined.
(lower_nested_functions): If create_nesting_tree returns null
then we can just return.
Index: tree-nested.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-nested.c,v
retrieving revision 2.19
diff -u -p -r2.19 tree-nested.c
--- tree-nested.c 20 Sep 2004 20:38:17 -0000 2.19
+++ tree-nested.c 4 Oct 2004 17:45:07 -0000
@@ -101,7 +101,7 @@ struct nesting_info
bool any_parm_remapped;
bool any_tramp_created;
};
-
+static void free_nesting_tree (struct nesting_info *root);
/* Hashing and equality functions for nesting_info->var_map. */
@@ -625,7 +625,21 @@ create_nesting_tree (struct cgraph_node
for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
{
- struct nesting_info *sub = create_nesting_tree (cgn);
+ struct nesting_info *sub;
+ if (DECL_STRUCT_FUNCTION (cgn->decl) == NULL)
+ {
+ error ("nested function, %qE, not declared", cgn->decl);
+ cgraph_unnest_node (cgn);
+ free_nesting_tree (info);
+ return NULL;
+ }
+ sub = create_nesting_tree (cgn);
+ if (sub == NULL)
+ {
+ cgraph_unnest_node (cgn);
+ free_nesting_tree (info);
+ return NULL;
+ }
sub->outer = info;
sub->next = info->inner;
info->inner = sub;
@@ -1375,6 +1389,8 @@ lower_nested_functions (tree fndecl)
return;
root = create_nesting_tree (cgn);
+ if (!root)
+ return;
walk_all_functions (convert_nonlocal_reference, root);
walk_all_functions (convert_local_reference, root);
walk_all_functions (convert_nl_goto_reference, root);