diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-10-29 01:06:54 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-10-29 01:06:54 +0000 |
commit | 74faec22ec84c54bcbd82cb6c48b72cb466b945f (patch) | |
tree | e64ceeac7ffce875c0406c1cc90624df76c07c42 | |
parent | 1dfb26af4d6aa4f7818e256659a79f1ec2cba784 (diff) |
Don't flag idempotent '+' or '-' warnings for pointer arithmetic (typically false positives).
Fixes <rdar://problem/8601243>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117635 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Checker/IdempotentOperationChecker.cpp | 7 | ||||
-rw-r--r-- | test/Analysis/idempotent-operations.c | 10 |
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/Checker/IdempotentOperationChecker.cpp b/lib/Checker/IdempotentOperationChecker.cpp index 3dcbea491e..7b9ff755a7 100644 --- a/lib/Checker/IdempotentOperationChecker.cpp +++ b/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/test/Analysis/idempotent-operations.c b/test/Analysis/idempotent-operations.c index c673f0062f..197357f800 100644 --- a/test/Analysis/idempotent-operations.c +++ b/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; +} + |