This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: c-family PATCH to improve -Wbool-compare (PR c/64610)
- From: Andreas Schwab <schwab at linux-m68k dot org>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 30 Apr 2015 15:39:24 +0200
- Subject: Re: c-family PATCH to improve -Wbool-compare (PR c/64610)
- Authentication-results: sourceware.org; auth=none
- References: <20150428104932 dot GD11448 at redhat dot com> <87egn2hs05 dot fsf at igel dot home> <20150430112727 dot GG3384 at redhat dot com>
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."