1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.RetainCount -verify -fblocks %s 2 3 @class NSString; 4 typedef long NSInteger; 5 typedef unsigned char BOOL; 6 @interface NSObject {} 7 +(id)alloc; 8 -(id)init; 9 -(id)autorelease; 10 -(id)copy; 11 -(id)retain; 12 @end 13 @interface NSNumber : NSObject 14 + (NSNumber *)numberWithInteger:(NSInteger)value __attribute__((availability(ios,introduced=2.0))); 15 @end 16 17 NSInteger *inoutIntegerValueGlobal; 18 NSInteger *inoutIntegerValueGlobal2; 19 NSString *traitNameGlobal; 20 static BOOL cond; 21 22 static inline void reallyPerformAction(void (^integerHandler)(NSInteger *inoutIntegerValue, NSString *traitName)) { 23 integerHandler(inoutIntegerValueGlobal, traitNameGlobal); 24 integerHandler(inoutIntegerValueGlobal2,traitNameGlobal); 25 } 26 27 static inline BOOL performAction(NSNumber *(^action)(NSNumber *traitValue)) { 28 __attribute__((__blocks__(byref))) BOOL didFindTrait = 0; 29 reallyPerformAction(^(NSInteger *inoutIntegerValue,NSString *traitName) { 30 31 if (cond) { 32 33 NSNumber *traitValue = @(*inoutIntegerValue); 34 35 NSNumber *newTraitValue = action(traitValue); 36 37 if (traitValue != newTraitValue) { 38 *inoutIntegerValue = newTraitValue ? *inoutIntegerValue : *inoutIntegerValue; 39 } 40 didFindTrait = 1; 41 } 42 43 }); 44 return didFindTrait; 45 } 46 47 void runTest() { 48 __attribute__((__blocks__(byref))) NSNumber *builtinResult = ((NSNumber *)0); 49 BOOL wasBuiltinTrait = performAction(^(NSNumber *traitValue) { 50 builtinResult = [traitValue retain]; // expected-warning {{Potential leak of an object}} 51 52 return traitValue; 53 }); 54 if (wasBuiltinTrait) { 55 [builtinResult autorelease]; 56 return; 57 } else { 58 return; 59 } 60 } 61