blob: 306376dd57577342081889f1b7fc8afd9f487a5b [file] [log] [blame]
Ted Kremenekcdc3a892012-08-24 20:39:55 +00001// RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-checker=alpha.deadcode.IdempotentOperations,osx.cocoa.RetainCount -verify %s
Andy Gibbs8e8fb3b2012-10-19 12:44:48 +00002// expected-no-diagnostics
Ted Kremenek148849a2011-02-12 01:01:31 +00003
4typedef signed char BOOL;
5typedef unsigned long NSUInteger;
6typedef struct _NSZone NSZone;
7@protocol NSObject - (BOOL)isEqual:(id)object;
Ted Kremenek148849a2011-02-12 01:01:31 +00008@end
9
Ted Kremenek020c3742011-02-12 18:50:03 +000010@interface NSObject {}
11 @property int locked;
12 @property(nonatomic, readonly) NSObject *media;
13@end
Ted Kremenek148849a2011-02-12 01:01:31 +000014
15// <rdar://problem/8725041> - Don't flag idempotent operation warnings when
16// a method may invalidate an instance variable.
17@interface Rdar8725041 : NSObject {
18 id _attribute;
19}
20 - (void) method2;
21@end
22
23@implementation Rdar8725041
24- (BOOL) method1 {
25 BOOL needsUpdate = (BOOL)0;
26 id oldAttribute = _attribute;
27 [self method2];
28 needsUpdate |= (_attribute != oldAttribute); // no-warning
29 return needsUpdate;
30}
31
32- (void) method2
33{
34 _attribute = ((void*)0);
35}
36@end
37
Ted Kremenek020c3742011-02-12 18:50:03 +000038// Test that the idempotent operations checker works in the prescence
39// of property expressions.
40void pr9116(NSObject *placeholder) {
41 int x = placeholder.media.locked = placeholder ? 1 : 0;
42}
43
Ted Kremenekcf995d32011-03-15 19:27:57 +000044// <rdar://problem/9130239>: Test that calling property setters doesn't
45// trigger an assertion failure when the object is nil.
46@interface RDar9130239
47@property (assign) id delegate;
48@end
49
50void test_RDar9130239(RDar9130239 *x) {
51 if (x)
52 return;
53 x.delegate = x; // no-warning
54}
55