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 -Wtautological-compare (PR c/81783)


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


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