public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix -Wunused-but-set-* in C with stmt expression and array in it (PR c/50179)
@ 2011-08-26  4:27 Jakub Jelinek
  2011-08-26 14:44 ` Joseph S. Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2011-08-26  4:27 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc-patches

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix -Wunused-but-set-* in C with stmt expression and array in it (PR c/50179)
  2011-08-26  4:27 [PATCH] Fix -Wunused-but-set-* in C with stmt expression and array in it (PR c/50179) Jakub Jelinek
@ 2011-08-26 14:44 ` Joseph S. Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph S. Myers @ 2011-08-26 14:44 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Fri, 26 Aug 2011, Jakub Jelinek wrote:

> 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?

OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-26 14:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-26  4:27 [PATCH] Fix -Wunused-but-set-* in C with stmt expression and array in it (PR c/50179) Jakub Jelinek
2011-08-26 14:44 ` Joseph S. Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).