This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] fix c/11267
- From: Richard Henderson <rth at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 23 Jan 2004 00:51:32 -0800
- Subject: [tree-ssa] fix c/11267
By gimplifying outer functions first, we resolve the size of VLAs
into the proper context.
r~
PR c/11267
* c-decl.c (c_finalize): New.
(finish_function): Use it. Genericize and finalize only non-nested
functions. Register nested functions with cgraph.
* c-simplify.c: Include cgraph.h.
(c_genericize): Genericize nested functions.
* gimplify.c (gimplify_expr): Use DECL_SAVED_INSNS to access
the struct function for the context.
* Makefile.in (c-simplify.o): Update dependencies.
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.903.2.170
diff -c -p -d -u -r1.903.2.170 Makefile.in
--- Makefile.in 20 Jan 2004 01:07:11 -0000 1.903.2.170
+++ Makefile.in 23 Jan 2004 08:42:02 -0000
@@ -1599,7 +1599,7 @@ tree-optimize.o : tree-optimize.c $(TREE
c-simplify.o : c-simplify.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) errors.h \
$(C_TREE_H) $(C_COMMON_H) diagnostic.h $(TREE_SIMPLE_H) varray.h flags.h \
langhooks.h toplev.h rtl.h $(TREE_FLOW_H) langhooks-def.h \
- $(TM_H) coretypes.h $(C_PRETTY_PRINT_H)
+ $(TM_H) coretypes.h $(C_PRETTY_PRINT_H) cgraph.h
gimplify.o : gimplify.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) errors.h \
diagnostic.h $(TREE_SIMPLE_H) tree-inline.h varray.h langhooks.h \
langhooks-def.h $(TREE_FLOW_H) $(TIMEVAR_H) $(TM_H) coretypes.h except.h \
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.334.2.76
diff -c -p -d -u -r1.334.2.76 c-decl.c
--- c-decl.c 5 Jan 2004 22:33:06 -0000 1.334.2.76
+++ c-decl.c 23 Jan 2004 08:42:03 -0000
@@ -6092,6 +6092,32 @@ store_parm_decls (void)
cfun->x_dont_save_pending_sizes_p = 1;
}
+/* Give FNDECL and all its nested functions to cgraph for compilation. */
+
+static void
+c_finalize (tree fndecl)
+{
+ struct cgraph_node *cgn;
+
+ /* Handle attribute((warn_unused_result)). Relies on gimple input. */
+ c_warn_unused_result (&DECL_SAVED_TREE (fndecl));
+
+ /* ??? Objc emits functions after finalizing the compilation unit.
+ This should be cleaned up later and this conditional removed. */
+ if (cgraph_global_info_ready)
+ {
+ c_expand_body (fndecl);
+ return;
+ }
+
+ /* Finalize all nested functions now. */
+ cgn = cgraph_node (fndecl);
+ for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
+ c_finalize (cgn->decl);
+
+ cgraph_finalize_function (fndecl, false);
+}
+
/* Finish up a function declaration and compile that function
all the way to assembler language output. The free the storage
for the function definition.
@@ -6193,22 +6219,25 @@ finish_function (void)
info for the epilogue. */
cfun->function_end_locus = input_location;
- /* Genericize before inlining. */
- c_genericize (fndecl);
-
- /* Handle attribute((warn_unused_result)). Relies on gimple input. */
- c_warn_unused_result (&DECL_SAVED_TREE (fndecl));
+ /* Genericize before inlining. Delay genericizing nested functions
+ until their parent function is genericized. Since finalizing
+ requires GENERIC, delay that as well. */
+ if (!decl_function_context (fndecl))
+ {
+ c_genericize (fndecl);
+ c_finalize (fndecl);
+ }
+ else
+ {
+ /* Register this function with cgraph just far enough to get it
+ added to our parent's nested function list. Handy, since the
+ C front end doesn't have such a list. */
+ (void) cgraph_node (fndecl);
+ }
/* We're leaving the context of this function, so zap cfun. It's still in
DECL_SAVED_INSNS, and we'll restore it in tree_rest_of_compilation. */
cfun = NULL;
-
- /* ??? Objc emits functions after finalizing the compilation unit.
- This should be cleaned up later and this conditional removed. */
- if (!cgraph_global_info_ready)
- cgraph_finalize_function (fndecl, false);
- else
- c_expand_body (fndecl);
current_function_decl = NULL;
}
Index: c-simplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/c-simplify.c,v
retrieving revision 1.1.4.87
diff -c -p -d -u -r1.1.4.87 c-simplify.c
--- c-simplify.c 19 Dec 2003 03:05:47 -0000 1.1.4.87
+++ c-simplify.c 23 Jan 2004 08:42:03 -0000
@@ -46,6 +46,8 @@ Software Foundation, 59 Temple Place - S
#include "toplev.h"
#include "tree-dump.h"
#include "c-pretty-print.h"
+#include "cgraph.h"
+
/* The gimplification pass converts the language-dependent trees
(ld-trees) emitted by the parser into language-independent trees
@@ -133,6 +135,7 @@ c_genericize (tree fndecl)
{
FILE *dump_file;
int dump_flags;
+ struct cgraph_node *cgn;
/* Dump the C-specific tree IR. */
dump_file = dump_begin (TDI_original, &dump_flags);
@@ -161,6 +164,13 @@ c_genericize (tree fndecl)
/* Dump the genericized tree IR. */
dump_function (TDI_generic, fndecl);
+
+ /* Genericize all nested functions now. We do things in this order so
+ that items like VLA sizes are expanded properly in the context of
+ the correct function. */
+ cgn = cgraph_node (fndecl);
+ for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
+ c_genericize (cgn->decl);
}
/* Entry point for the tree lowering pass. Recursively scan
Index: gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/gimplify.c,v
retrieving revision 1.1.2.135
diff -c -p -d -u -r1.1.2.135 gimplify.c
--- gimplify.c 19 Jan 2004 23:21:42 -0000 1.1.2.135
+++ gimplify.c 23 Jan 2004 08:42:03 -0000
@@ -3102,7 +3102,7 @@ gimplify_expr (tree *expr_p, tree *pre_p
if (current_function_decl != context)
{
NONLOCAL_LABEL (dest) = 1;
- find_function_data (context)->has_nonlocal_label = 1;
+ DECL_SAVED_INSNS (context)->has_nonlocal_label = 1;
}
}
break;