]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/Analysis/objc-radar17039661.m
Vendor import of clang trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / test / Analysis / objc-radar17039661.m
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.RetainCount -fblocks -verify %s
2 // RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.RetainCount -fblocks -analyzer-output=plist-multi-file %s -o %t
3 // RUN: cat %t | %diff_plist %S/Inputs/expected-plists/objc-radar17039661.m.plist -
4
5 @class NSString;
6 typedef long NSInteger;
7 typedef unsigned char BOOL;
8 @interface NSObject {}
9 +(id)alloc;
10 -(id)init;
11 -(id)autorelease;
12 -(id)copy;
13 -(id)retain;
14 @end
15 @interface NSNumber : NSObject
16 + (NSNumber *)numberWithInteger:(NSInteger)value __attribute__((availability(ios,introduced=2.0)));
17 @end
18 NSInteger *inoutIntegerValueGlobal;
19 NSInteger *inoutIntegerValueGlobal2;
20 NSString *traitNameGlobal;
21 static BOOL cond;
22
23 static 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
28 static 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
48 void runTest() {
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 }