summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-10-29 01:06:54 +0000
committerTed Kremenek <kremenek@apple.com>2010-10-29 01:06:54 +0000
commit310c5a8e317f2f31f2df41a1ab75e74d70f8d76a (patch)
tree3d8b74a9634ee5de8640797234bf24635f80dfae /clang
parent55ccf4e81f62fa51b395ead095bcf326ab5616d3 (diff)
downloadbcm5719-llvm-310c5a8e317f2f31f2df41a1ab75e74d70f8d76a.tar.gz
bcm5719-llvm-310c5a8e317f2f31f2df41a1ab75e74d70f8d76a.zip
Don't flag idempotent '+' or '-' warnings for pointer arithmetic (typically false positives).
Fixes <rdar://problem/8601243>. llvm-svn: 117635
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Checker/IdempotentOperationChecker.cpp7
-rw-r--r--clang/test/Analysis/idempotent-operations.c10
2 files changed, 17 insertions, 0 deletions
diff --git a/clang/lib/Checker/IdempotentOperationChecker.cpp b/clang/lib/Checker/IdempotentOperationChecker.cpp
index 3dcbea491eb..7b9ff755a77 100644
--- a/clang/lib/Checker/IdempotentOperationChecker.cpp
+++ b/clang/lib/Checker/IdempotentOperationChecker.cpp
@@ -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);
}
diff --git a/clang/test/Analysis/idempotent-operations.c b/clang/test/Analysis/idempotent-operations.c
index c673f0062f0..197357f800e 100644
--- a/clang/test/Analysis/idempotent-operations.c
+++ b/clang/test/Analysis/idempotent-operations.c
@@ -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;
+}
+
OpenPOWER on IntegriCloud