This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: c-family PATCH to improve -Wtautological-compare (PR c/81783)
- From: Jeff Law <law at redhat dot com>
- To: Marek Polacek <polacek at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Joseph Myers <joseph at codesourcery dot com>, David Malcolm <dmalcolm at redhat dot com>, Jason Merrill <jason at redhat dot com>
- Date: Fri, 1 Sep 2017 10:41:01 -0600
- Subject: Re: c-family PATCH to improve -Wtautological-compare (PR c/81783)
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=law at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A371485547
- References: <20170816142917.GB17069@redhat.com>
On 08/16/2017 08:29 AM, Marek Polacek wrote:
> This patch improves -Wtautological-compare so that it also detects
> bitwise comparisons involving & and | that are always true or false, e.g.
>
> if ((a & 16) == 10)
> return 1;
>
> can never be true. Note that e.g. "(a & 9) == 8" is *not* always false
> or true.
>
> I think it's pretty straightforward with one snag: we shouldn't warn if
> the constant part of the bitwise operation comes from a macro, but currently
> that's not possible, so I XFAILed this in the new test.
>
> This has found one issue in the GCC codebase and it's a genuine bug:
> <https://gcc.gnu.org/ml/gcc-patches/2017-08/msg00757.html>.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2017-08-16 Marek Polacek <polacek@redhat.com>
>
> PR c/81783
> * c-warn.c (warn_tautological_bitwise_comparison): New function.
> (warn_tautological_cmp): Call it.
>
> * doc/invoke.texi: Update -Wtautological-compare documentation.
>
> * c-c++-common/Wtautological-compare-5.c: New test.
OK.
jeff