[Clang] Extend -Wbool-operation to warn about bitwise and of bools with side effects
authorDávid Bolvanský <david.bolvansky@gmail.com>
Sun, 3 Oct 2021 09:06:19 +0000 (11:06 +0200)
committerDávid Bolvanský <david.bolvansky@gmail.com>
Sun, 3 Oct 2021 09:06:40 +0000 (11:06 +0200)
commitf62d18ff140f67a8776a7a3c62a75645d8d540b5
tree343ad3b972a6d043f13f624c56a3443ca14827fe
parentcf284f6c5ef34040bb28190509e2876242f85b49
[Clang] Extend -Wbool-operation to warn about bitwise and of bools with side effects

Motivation: https://arstechnica.com/gadgets/2021/07/google-pushed-a-one-character-typo-to-production-bricking-chrome-os-devices/

Warn for pattern boolA & boolB or boolA | boolB where boolA and boolB has possible side effects.

Casting one operand to int is enough to silence this warning: for example (int)boolA & boolB or boolA| (int)boolB

Fixes https://bugs.llvm.org/show_bug.cgi?id=51216

Differential Revision: https://reviews.llvm.org/D108003
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp
clang/test/Misc/warning-wall.c
clang/test/Sema/warn-bitwise-and-bool.c [new file with mode: 0644]
clang/test/Sema/warn-bitwise-or-bool.c [new file with mode: 0644]