re PR c/53702 (ICE with -Wall and nested functions and unused typedef)
authorMeador Inge <meadori@codesourcery.com>
Thu, 21 Jun 2012 20:20:30 +0000 (20:20 +0000)
committerMeador Inge <meadori@gcc.gnu.org>
Thu, 21 Jun 2012 20:20:30 +0000 (20:20 +0000)
PR c/53702

* c-decl.c (c_push_function_context): Restore the behavior to reuse
the language function allocated for -Wunused-local-typedefs.
(c_pop_function_context): If necessary, clear the language function
created in c_push_function_context.  Always clear out the
x_cur_stmt_list field of the restored language function.

testsuite/
* gcc.dg/Wunused-local-typedefs.c: New testcase.

From-SVN: r188860

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wunused-local-typedefs.c [new file with mode: 0644]

index baedb0f712dc97a4c5ad1c9ae2951a669244ec29..76c083c7b09e54968f6801aa0b59623cf04e490f 100644 (file)
@@ -1,3 +1,12 @@
+2012-06-21  Meador Inge  <meadori@codesourcery.com>
+
+       PR c/53702
+       * c-decl.c (c_push_function_context): Restore the behavior to reuse
+       the language function allocated for -Wunused-local-typedefs.
+       (c_pop_function_context): If necessary, clear the language function
+       created in c_push_function_context.  Always clear out the
+       x_cur_stmt_list field of the restored language function.
+
 2012-06-21   Sterling Augustine  <saugustine@google.com>
         Cary Coutant  <ccoutant@google.com>
 
index 9622b1207d46a0369af26349b6988a68fb97409d..bbb437d8231163b12ee568d75efd70d03f6f5ff6 100644 (file)
@@ -8579,9 +8579,11 @@ check_for_loop_decls (location_t loc, bool turn_off_iso_c99_error)
 void
 c_push_function_context (void)
 {
-  struct language_function *p;
-  p = ggc_alloc_language_function ();
-  cfun->language = p;
+  struct language_function *p = cfun->language;
+  /* cfun->language might have been already allocated by the use of
+     -Wunused-local-typedefs.  In that case, just re-use it.  */
+  if (p == NULL)
+    cfun->language = p = ggc_alloc_cleared_language_function ();
 
   p->base.x_stmt_tree = c_stmt_tree;
   c_stmt_tree.x_cur_stmt_list
@@ -8607,7 +8609,12 @@ c_pop_function_context (void)
 
   pop_function_context ();
   p = cfun->language;
-  cfun->language = NULL;
+
+  /* When -Wunused-local-typedefs is in effect, cfun->languages is
+     used to store data throughout the life time of the current cfun,
+     So don't deallocate it.  */
+  if (!warn_unused_local_typedefs)
+    cfun->language = NULL;
 
   if (DECL_STRUCT_FUNCTION (current_function_decl) == 0
       && DECL_SAVED_TREE (current_function_decl) == NULL_TREE)
@@ -8620,6 +8627,7 @@ c_pop_function_context (void)
     }
 
   c_stmt_tree = p->base.x_stmt_tree;
+  p->base.x_stmt_tree.x_cur_stmt_list = NULL;
   c_break_label = p->x_break_label;
   c_cont_label = p->x_cont_label;
   c_switch_stack = p->x_switch_stack;
index 9ae68f18c1b4d53ad7343494e23cdc4ea68c7a17..48f5f4e79632f6fdf125dc1c6823df0d283afff9 100644 (file)
@@ -1,3 +1,8 @@
+2012-06-21  Meador Inge  <meadori@codesourcery.com>
+
+       PR c/53702
+       * gcc.dg/Wunused-local-typedefs.c: New testcase.
+
 2012-06-21  Steven Bosscher  <steven@gcc.gnu.org>
 
        * testsuite/gcc.dg/pch/ident-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/Wunused-local-typedefs.c b/gcc/testsuite/gcc.dg/Wunused-local-typedefs.c
new file mode 100644 (file)
index 0000000..4c8c15e
--- /dev/null
@@ -0,0 +1,36 @@
+/*  Origin PR c/53702
+    { dg-options "-Wunused-local-typedefs" }
+    { dg-do compile }
+*/
+
+/* Only test nested functions for C.  More tests that work for C and C++
+   can be found in c-c++-common.
+*/
+
+void
+test0 ()
+{
+  typedef int foo; /* { dg-warning "locally defined but not used" } */
+  void f ()
+  {
+  }
+}
+
+void
+test1 ()
+{
+  void f ()
+  {
+    typedef int foo; /* { dg-warning "locally defined but not used" } */
+  }
+}
+
+
+void
+test2 ()
+{
+  void f ()
+  {
+  }
+  typedef int foo; /* { dg-warning "locally defined but not used" } */
+}