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