[PATCH] D108003: [Clang] Extend -Wbool-operation to warn about bitwise and of bools with side effects

Dávid Bolvanský via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 12 16:04:43 PDT 2021


xbolva00 marked an inline comment as not done.
xbolva00 added inline comments.


================
Comment at: clang/test/Sema/warn-bitwise-and-bool.c:21-22
+void test(boolean a, boolean b, int i) {
+  b = a & b;
+  b = a & foo();      // expected-warning {{bitwise and of boolean expressions; did you mean logical and?}}
+                      // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:10}:"&&"
----------------
Quuxplusone wrote:
> So the warning triggers only when the RHS has side-effects? I'd like tests for
> ```
> foo() & a;  // should not trigger, by that logic, because && wouldn't short-circuit anything?
> (p != nullptr) & (*p == 42);  // should certainly trigger: deref is a side effect, and of course obviously this is a bug
> ```
Yes, but oh.

This is weird, HasSideEffects is false for this case. Works fine for volatile int.

@rsmith?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108003/new/

https://reviews.llvm.org/D108003



More information about the cfe-commits mailing list