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