Re: [C++ PATCH] Fix -Wunused-but-set-* false positive with ~ of vector type (PR c++/78949)

2017-01-04 Thread Jason Merrill
OK.

On Thu, Dec 29, 2016 at 10:19 AM, Jakub Jelinek  wrote:
> Hi!
>
> For integral arg, mark_exp_read is called during
> cp_perform_integral_promotions, for complex type it is called during
> cp_default_conversion, but for vector types nothing actually calls it.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?
>
> 2016-12-29  Jakub Jelinek  
>
> PR c++/78949
> * typeck.c (cp_build_unary_op): Call mark_rvalue_use on arg if it has
> vector type.
>
> * c-c++-common/Wunused-var-16.c: New test.
>
> --- gcc/cp/typeck.c.jj  2016-12-21 23:12:01.0 +0100
> +++ gcc/cp/typeck.c 2016-12-29 13:48:58.363469890 +0100
> @@ -5907,6 +5907,8 @@ cp_build_unary_op (enum tree_code code,
> inform (location, "did you mean to use logical not (%)?");
>   arg = cp_perform_integral_promotions (arg, complain);
> }
> +  else if (!noconvert && VECTOR_TYPE_P (TREE_TYPE (arg)))
> +   arg = mark_rvalue_use (arg);
>break;
>
>  case ABS_EXPR:
> --- gcc/testsuite/c-c++-common/Wunused-var-16.c.jj  2016-12-29 
> 13:51:07.143825569 +0100
> +++ gcc/testsuite/c-c++-common/Wunused-var-16.c 2016-12-29 13:50:42.0 
> +0100
> @@ -0,0 +1,15 @@
> +/* PR c++/78949 */
> +/* { dg-do compile } */
> +/* { dg-options "-Wunused" } */
> +
> +typedef unsigned char V __attribute__((vector_size(16)));
> +V v;
> +
> +void
> +foo ()
> +{
> +  V y = {};
> +  V x = {};// { dg-bogus "set but not used" }
> +  y &= ~x;
> +  v = y;
> +}
>
> Jakub


[C++ PATCH] Fix -Wunused-but-set-* false positive with ~ of vector type (PR c++/78949)

2016-12-29 Thread Jakub Jelinek
Hi!

For integral arg, mark_exp_read is called during
cp_perform_integral_promotions, for complex type it is called during
cp_default_conversion, but for vector types nothing actually calls it.

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

2016-12-29  Jakub Jelinek  

PR c++/78949
* typeck.c (cp_build_unary_op): Call mark_rvalue_use on arg if it has
vector type.

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

--- gcc/cp/typeck.c.jj  2016-12-21 23:12:01.0 +0100
+++ gcc/cp/typeck.c 2016-12-29 13:48:58.363469890 +0100
@@ -5907,6 +5907,8 @@ cp_build_unary_op (enum tree_code code,
inform (location, "did you mean to use logical not (%)?");
  arg = cp_perform_integral_promotions (arg, complain);
}
+  else if (!noconvert && VECTOR_TYPE_P (TREE_TYPE (arg)))
+   arg = mark_rvalue_use (arg);
   break;
 
 case ABS_EXPR:
--- gcc/testsuite/c-c++-common/Wunused-var-16.c.jj  2016-12-29 
13:51:07.143825569 +0100
+++ gcc/testsuite/c-c++-common/Wunused-var-16.c 2016-12-29 13:50:42.0 
+0100
@@ -0,0 +1,15 @@
+/* PR c++/78949 */
+/* { dg-do compile } */
+/* { dg-options "-Wunused" } */
+
+typedef unsigned char V __attribute__((vector_size(16)));
+V v;
+
+void
+foo ()
+{
+  V y = {};
+  V x = {};// { dg-bogus "set but not used" }
+  y &= ~x;
+  v = y;
+}

Jakub