Patchwork [C/C++] Fix -Wunused-but-set* with computed goto (PR c/46015)

login
register
mail settings
Submitter Jakub Jelinek
Date Oct. 18, 2010, 3 p.m.
Message ID <20101018150019.GJ18103@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/68200/
State New
Headers show

Comments

Jakub Jelinek - Oct. 18, 2010, 3 p.m.
Hi!

As the testcase shows, mark_exp_read wasn't being called on computed goto's
argument, leading to spurious -Wunused-but-set* warnings.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

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.

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

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


	Jakub
Richard Henderson - Oct. 18, 2010, 3:32 p.m.
On 10/18/2010 08:00 AM, Jakub Jelinek wrote:
> 	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.

Ok.


r~

Patch

--- gcc/c-parser.c.jj	2010-10-07 19:45:22.000000000 +0200
+++ gcc/c-parser.c	2010-10-18 13:34:24.000000000 +0200
@@ -4116,9 +4116,12 @@  c_parser_statement_after_labels (c_parse
 	    }
 	  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 %<*%>");
--- gcc/cp/semantics.c.jj	2010-09-17 14:10:56.000000000 +0200
+++ gcc/cp/semantics.c	2010-10-18 14:00:06.000000000 +0200
@@ -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);
--- gcc/testsuite/c-c++-common/Wunused-var-13.c.jj	2010-10-18 14:01:07.000000000 +0200
+++ gcc/testsuite/c-c++-common/Wunused-var-13.c	2010-10-18 14:01:59.000000000 +0200
@@ -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;
+}