This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c-family PATCH to improve -Wbool-compare (PR c/64610)


Marek Polacek <polacek@redhat.com> writes:

> diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
> index 7d314f8..ada8e8a 100644
> --- gcc/c-family/c-common.c
> +++ gcc/c-family/c-common.c
> @@ -11924,6 +11924,17 @@ maybe_warn_bool_compare (location_t loc, enum tree_code code, tree op0,
>      }
>    else if (integer_zerop (cst) || integer_onep (cst))
>      {
> +      /* If the non-constant operand isn't of a boolean type, we
> +	 don't want to warn here.  */
> +      tree noncst = TREE_CODE (op0) == INTEGER_CST ? op1 : op0;
> +      /* Handle booleans promoted to integers.  */
> +      if (CONVERT_EXPR_P (noncst)
> +	  && TREE_TYPE (noncst) == integer_type_node
> +	  && TREE_CODE (TREE_TYPE (TREE_OPERAND (noncst, 0))) == BOOLEAN_TYPE)
> +	/* Warn.  */;
> +      else if (TREE_CODE (TREE_TYPE (noncst)) != BOOLEAN_TYPE
> +	       && !truth_value_p (TREE_CODE (noncst)))
> +	return;
>        /* Do some magic to get the right diagnostics.  */
>        bool flag = TREE_CODE (op0) == INTEGER_CST;
>        flag = integer_zerop (cst) ? flag : !flag;

Looks good, successfully built stage3.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]