]> granicus.if.org Git - clang/commit
New tautological warning for bitwise-or with non-zero constant always true.
authorRichard Trieu <rtrieu@google.com>
Sat, 19 Oct 2019 00:57:23 +0000 (00:57 +0000)
committerRichard Trieu <rtrieu@google.com>
Sat, 19 Oct 2019 00:57:23 +0000 (00:57 +0000)
commita27ae544f30bfd7dc765b8a6080190d39d893b99
tree20f6b66320ee0e421f33e6e54eab73db57932762
parent7decfe83555385bebac2e4bed35035f3b0f4d666
New tautological warning for bitwise-or with non-zero constant always true.

Taking a value and the bitwise-or it with a non-zero constant will always
result in a non-zero value. In a boolean context, this is always true.

if (x | 0x4) {}  // always true, intended '&'

This patch creates a new warning group -Wtautological-bitwise-compare for this
warning. It also moves in the existing tautological bitwise comparisons into
this group. A few other changes were needed to the CFGBuilder so that all bool
contexts would be checked. The warnings in -Wtautological-bitwise-compare will
be off by default due to using the CFG.

Fixes: https://bugs.llvm.org/show_bug.cgi?id=42666
Differential Revision: https://reviews.llvm.org/D66046

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@375318 91177308-0d34-0410-b5e6-96231b3b80d8
docs/ReleaseNotes.rst
include/clang/Analysis/CFG.h
include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
lib/Analysis/CFG.cpp
lib/Sema/AnalysisBasedWarnings.cpp
test/Sema/warn-bitwise-compare.c
test/SemaCXX/warn-bitwise-compare.cpp [new file with mode: 0644]