Teach the IdempotentOperations checker to ignore property setters.

llvm-svn: 125443
This commit is contained in:
Ted Kremenek 2011-02-12 18:50:03 +00:00
parent 210ce0feb5
commit c059798756
2 changed files with 19 additions and 4 deletions

View File

@ -357,8 +357,15 @@ void IdempotentOperationChecker::PostVisitBinaryOperator(
const BinaryOperator *B) {
// Add the ExplodedNode we just visited
BinaryOperatorData &Data = hash[B];
assert(isa<BinaryOperator>(cast<StmtPoint>(C.getPredecessor()
->getLocation()).getStmt()));
const Stmt *predStmt
= cast<StmtPoint>(C.getPredecessor()->getLocation()).getStmt();
// Ignore implicit calls to setters.
if (isa<ObjCPropertyRefExpr>(predStmt))
return;
assert(isa<BinaryOperator>(predStmt));
Data.explodedNodes.Add(C.getPredecessor());
}

View File

@ -4,10 +4,12 @@ typedef signed char BOOL;
typedef unsigned long NSUInteger;
typedef struct _NSZone NSZone;
@protocol NSObject - (BOOL)isEqual:(id)object;
@end @interface NSObject <NSObject> {
}
@end
@interface NSObject {}
@property int locked;
@property(nonatomic, readonly) NSObject *media;
@end
// <rdar://problem/8725041> - Don't flag idempotent operation warnings when
// a method may invalidate an instance variable.
@ -32,3 +34,9 @@ typedef struct _NSZone NSZone;
}
@end
// Test that the idempotent operations checker works in the prescence
// of property expressions.
void pr9116(NSObject *placeholder) {
int x = placeholder.media.locked = placeholder ? 1 : 0;
}