[PATCH] D66046: Add new tautological compare warning for bitwise-or with a non-zero constant

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 16 16:34:15 PDT 2019


NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Looks great, thank you!



================
Comment at: lib/Analysis/CFG.cpp:1118
+    Expr::EvalResult Result;
+    if (!Constant->EvaluateAsInt(Result, *Context))
+      return {};
----------------
rtrieu wrote:
> NoQ wrote:
> > It's kinda strange to me that we first confirm that it's a constant by doing `tryTransformToIntOrEnumConstant`, but then fire up the heavy machinery of `EvaluateAsInt` anyway. Did you consider using only `EvaluateAsInt()` to begin with? I guess you're trying to make sure that "the user's intent is clear" as other similar warnings do, right? Could you comment on that?
> A new function has been created to check the zero-ness of the Expr.  Since we know it the Expr comes from tryTransformToIntOrEnumConstant, this function doesn't have to handle the full Expr sub-classes.
Whoa!


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

https://reviews.llvm.org/D66046





More information about the cfe-commits mailing list