1f4a2713aSLionel Sambuc// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.core -analyzer-checker=deadcode.DeadStores,osx.cocoa.RetainCount -fblocks -verify -Wno-objc-root-class %s 2f4a2713aSLionel Sambuc// expected-no-diagnostics 3f4a2713aSLionel Sambuc 4f4a2713aSLionel Sambuctypedef signed char BOOL; 5f4a2713aSLionel Sambuctypedef unsigned int NSUInteger; 6f4a2713aSLionel Sambuctypedef struct _NSZone NSZone; 7f4a2713aSLionel Sambuc@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; 8f4a2713aSLionel Sambuc@protocol NSObject - (BOOL)isEqual:(id)object; @end 9f4a2713aSLionel Sambuc@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end 10f4a2713aSLionel Sambuc@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end 11f4a2713aSLionel Sambuc@interface NSObject <NSObject> {} @end 12f4a2713aSLionel Sambucextern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone); 13f4a2713aSLionel Sambuc@interface NSValue : NSObject <NSCopying, NSCoding> - (void)getValue:(void *)value; @end 14f4a2713aSLionel Sambuctypedef float CGFloat; 15f4a2713aSLionel Sambuctypedef struct _NSPoint {} NSRange; 16f4a2713aSLionel Sambuc@interface NSValue (NSValueRangeExtensions) + (NSValue *)valueWithRange:(NSRange)range; 17f4a2713aSLionel Sambuc- (BOOL)containsObject:(id)anObject; 18f4a2713aSLionel Sambuc@end 19f4a2713aSLionel Sambuc@class NSURLAuthenticationChallenge; 20f4a2713aSLionel Sambuc@interface NSResponder : NSObject <NSCoding> {} @end 21f4a2713aSLionel Sambuc@class NSArray, NSDictionary, NSString; 22f4a2713aSLionel Sambuc@interface NSObject (NSKeyValueBindingCreation) 23f4a2713aSLionel Sambuc+ (void)exposeBinding:(NSString *)binding; 24f4a2713aSLionel Sambuc- (NSArray *)exposedBindings; 25f4a2713aSLionel Sambuc@end 26f4a2713aSLionel Sambucextern NSString *NSAlignmentBinding; 27f4a2713aSLionel Sambuc 28f4a2713aSLionel Sambuc// This test case was reported as a false positive due to a bug in the 29f4a2713aSLionel Sambuc// LiveVariables <-> deadcode.DeadStores interplay. We should not flag a warning 30f4a2713aSLionel Sambuc// here. The test case was reported in: 31f4a2713aSLionel Sambuc// http://lists.cs.uiuc.edu/pipermail/cfe-dev/2008-July/002157.html 32f4a2713aSLionel Sambucvoid DeadStoreTest(NSObject *anObject) { 33f4a2713aSLionel Sambuc NSArray *keys; 34f4a2713aSLionel Sambuc if ((keys = [anObject exposedBindings]) && // no-warning 35f4a2713aSLionel Sambuc ([keys containsObject:@"name"] && [keys containsObject:@"icon"])) {} 36f4a2713aSLionel Sambuc} 37f4a2713aSLionel Sambuc 38f4a2713aSLionel Sambuc// This test case was a false positive due to how clang models 39f4a2713aSLionel Sambuc// pointer types and ObjC object pointer types differently. Here 40f4a2713aSLionel Sambuc// we don't warn about a dead store because 'nil' is assigned to 41f4a2713aSLionel Sambuc// an object pointer for the sake of defensive programming. 42f4a2713aSLionel Sambucvoid rdar_7631278(NSObject *x) { 43f4a2713aSLionel Sambuc x = ((void*)0); 44f4a2713aSLionel Sambuc} 45f4a2713aSLionel Sambuc 46f4a2713aSLionel Sambuc// This test case issuing a bogus warning for the declaration of 'isExec' 47f4a2713aSLionel Sambuc// because the compound statement for the @synchronized was being visited 48f4a2713aSLionel Sambuc// twice by the LiveVariables analysis. 49f4a2713aSLionel SambucBOOL baz_rdar8527823(); 50f4a2713aSLionel Sambucvoid foo_rdar8527823(); 51f4a2713aSLionel Sambuc@interface RDar8527823 52f4a2713aSLionel Sambuc- (void) bar_rbar8527823; 53f4a2713aSLionel Sambuc@end 54f4a2713aSLionel Sambuc@implementation RDar8527823 55f4a2713aSLionel Sambuc- (void) bar_rbar8527823 56f4a2713aSLionel Sambuc{ 57f4a2713aSLionel Sambuc @synchronized(self) { 58f4a2713aSLionel Sambuc BOOL isExec = baz_rdar8527823(); // no-warning 59f4a2713aSLionel Sambuc if (isExec) foo_rdar8527823(); 60f4a2713aSLionel Sambuc } 61f4a2713aSLionel Sambuc} 62f4a2713aSLionel Sambuc@end 63f4a2713aSLionel Sambuc 64f4a2713aSLionel Sambuc// Don't flag dead stores to assignments to self within a nested assignment. 65f4a2713aSLionel Sambuc@interface Rdar7947686 66f4a2713aSLionel Sambuc- (id) init; 67f4a2713aSLionel Sambuc@end 68f4a2713aSLionel Sambuc 69f4a2713aSLionel Sambuc@interface Rdar7947686_B : Rdar7947686 70f4a2713aSLionel Sambuc- (id) init; 71f4a2713aSLionel Sambuc@end 72f4a2713aSLionel Sambuc 73f4a2713aSLionel Sambuc@implementation Rdar7947686_B 74f4a2713aSLionel Sambuc- (id) init { 75f4a2713aSLionel Sambuc id x = (self = [super init]); // no-warning 76f4a2713aSLionel Sambuc return x; 77f4a2713aSLionel Sambuc} 78f4a2713aSLionel Sambuc@end 79f4a2713aSLionel Sambuc 80f4a2713aSLionel Sambuc// Don't flag dead stores when a variable is captured in a block used 81f4a2713aSLionel Sambuc// by a property access. 82f4a2713aSLionel Sambuc@interface RDar10591355 83f4a2713aSLionel Sambuc@property (assign) int x; 84f4a2713aSLionel Sambuc@end 85f4a2713aSLionel Sambuc 86f4a2713aSLionel SambucRDar10591355 *rdar10591355_aux(); 87f4a2713aSLionel Sambuc 88f4a2713aSLionel Sambucvoid rdar10591355() { 89f4a2713aSLionel Sambuc RDar10591355 *p = rdar10591355_aux(); 90f4a2713aSLionel Sambuc ^{ (void) p.x; }(); 91f4a2713aSLionel Sambuc} 92f4a2713aSLionel Sambuc 93f4a2713aSLionel Sambuc@interface Radar11059352_1 { 94f4a2713aSLionel Sambuc@private 95f4a2713aSLionel Sambuc int *_pathString; 96f4a2713aSLionel Sambuc} 97f4a2713aSLionel Sambuc@property int *pathString; 98f4a2713aSLionel Sambuc@end 99f4a2713aSLionel Sambuc@interface Radar11059352 { 100f4a2713aSLionel Sambuc@private 101f4a2713aSLionel SambucRadar11059352_1 *_Path; 102f4a2713aSLionel Sambuc} 103f4a2713aSLionel Sambuc@end 104f4a2713aSLionel Sambuc@implementation Radar11059352 105f4a2713aSLionel Sambuc 106f4a2713aSLionel Sambuc- (int*)usePath { 107f4a2713aSLionel Sambuc Radar11059352_1 *xxxxx = _Path; // no warning 108f4a2713aSLionel Sambuc int *wp = xxxxx.pathString; 109f4a2713aSLionel Sambuc return wp; 110f4a2713aSLionel Sambuc} 111f4a2713aSLionel Sambuc@end 112*0a6a1f1dSLionel Sambuc 113*0a6a1f1dSLionel Sambucid test_objc_precise_lifetime_foo(); 114*0a6a1f1dSLionel Sambucvoid test_objc_precise_lifetime() { 115*0a6a1f1dSLionel Sambuc __attribute__((objc_precise_lifetime)) id dead = test_objc_precise_lifetime_foo(); // no-warning 116*0a6a1f1dSLionel Sambuc dead = 0; 117*0a6a1f1dSLionel Sambuc dead = test_objc_precise_lifetime_foo(); // no-warning 118*0a6a1f1dSLionel Sambuc dead = 0; 119*0a6a1f1dSLionel Sambuc} 120