phunix/external/bsd/llvm/dist/clang/test/Analysis/objc-radar17039661.m
Lionel Sambuc 0a6a1f1d05 NetBSD re-synchronization of the source tree
This brings our tree to NetBSD 7.0, as found on -current on the
10-10-2015.

This updates:
 - LLVM to 3.6.1
 - GCC to GCC 5.1
 - Replace minix/commands/zdump with usr.bin/zdump
 - external/bsd/libelf has moved to /external/bsd/elftoolchain/
 - Import ctwm
 - Drop sprintf from libminc

Change-Id: I149836ac18e9326be9353958bab9b266efb056f0
2016-01-13 20:32:14 +01:00

61 lines
1.6 KiB
Objective-C

// RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.RetainCount -verify -fblocks %s
@class NSString;
typedef long NSInteger;
typedef unsigned char BOOL;
@interface NSObject {}
+(id)alloc;
-(id)init;
-(id)autorelease;
-(id)copy;
-(id)retain;
@end
@interface NSNumber : NSObject
+ (NSNumber *)numberWithInteger:(NSInteger)value __attribute__((availability(ios,introduced=2.0)));
@end
NSInteger *inoutIntegerValueGlobal;
NSInteger *inoutIntegerValueGlobal2;
NSString *traitNameGlobal;
static BOOL cond;
static inline void reallyPerformAction(void (^integerHandler)(NSInteger *inoutIntegerValue, NSString *traitName)) {
integerHandler(inoutIntegerValueGlobal, traitNameGlobal);
integerHandler(inoutIntegerValueGlobal2,traitNameGlobal);
}
static inline BOOL performAction(NSNumber *(^action)(NSNumber *traitValue)) {
__attribute__((__blocks__(byref))) BOOL didFindTrait = 0;
reallyPerformAction(^(NSInteger *inoutIntegerValue,NSString *traitName) {
if (cond) {
NSNumber *traitValue = @(*inoutIntegerValue);
NSNumber *newTraitValue = action(traitValue);
if (traitValue != newTraitValue) {
*inoutIntegerValue = newTraitValue ? *inoutIntegerValue : *inoutIntegerValue;
}
didFindTrait = 1;
}
});
return didFindTrait;
}
void runTest() {
__attribute__((__blocks__(byref))) NSNumber *builtinResult = ((NSNumber *)0);
BOOL wasBuiltinTrait = performAction(^(NSNumber *traitValue) {
builtinResult = [traitValue retain]; // expected-warning {{Potential leak of an object}}
return traitValue;
});
if (wasBuiltinTrait) {
[builtinResult autorelease];
return;
} else {
return;
}
}