[cfe-commits] r117635 - in /cfe/trunk: lib/Checker/IdempotentOperationChecker.cpp test/Analysis/idempotent-operations.c

Ted Kremenek kremenek at apple.com
Thu Oct 28 18:06:54 PDT 2010


Author: kremenek
Date: Thu Oct 28 20:06:54 2010
New Revision: 117635

URL: http://llvm.org/viewvc/llvm-project?rev=117635&view=rev
Log:
Don't flag idempotent '+' or '-' warnings for pointer arithmetic (typically false positives).

Fixes <rdar://problem/8601243>.

Modified:
    cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp
    cfe/trunk/test/Analysis/idempotent-operations.c

Modified: cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp?rev=117635&r1=117634&r2=117635&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp (original)
+++ cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp Thu Oct 28 20:06:54 2010
@@ -629,6 +629,13 @@
   // The next cases require recursion for subexpressions
   case Stmt::BinaryOperatorClass: {
     const BinaryOperator *B = cast<const BinaryOperator>(Ex);
+
+    // Exclude cases involving pointer arithmetic.  These are usually
+    // false positives.
+    if (B->getOpcode() == BO_Sub || B->getOpcode() == BO_Add)
+      if (B->getLHS()->getType()->getAs<PointerType>())
+        return false;
+
     return CanVary(B->getRHS(), AC)
         || CanVary(B->getLHS(), AC);
    }

Modified: cfe/trunk/test/Analysis/idempotent-operations.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/idempotent-operations.c?rev=117635&r1=117634&r2=117635&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/idempotent-operations.c (original)
+++ cfe/trunk/test/Analysis/idempotent-operations.c Thu Oct 28 20:06:54 2010
@@ -224,3 +224,13 @@
   return pred;
 }
 
+// <rdar://problem/8601243> - Don't warn on pointer arithmetic.  This
+// is often idiomatic.
+unsigned rdar8601243_aux(unsigned n);
+void rdar8601243() {
+  char arr[100];
+  char *start = arr;
+  start = start + rdar8601243_aux(sizeof(arr) - (arr - start)); // no-warning
+  (void) start;
+}
+





More information about the cfe-commits mailing list