blob: 4ed71c4e8bfa72129b72ee6d1017fe5995eaaa3c [file] [log] [blame]
Jordy Rose17a38e22011-09-02 05:55:19 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=experimental.core -analyzer-checker=deadcode.DeadStores,osx.cocoa.RetainCount -verify %s
Ted Kremenek03648652008-07-03 22:25:27 +00002
3typedef signed char BOOL;
4typedef unsigned int NSUInteger;
5typedef struct _NSZone NSZone;
6@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
7@protocol NSObject - (BOOL)isEqual:(id)object; @end
8@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end
9@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end
10@interface NSObject <NSObject> {} @end
11extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
12@interface NSValue : NSObject <NSCopying, NSCoding> - (void)getValue:(void *)value; @end
13typedef float CGFloat;
14typedef struct _NSPoint {} NSRange;
15@interface NSValue (NSValueRangeExtensions) + (NSValue *)valueWithRange:(NSRange)range;
16- (BOOL)containsObject:(id)anObject;
17@end
18@class NSURLAuthenticationChallenge;
19@interface NSResponder : NSObject <NSCoding> {} @end
20@class NSArray, NSDictionary, NSString;
21@interface NSObject (NSKeyValueBindingCreation)
22+ (void)exposeBinding:(NSString *)binding;
23- (NSArray *)exposedBindings;
24@end
25extern NSString *NSAlignmentBinding;
26
27// This test case was reported as a false positive due to a bug in the
Ted Kremenekade31952011-03-12 06:14:28 +000028// LiveVariables <-> deadcode.DeadStores interplay. We should not flag a warning
Ted Kremenek03648652008-07-03 22:25:27 +000029// here. The test case was reported in:
30// http://lists.cs.uiuc.edu/pipermail/cfe-dev/2008-July/002157.html
31void DeadStoreTest(NSObject *anObject) {
32 NSArray *keys;
33 if ((keys = [anObject exposedBindings]) && // no-warning
34 ([keys containsObject:@"name"] && [keys containsObject:@"icon"])) {}
35}
36
Ted Kremenek89132202010-02-23 21:19:33 +000037// This test case was a false positive due to how clang models
38// pointer types and ObjC object pointer types differently. Here
39// we don't warn about a dead store because 'nil' is assigned to
40// an object pointer for the sake of defensive programming.
41void rdar_7631278(NSObject *x) {
42 x = ((void*)0);
43}
Ted Kremenekf50595d2010-10-22 22:08:32 +000044
45// This test case issuing a bogus warning for the declaration of 'isExec'
46// because the compound statement for the @synchronized was being visited
47// twice by the LiveVariables analysis.
48BOOL baz_rdar8527823();
49void foo_rdar8527823();
50@interface RDar8527823
51- (void) bar_rbar8527823;
52@end
53@implementation RDar8527823
54- (void) bar_rbar8527823
55{
56 @synchronized(self) {
57 BOOL isExec = baz_rdar8527823(); // no-warning
58 if (isExec) foo_rdar8527823();
59 }
60}
61@end
Ted Kremenekbf5c3ac2011-02-01 20:45:26 +000062
63// Don't flag dead stores to assignments to self within a nested assignment.
64@interface Rdar7947686
65- (id) init;
66@end
67
68@interface Rdar7947686_B : Rdar7947686
69- (id) init;
70@end
71
72@implementation Rdar7947686_B
73- (id) init {
74 id x = (self = [super init]); // no-warning
75 return x;
76}
77@end
78