This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix -Wunused-but-set-* in C with stmt expression and array in it (PR c/50179)


Hi!

As the following testcase shows, if the last expression in statement
expression is array, mark_exp_read wasn't called on it.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk/4.6?

2011-08-26  Jakub Jelinek  <jakub@redhat.com>

	PR c/50179
	* c-typeck.c (c_process_expr_stmt): Skip over nops and
	call mark_exp_read even if exprv is ADDR_EXPR.

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

--- gcc/c-typeck.c.jj	2011-08-18 08:36:00.000000000 +0200
+++ gcc/c-typeck.c	2011-08-25 12:08:02.000000000 +0200
@@ -9109,7 +9109,11 @@ c_process_expr_stmt (location_t loc, tre
   exprv = expr;
   while (TREE_CODE (exprv) == COMPOUND_EXPR)
     exprv = TREE_OPERAND (exprv, 1);
-  if (DECL_P (exprv) || handled_component_p (exprv))
+  while (CONVERT_EXPR_P (exprv))
+    exprv = TREE_OPERAND (exprv, 0);
+  if (DECL_P (exprv)
+      || handled_component_p (exprv)
+      || TREE_CODE (exprv) == ADDR_EXPR)
     mark_exp_read (exprv);
 
   /* If the expression is not of a type to which we cannot assign a line
--- gcc/testsuite/c-c++-common/Wunused-var-14.c.jj	2011-08-25 12:04:39.000000000 +0200
+++ gcc/testsuite/c-c++-common/Wunused-var-14.c	2011-08-25 12:04:34.000000000 +0200
@@ -0,0 +1,13 @@
+/* PR c/50179 */
+/* { dg-options "-Wunused" } */
+/* { dg-do compile } */
+
+void bar (int, ...);
+
+char *
+foo (void)
+{
+  bar (1, (__extension__ ({ static char b[2]; b[0] = 1; b; })));
+  bar (1, ({ static char c[2]; c[0] = 1; c; }));
+  return ({ static char d[2]; d[0] = 1; d; });
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]