[PATCH] D37565: [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 7 10:05:14 PDT 2017


rjmccall added inline comments.


================
Comment at: lib/Sema/SemaChecking.cpp:8592
+  bool BadR = !RType->isIntegerType() || RType->isSignedIntegerType() ||
+              RHS->isKnownToHaveBooleanValue();
+
----------------
Please extract a function which computes this for an Expr* and then call it as part of the conditions below, e.g.:

  if (op == BO_LT && isNonBooleanUnsignedValue(E->getLHS()) && IsZero(S, E->getRHS()))


================
Comment at: lib/Sema/SemaChecking.cpp:8879
+  if (IsComparisonConstant)
     return AnalyzeImpConvsInComparison(S, E);
   
----------------
Part of the purpose of checking for signed comparisons up here is to avoid unnecessarily computing ranges for the operands when we aren't going to use them.  That's still something we want to avoid.  I think you just need to call CheckTrivialUnsignedComparison in this fallback case, at least when the comparison is not constant.

You should also rename CheckTrivialUnsignedComparison to something like CheckTautologicalComparison.


Repository:
  rL LLVM

https://reviews.llvm.org/D37565





More information about the cfe-commits mailing list