From: Richard Guenther Date: Tue, 29 Jan 2008 15:47:19 +0000 (+0000) Subject: re PR tree-optimization/35006 (Segfault in remove_unused_locals with nested functions) X-Git-Tag: releases/gcc-4.3.0~339 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f5c64b8ace84098b6222b495294765fb3fc38c2;p=thirdparty%2Fgcc.git re PR tree-optimization/35006 (Segfault in remove_unused_locals with nested functions) 2008-01-29 Richard Guenther PR middle-end/35006 * tree-inline.h (struct copy_body_data): Add remapping_type_depth field. * tree-inline.c (remap_type): Increment remapping_type_depth around remapping types. (copy_body_r): Only add referenced variables if they are referenced from code, not types. * gcc.c-torture/compile/pr35006.c: New testcase. From-SVN: r131939 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a827f0df4f52..cb097d93c946 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2008-01-29 Richard Guenther + + PR middle-end/35006 + * tree-inline.h (struct copy_body_data): Add remapping_type_depth + field. + * tree-inline.c (remap_type): Increment remapping_type_depth + around remapping types. + (copy_body_r): Only add referenced variables if they are referenced + from code, not types. + 2008-01-29 Douglas Gregor PR c++/34055 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 832e1e87b613..86bfcc7a34b4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-01-29 Richard Guenther + + PR middle-end/35006 + * gcc.c-torture/compile/pr35006.c: New testcase. + 2008-01-29 Douglas Gregor PR c++/34055 diff --git a/gcc/testsuite/gcc.c-torture/compile/pr35006.c b/gcc/testsuite/gcc.c-torture/compile/pr35006.c new file mode 100644 index 000000000000..53de05cdb403 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr35006.c @@ -0,0 +1,29 @@ +typedef unsigned long grub_uint64_t; +typedef grub_uint64_t grub_size_t; +grub_cmdline_get (unsigned max_len, int echo_char) +{ + unsigned xpos, ypos, ystart; + grub_size_t lpos, llen; + char buf[max_len]; + void cl_print (int pos, int c) + { + char *p; + for (p = buf + pos; *p; p++) + { + if (xpos++ > 78) + grub_putchar ('\n'); + grub_putchar (*p); + } + } + void cl_delete (unsigned len) + { + cl_set_pos (); + cl_print (lpos, ' '); + grub_memmove (); + cl_print (lpos, echo_char); + cl_set_pos (); + } + cl_delete (llen); + grub_size_t n = lpos; + cl_delete (n); +} diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 636e37d8024c..d2ef9619eb2d 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -409,6 +409,7 @@ tree remap_type (tree type, copy_body_data *id) { tree *node; + tree tmp; if (type == NULL) return type; @@ -425,7 +426,11 @@ remap_type (tree type, copy_body_data *id) return type; } - return remap_type_1 (type, id); + id->remapping_type_depth++; + tmp = remap_type_1 (type, id); + id->remapping_type_depth--; + + return tmp; } static tree @@ -723,9 +728,10 @@ copy_body_r (tree *tp, int *walk_subtrees, void *data) tweak some special cases. */ copy_tree_r (tp, walk_subtrees, NULL); - /* Global variables we didn't seen yet needs to go into referenced - vars. */ - if (gimple_in_ssa_p (cfun) && TREE_CODE (*tp) == VAR_DECL) + /* Global variables we haven't seen yet needs to go into referenced + vars. If not referenced from types only. */ + if (gimple_in_ssa_p (cfun) && TREE_CODE (*tp) == VAR_DECL + && id->remapping_type_depth == 0) add_referenced_var (*tp); /* If EXPR has block defined, map it to newly constructed block. diff --git a/gcc/tree-inline.h b/gcc/tree-inline.h index 893b9c9d0ce3..562713a32990 100644 --- a/gcc/tree-inline.h +++ b/gcc/tree-inline.h @@ -95,6 +95,9 @@ typedef struct copy_body_data /* True if this statement will need to be regimplified. */ bool regimplify; + /* > 0 if we are remapping a type currently. */ + int remapping_type_depth; + /* Statements that might be possibly folded. */ struct pointer_set_t *statements_to_fold;