public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@linux-m68k.org>
To: Marek Polacek <polacek@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: c-family PATCH to improve -Wbool-compare (PR c/64610)
Date: Thu, 30 Apr 2015 14:21:00 -0000	[thread overview]
Message-ID: <87lhh9hh0z.fsf@igel.home> (raw)
In-Reply-To: <20150430112727.GG3384@redhat.com> (Marek Polacek's message of	"Thu, 30 Apr 2015 13:27:27 +0200")

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."

      reply	other threads:[~2015-04-30 13:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-28 12:06 Marek Polacek
2015-04-28 17:16 ` Jeff Law
2015-04-30 10:00 ` Andreas Schwab
2015-04-30 11:34   ` Marek Polacek
2015-04-30 14:21     ` Andreas Schwab [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lhh9hh0z.fsf@igel.home \
    --to=schwab@linux-m68k.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=polacek@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).