diff mbox

[C++] Fix -Wunused-but-set-variable issue with vector conversion (PR c++/44780)

Message ID 20100702165225.GD25077@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek July 2, 2010, 4:52 p.m. UTC
Hi!

For convertible vector types (and some ObjC++ case apparently too)
convert_fro_assignment doesn't go through perform_implicit* and thus
mark_rvalue_use isn't called.

Fixed thusly.  Additionally, I've noticed that in a couple of recent
-Wunused-but* patched I forgot that mark_[rl]value_use return a value.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2010-07-02  Jakub Jelinek  <jakub@redhat.com>

	PR c++/44780
	* typeck.c (convert_for_assignment): When converting a convertible
	vector type or objc++ types, call mark_rvalue_use.
	* typeck2.c (build_m_component_ref): Use return values from
	mark_rvalue_use or mark_lvalue_use.
	* class.c (build_base_path): Likewise.
	* call.c (build_conditional_expr): Likewise.

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


	Jakub

Comments

Jason Merrill July 2, 2010, 7:48 p.m. UTC | #1
OK.

Jason
diff mbox

Patch

--- gcc/cp/typeck.c.jj	2010-07-01 08:45:31.000000000 +0200
+++ gcc/cp/typeck.c	2010-07-02 10:54:59.000000000 +0200
@@ -7211,7 +7211,10 @@  convert_for_assignment (tree type, tree 
 
   if (TREE_CODE (type) == VECTOR_TYPE && coder == VECTOR_TYPE
       && vector_types_convertible_p (type, rhstype, true))
-    return convert (type, rhs);
+    {
+      rhs = mark_rvalue_use (rhs);
+      return convert (type, rhs);
+    }
 
   if (rhs == error_mark_node || rhstype == error_mark_node)
     return error_mark_node;
@@ -7255,7 +7258,10 @@  convert_for_assignment (tree type, tree 
 	}
 
       if (objc_compare_types (type, rhstype, parmno, rname))
-	return convert (type, rhs);
+	{
+	  rhs = mark_rvalue_use (rhs);
+	  return convert (type, rhs);
+	}
     }
 
   /* [expr.ass]
--- gcc/cp/typeck2.c.jj	2010-07-01 08:45:31.000000000 +0200
+++ gcc/cp/typeck2.c	2010-07-02 10:55:58.000000000 +0200
@@ -1478,8 +1478,8 @@  build_m_component_ref (tree datum, tree 
   if (error_operand_p (datum) || error_operand_p (component))
     return error_mark_node;
 
-  mark_lvalue_use (datum);
-  mark_rvalue_use (component);
+  datum = mark_lvalue_use (datum);
+  component = mark_rvalue_use (component);
 
   ptrmem_type = TREE_TYPE (component);
   if (!TYPE_PTR_TO_MEMBER_P (ptrmem_type))
--- gcc/cp/class.c.jj	2010-07-01 08:45:31.000000000 +0200
+++ gcc/cp/class.c	2010-07-02 10:55:29.000000000 +0200
@@ -284,7 +284,7 @@  build_base_path (enum tree_code code,
     /* This must happen before the call to save_expr.  */
     expr = cp_build_unary_op (ADDR_EXPR, expr, 0, tf_warning_or_error);
   else
-    mark_rvalue_use (expr);
+    expr = mark_rvalue_use (expr);
 
   offset = BINFO_OFFSET (binfo);
   fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
--- gcc/cp/call.c.jj	2010-07-01 08:45:31.000000000 +0200
+++ gcc/cp/call.c	2010-07-02 10:56:57.000000000 +0200
@@ -3861,8 +3861,8 @@  build_conditional_expr (tree arg1, tree 
       && same_type_p (arg2_type, arg3_type))
     {
       result_type = arg2_type;
-      mark_lvalue_use (arg2);
-      mark_lvalue_use (arg3);
+      arg2 = mark_lvalue_use (arg2);
+      arg3 = mark_lvalue_use (arg3);
       goto valid_operands;
     }
 
--- gcc/testsuite/c-c++-common/Wunused-var-12.c.jj	2010-07-02 11:10:18.000000000 +0200
+++ gcc/testsuite/c-c++-common/Wunused-var-12.c	2010-07-02 11:07:18.000000000 +0200
@@ -0,0 +1,25 @@ 
+/* PR c++/44780 */
+/* { dg-do compile } */
+/* { dg-options "-Wunused" } */
+
+typedef double vec __attribute__ ((__vector_size__ (16)));
+vec c, d;
+
+void
+foo (void)
+{
+  vec a;
+  vec b;
+  a = c;
+  b = a;
+  d = b;
+}
+
+void
+bar (void)
+{
+  vec a;
+  vec b;	/* { dg-warning "set but not used" } */
+  a = c;
+  b = a;
+}