[PATCH] D130510: Missing tautological compare warnings due to unary operators

Richard Trieu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 3 20:12:55 PDT 2022


rtrieu added a comment.

Can you add my earlier test case or something like it to SemaCXX/warn-bitwise-compare.cpp ?

  template <int I, class T>
  void foo(int x) {
      bool b1 = (x & sizeof(T)) == 8;
      bool b2 = (x & I) == 8;
      bool b3 = (x & 4) == 8;  // only warn here
  }
  
  void run(int x) {
      foo<4, int>(8);
  }



================
Comment at: clang/lib/Analysis/CFG.cpp:58
 #include <cassert>
+#include <iostream>
 #include <memory>
----------------
For debugging?

Have you tried `llvm::errs() << "message";` ?  A few streams are provided by LLVM support which most places have already, so no extra header is needed to make it work.


================
Comment at: clang/lib/Analysis/CFG.cpp:1023
+  // as -12.
+  llvm::APInt getIntegerLiteralSubexpressionValue(const Expr *E) {
+    // UnaryOperator identification.
----------------
Is this any better than just having the callers use EvaluateAsInt themselves?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130510



More information about the cfe-commits mailing list