r373614 - [Diagnostics] Bitwise negation of a boolean expr always evaluates to true; warn with -Wbool-operation

Nico Weber via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 3 08:32:09 PDT 2019


Thanks for the fix!

This seems like a very safe warning from a distance, so I too hope that it
won't fire. I'll let you know how it goes.

If you're very curious,
https://ci.chromium.org/p/chromium/g/chromium.clang/console are our bots
that build trunk clang and then chromium with it.

(Currently the LLLVM build is broken with gcc5.3 host compilers apparently,
hence lots of red.)

On Thu, Oct 3, 2019 at 11:26 AM Dávid Bolvanský <david.bolvansky at gmail.com>
wrote:

> Fixed. I manually svncommited only specific files since I have other
> changes and forgot to add that file too.
> Sorry. Please evaluate this on Chromium. Since ~bool is always true, I
> dont think we are gonna have any false positives..
>
> št 3. 10. 2019 o 17:23 Nico Weber <thakis at chromium.org> napísal(a):
> >
> > ../../clang/lib/Sema/SemaExpr.cpp:13481:25: error: no member named
> 'warn_bitwise_negation_bool' in namespace 'clang::diag'
> >       Diag(OpLoc, diag::warn_bitwise_negation_bool)
> >                   ~~~~~~^
> > 1 error generated.
> >
> > On Thu, Oct 3, 2019 at 11:16 AM David Bolvansky via cfe-commits <
> cfe-commits at lists.llvm.org> wrote:
> >>
> >> Author: xbolva00
> >> Date: Thu Oct  3 08:17:59 2019
> >> New Revision: 373614
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=373614&view=rev
> >> Log:
> >> [Diagnostics] Bitwise negation of a boolean expr always evaluates to
> true; warn with -Wbool-operation
> >>
> >> Requested here:
> >> http://lists.llvm.org/pipermail/cfe-dev/2019-October/063452.html
> >>
> >>
> >> Added:
> >>     cfe/trunk/test/Sema/warn-bitwise-negation-bool.c
> >> Modified:
> >>     cfe/trunk/lib/Sema/SemaExpr.cpp
> >>
> >> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> >> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=373614&r1=373613&r2=373614&view=diff
> >>
> ==============================================================================
> >> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> >> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Oct  3 08:17:59 2019
> >> @@ -13470,7 +13470,6 @@ ExprResult Sema::CreateBuiltinUnaryOp(So
> >>      if (Input.isInvalid())
> >>        return ExprError();
> >>      resultType = Input.get()->getType();
> >> -
> >>      if (resultType->isDependentType())
> >>        break;
> >>      // C99 6.5.3.3p1. We allow complex int and float as a GCC
> extension.
> >> @@ -13478,6 +13477,9 @@ ExprResult Sema::CreateBuiltinUnaryOp(So
> >>        // C99 does not support '~' for complex conjugation.
> >>        Diag(OpLoc, diag::ext_integer_complement_complex)
> >>            << resultType << Input.get()->getSourceRange();
> >> +    else if
> (Input.get()->IgnoreParenImpCasts()->getType()->isBooleanType())
> >> +      Diag(OpLoc, diag::warn_bitwise_negation_bool)
> >> +          << FixItHint::CreateReplacement(OpLoc, "!");
> >>      else if (resultType->hasIntegerRepresentation())
> >>        break;
> >>      else if (resultType->isExtVectorType() &&
> Context.getLangOpts().OpenCL) {
> >>
> >> Added: cfe/trunk/test/Sema/warn-bitwise-negation-bool.c
> >> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-bitwise-negation-bool.c?rev=373614&view=auto
> >>
> ==============================================================================
> >> --- cfe/trunk/test/Sema/warn-bitwise-negation-bool.c (added)
> >> +++ cfe/trunk/test/Sema/warn-bitwise-negation-bool.c Thu Oct  3
> 08:17:59 2019
> >> @@ -0,0 +1,20 @@
> >> +// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wbool-operation %s
> >> +// RUN: %clang_cc1 -x c -fsyntax-only -verify %s
> >> +// RUN: %clang_cc1 -x c -fsyntax-only -fdiagnostics-parseable-fixits
> %s 2>&1 | FileCheck %s
> >> +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wbool-operation %s
> >> +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
> >> +// RUN: %clang_cc1 -x c++ -fsyntax-only -fdiagnostics-parseable-fixits
> %s 2>&1 | FileCheck %s
> >> +
> >> +#ifdef __cplusplus
> >> +typedef bool boolean;
> >> +#else
> >> +typedef _Bool boolean;
> >> +#endif
> >> +
> >> +void test(boolean b, int i) {
> >> +  b = ~b; // expected-warning {{bitwise negation of a boolean
> expression always evaluates to 'true'}}
> >> +  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
> >> +  b = ~(b); // expected-warning {{bitwise negation of a boolean
> expression always evaluates to 'true'}}
> >> +  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
> >> +  b = ~i;
> >> +}
> >>
> >>
> >> _______________________________________________
> >> cfe-commits mailing list
> >> cfe-commits at lists.llvm.org
> >> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191003/ab111751/attachment-0001.html>


More information about the cfe-commits mailing list