brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.0 KiB · 78f737b Raw
101 lines · plain
1// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,osx.cocoa.VariadicMethodTypes -fblocks -verify %s2 3//===----------------------------------------------------------------------===//4// The following code is reduced using delta-debugging from5// Foundation.h (Mac OS X).6//7// It includes the basic definitions for the test cases below.8// Not directly including Foundation.h directly makes this test case 9// both svelte and portable to non-Mac platforms.10//===----------------------------------------------------------------------===//11 12#define nil (void*)013typedef const struct __CFString * CFStringRef;14extern const CFStringRef kCGImageSourceShouldCache __attribute__((visibility("default")));15typedef signed char BOOL;16typedef struct _NSZone NSZone;17typedef unsigned int NSUInteger;18@protocol NSObject19- (BOOL)isEqual:(id)object;20- (oneway void)release;21- (id)retain;22- (id)autorelease;23@end24@protocol NSCopying25- (id)copyWithZone:(NSZone *)zone;26@end27@protocol NSMutableCopying28- (id)mutableCopyWithZone:(NSZone *)zone;29@end30@class NSCoder;31@protocol NSCoding32- (void)encodeWithCoder:(NSCoder *)aCoder;33@end34@interface NSObject <NSObject> {}35- (id)init;36+ (id)alloc;37@end38typedef struct {} NSFastEnumerationState;39@protocol NSFastEnumeration40- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;41@end42@interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>43@end44@interface NSArray (NSArrayCreation)45+ (id)arrayWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));46- (id)initWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));47@end48@interface NSDictionary : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>49@end50@interface NSDictionary (NSDictionaryCreation)51+ (id)dictionaryWithObjectsAndKeys:(id)firstObject, ... __attribute__((sentinel(0,1)));52- (id)initWithObjectsAndKeys:(id)firstObject, ... __attribute__((sentinel(0,1)));53@end54@interface NSSet : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>55@end56@interface NSSet (NSSetCreation)57+ (id)setWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));58- (id)initWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));59@end60@interface NSOrderedSet : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>61@end62@interface NSOrderedSet (NSOrderedSetCreation)63+ (id)orderedSetWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));64- (id)initWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));65@end66@protocol P;67@class C;68 69typedef struct FooType * __attribute__ ((NSObject)) FooType;70typedef struct BarType * BarType;71 72 73void f(id a, id<P> b, C* c, C<P> *d, FooType fooType, BarType barType) {74  [NSArray arrayWithObjects:@"Hello", a, b, c, d, nil];75  [NSArray arrayWithObjects:@"Foo", ^{}, nil];76 77  [NSArray arrayWithObjects:@"Foo", "Bar", "Baz", nil]; // expected-warning {{Argument to 'NSArray' method 'arrayWithObjects:' should be an Objective-C pointer type, not 'char *'}}78  [NSDictionary dictionaryWithObjectsAndKeys:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSDictionary' method 'dictionaryWithObjectsAndKeys:' should be an Objective-C pointer type, not 'char *'}}79  [NSSet setWithObjects:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSSet' method 'setWithObjects:' should be an Objective-C pointer type, not 'char *'}}80  [NSOrderedSet orderedSetWithObjects:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSOrderedSet' method 'orderedSetWithObjects:' should be an Objective-C pointer type, not 'char *'}}81 82  [[[NSArray alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to 'NSArray' method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}}83  [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to 'NSDictionary' method 'initWithObjectsAndKeys:' should be an Objective-C pointer type, not 'char *'}}84  [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", (void*) 0, nil] autorelease]; // no-warning85  [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", kCGImageSourceShouldCache, nil] autorelease]; // no-warning86  [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", fooType, nil] autorelease]; // no-warning87  [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", barType, nil] autorelease]; // expected-warning {{Argument to 'NSDictionary' method 'initWithObjectsAndKeys:' should be an Objective-C pointer type, not 'BarType'}}88  [[[NSSet alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to 'NSSet' method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}}89  [[[NSOrderedSet alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to 'NSOrderedSet' method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}}90}91 92// This previously crashed the variadic argument checker.93@protocol RDar927321594- (void)rdar9273215:(id)x, ...;95@end96 97void test_rdar9273215(id<RDar9273215> y) {98  return [y rdar9273215:y, y];99}100 101