re PR c/46015 (-Wunused-but-set-variable warns for arrays used in gotos)
authorJakub Jelinek <jakub@redhat.com>
Mon, 18 Oct 2010 15:55:25 +0000 (17:55 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 18 Oct 2010 15:55:25 +0000 (17:55 +0200)
PR c/46015
* c-parser.c (c_parser_statement_after_labels): Call mark_exp_read
on computed goto argument.

* semantics.c (finish_goto_stmt): Call mark_rvalue_use on computed
goto destination.

* c-c++-common/Wunused-var-13.c: New test.

From-SVN: r165643

gcc/ChangeLog
gcc/c-parser.c
gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/Wunused-var-13.c [new file with mode: 0644]

index 55303f2..e409c9d 100644 (file)
@@ -1,3 +1,9 @@
+2010-10-18  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/46015
+       * c-parser.c (c_parser_statement_after_labels): Call mark_exp_read
+       on computed goto argument.
+
 2010-10-18  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/45967
index 8338e9d..bde882c 100644 (file)
@@ -4151,9 +4151,12 @@ c_parser_statement_after_labels (c_parser *parser)
            }
          else if (c_parser_next_token_is (parser, CPP_MULT))
            {
+             tree val;
+
              c_parser_consume_token (parser);
-             stmt = c_finish_goto_ptr (loc,
-                                       c_parser_expression (parser).value);
+             val = c_parser_expression (parser).value;
+             mark_exp_read (val);
+             stmt = c_finish_goto_ptr (loc, val);
            }
          else
            c_parser_error (parser, "expected identifier or %<*%>");
index 9073ccb..8374750 100644 (file)
@@ -1,3 +1,9 @@
+2010-10-18  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/46015
+       * semantics.c (finish_goto_stmt): Call mark_rvalue_use on computed
+       goto destination.
+
 2010-10-17  Nicola Pero  <nicola.pero@meta-innovation.com>
        
        Merge from apple/trunk branch on FSF servers.
index 787c72c..ae3bf90 100644 (file)
@@ -537,6 +537,7 @@ finish_goto_stmt (tree destination)
     TREE_USED (destination) = 1;
   else
     {
+      destination = mark_rvalue_use (destination);
       if (!processing_template_decl)
        {
          destination = cp_convert (ptr_type_node, destination);
index 6a2738f..d066a8d 100644 (file)
@@ -1,3 +1,8 @@
+2010-10-18  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/46015
+       * c-c++-common/Wunused-var-13.c: New test.
+
 2010-10-18  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/45967
diff --git a/gcc/testsuite/c-c++-common/Wunused-var-13.c b/gcc/testsuite/c-c++-common/Wunused-var-13.c
new file mode 100644 (file)
index 0000000..3afd873
--- /dev/null
@@ -0,0 +1,27 @@
+/* PR c/46015 */
+/* { dg-options "-Wunused" } */
+/* { dg-do compile } */
+
+int
+f1 (int i)
+{
+  static void *labs[2] = { &&lab1, &&lab2 };
+  goto *(labs[i & 1]);
+
+lab1:
+  return 1;
+lab2:
+  return 2;
+}
+
+int
+f2 (int i)
+{
+  void *labs[2] = { &&lab1, &&lab2 };
+  goto *labs[i & 1];
+
+lab1:
+  return 1;
+lab2:
+  return 2;
+}