]> granicus.if.org Git - clang/commitdiff
Don't flag idempotent '+' or '-' warnings for pointer arithmetic (typically false...
authorTed Kremenek <kremenek@apple.com>
Fri, 29 Oct 2010 01:06:54 +0000 (01:06 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 29 Oct 2010 01:06:54 +0000 (01:06 +0000)
Fixes <rdar://problem/8601243>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117635 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Checker/IdempotentOperationChecker.cpp
test/Analysis/idempotent-operations.c

index 3dcbea491eb7b263011910f91f744d9a2142dccf..7b9ff755a779c2e124126a44ecf2aa7455f4a436 100644 (file)
@@ -629,6 +629,13 @@ bool IdempotentOperationChecker::CanVary(const Expr *Ex,
   // 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);
    }
index c673f0062f0e35d109138787fe73c61962e162ad..197357f800e753078595d3dad85ff52f9e341c20 100644 (file)
@@ -224,3 +224,13 @@ static inline int RDar8431728_C(RDar8431728_D * s, int n,
   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;
+}
+