From c059798756b4ffca77a209178dbcc1850a62b4a0 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Sat, 12 Feb 2011 18:50:03 +0000 Subject: [PATCH] Teach the IdempotentOperations checker to ignore property setters. llvm-svn: 125443 --- .../Checkers/IdempotentOperationChecker.cpp | 11 +++++++++-- clang/test/Analysis/idempotent-operations.m | 12 ++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp index 633648ec6c22..7f64f8e2c40a 100644 --- a/clang/lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp @@ -357,8 +357,15 @@ void IdempotentOperationChecker::PostVisitBinaryOperator( const BinaryOperator *B) { // Add the ExplodedNode we just visited BinaryOperatorData &Data = hash[B]; - assert(isa(cast(C.getPredecessor() - ->getLocation()).getStmt())); + + const Stmt *predStmt + = cast(C.getPredecessor()->getLocation()).getStmt(); + + // Ignore implicit calls to setters. + if (isa(predStmt)) + return; + + assert(isa(predStmt)); Data.explodedNodes.Add(C.getPredecessor()); } diff --git a/clang/test/Analysis/idempotent-operations.m b/clang/test/Analysis/idempotent-operations.m index 3f68206b168f..bda98fa71713 100644 --- a/clang/test/Analysis/idempotent-operations.m +++ b/clang/test/Analysis/idempotent-operations.m @@ -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 { -} @end +@interface NSObject {} + @property int locked; + @property(nonatomic, readonly) NSObject *media; +@end // - 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; +} +