public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Fix -Wunused-but-set-* on RHS of x op= rhs if rhs has side-effects (PR c++/50158)
@ 2011-08-23 16:03 Jakub Jelinek
  2011-08-23 16:31 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2011-08-23 16:03 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

Hi!

The recent cp_build_modify_expr change broke the following testcase,
we now complain that b is set but not used.  The problem is that
when rhs has side-effects, stabilize_expr returns a temporary (+ creates
a TARGET_EXPR), which means that mark_exp_read isn't actually called on the
original RHS expression.

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

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

	PR c++/50158
	* typeck.c (cp_build_modify_expr): Call mark_rvalue_use on rhs
	if it has side-effects and needs to be preevaluated.

	* g++.dg/warn/Wunused-var-16.C: New test.

--- gcc/cp/typeck.c.jj	2011-08-18 08:35:38.000000000 +0200
+++ gcc/cp/typeck.c	2011-08-23 14:36:42.000000000 +0200
@@ -6692,6 +6692,8 @@ cp_build_modify_expr (tree lhs, enum tre
 	     side effect associated with any single compound assignment
 	     operator. -- end note ]  */
 	  lhs = stabilize_reference (lhs);
+	  if (TREE_SIDE_EFFECTS (rhs))
+	    rhs = mark_rvalue_use (rhs);
 	  rhs = stabilize_expr (rhs, &init);
 	  newrhs = cp_build_binary_op (input_location,
 				       modifycode, lhs, rhs,
--- gcc/testsuite/g++.dg/warn/Wunused-var-16.C.jj	2011-08-23 14:37:31.000000000 +0200
+++ gcc/testsuite/g++.dg/warn/Wunused-var-16.C	2011-08-23 14:37:19.000000000 +0200
@@ -0,0 +1,13 @@
+// PR c++/50158
+// { dg-do compile }
+// { dg-options "-Wunused" }
+
+int bar (int);
+
+int
+foo (int a)
+{
+  int b[] = { a, -a };
+  a += b[bar (a) < a];
+  return a;
+}

	Jakub

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

* Re: [C++ PATCH] Fix -Wunused-but-set-* on RHS of x op= rhs if rhs has side-effects (PR c++/50158)
  2011-08-23 16:03 [C++ PATCH] Fix -Wunused-but-set-* on RHS of x op= rhs if rhs has side-effects (PR c++/50158) Jakub Jelinek
@ 2011-08-23 16:31 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2011-08-23 16:31 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

OK.

Jason

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

end of thread, other threads:[~2011-08-23 15:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-23 16:03 [C++ PATCH] Fix -Wunused-but-set-* on RHS of x op= rhs if rhs has side-effects (PR c++/50158) Jakub Jelinek
2011-08-23 16:31 ` Jason Merrill

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).