[PATCH] D13126: New static analyzer checker for loss of sign/precision

Aleksei Sidorin via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 17 08:21:35 PST 2015


a.sidorin added a subscriber: a.sidorin.

================
Comment at: lib/StaticAnalyzer/Checkers/ConversionChecker.cpp:41
@@ +40,3 @@
+    const Stmt *Parent = PM.getParent(Cast);
+    if (!Parent)
+      return;
----------------
Parent should always exist for an implicit cast. May be it's better to assert here?

================
Comment at: lib/StaticAnalyzer/Checkers/ConversionChecker.cpp:49
@@ +48,3 @@
+    BinaryOperator::Opcode Opc = B->getOpcode();
+    if (Opc == BO_Assign || Opc == BO_MulAssign)
+      diagnoseLossOfPrecision(Cast, C);
----------------
It's not evident why do you omit other Assign operators here, like BO_SubAssign, BO_AddAssign and BO_DivAssign. As I see from your test, there are some problems with them. Could you add a comment?

================
Comment at: lib/StaticAnalyzer/Checkers/ConversionChecker.cpp:74
@@ +73,3 @@
+static bool isSigned(const Expr *E) {
+  const Type *T = E ? E->getType().getTypePtr() : nullptr;
+  return T && T->isSignedIntegerType();
----------------
Source sub-expression of cast expression we're visiting cannot be null and it should have non-null type. I think you can use something like `E->getType()->isSignedIntegerType()` instead of this function or you can use some assertions.


http://reviews.llvm.org/D13126





More information about the cfe-commits mailing list