diff mbox

Make -Wint-in-bool-context warn on suspicious shift ops

Message ID CADzB+2k=a8Qmg1upMck9UCWo7ge8G+L==CH_fj14xnzcQY6-kg@mail.gmail.com
State New
Headers show

Commit Message

Jason Merrill Oct. 9, 2016, 2:41 a.m. UTC
On Sat, Oct 8, 2016 at 4:05 PM, Bernd Edlinger
<bernd.edlinger@hotmail.de> wrote:
> On 10/08/16 19:40, Jason Merrill wrote:
>> On Fri, Sep 30, 2016 at 1:07 AM, Bernd Edlinger
>> <bernd.edlinger@hotmail.de> wrote:
>>> On 09/29/16 22:38, Jason Merrill wrote:
>>>> On Thu, Sep 29, 2016 at 3:58 PM, Bernd Edlinger
>>>> <bernd.edlinger@hotmail.de> wrote:
>>>>> Unfortunately, without that exception there is a false positive:
>>>>>
>>>>> In file included from ../../gcc-trunk/gcc/ada/gcc-interface/decl.c:30:0:
>>>>> ../../gcc-trunk/gcc/ada/gcc-interface/decl.c: In function 'int
>>>>> adjust_packed(tree, tree, int)':
>>>>> ../../gcc-trunk/gcc/tree.h:1874:22: error: << on signed integer in
>>>>> boolean context [-Werror=int-in-bool-context]
>>>>>          ? ((unsigned)1) << ((NODE)->type_common.align - 1) : 0)
>>>>>            ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>
>>>> Ah, this issue again: the shift isn't in boolean context, it's in
>>>> integer context.  I think we want to be a lot more conservative about
>>>> these warnings in the arms of a COND_EXPR.  In fact, I think the
>>>> entire
>>>>
>>>>         /* Distribute the conversion into the arms of a COND_EXPR.  */
>>>>
>>>> section is wrong now that we're doing delayed folding.
>>>
>>> Could you take care of this ?
>>
>> Done thus:
>>
>
> Thanks.
>
> But I have one question:
>
> --- a/gcc/cp/cp-gimplify.c
> +++ b/gcc/cp/cp-gimplify.c
> @@ -2253,6 +2253,15 @@ cp_fold (tree x)
>         op1 = cp_fold (TREE_OPERAND (x, 1));
>         op2 = cp_fold (TREE_OPERAND (x, 2));
>
> +      if (TREE_CODE (TREE_TYPE (x)) == BOOLEAN_TYPE)
> +       {
> +         warning_sentinel (warn_int_in_bool_context);
>
>
> Yes, it compiles, but ...
> how can this compile at all?
>
> Doesn't it miss a name of a local?
> like warning_sentinel c (warn_int_in_bool_context);

Oops, yes, thanks.  What I wrote is an expression that creates a
temporary warning_sentinel that is then immediately destroyed.

Jason
commit 5df6967f5f787f8da43b0122a7d01542ea70adad
Author: Jason Merrill <jason@redhat.com>
Date:   Sat Oct 8 17:51:51 2016 -0400

            * cp-gimplify.c (cp_fold): Add variable name.
diff mbox

Patch

diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 4879632..b085f3a 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -2255,7 +2255,7 @@  cp_fold (tree x)
 
       if (TREE_CODE (TREE_TYPE (x)) == BOOLEAN_TYPE)
 	{
-	  warning_sentinel (warn_int_in_bool_context);
+	  warning_sentinel s (warn_int_in_bool_context);
 	  if (!VOID_TYPE_P (TREE_TYPE (op1)))
 	    op1 = cp_truthvalue_conversion (op1);
 	  if (!VOID_TYPE_P (TREE_TYPE (op2)))