1 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,osx.cocoa.VariadicMethodTypes -fblocks -verify %s
3 //===----------------------------------------------------------------------===//
4 // The following code is reduced using delta-debugging from
5 // Foundation.h (Mac OS X).
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 //===----------------------------------------------------------------------===//
13 typedef const struct __CFString * CFStringRef;
14 extern const CFStringRef kCGImageSourceShouldCache __attribute__((visibility("default")));
15 typedef signed char BOOL;
16 typedef struct _NSZone NSZone;
17 typedef unsigned int NSUInteger;
19 - (BOOL)isEqual:(id)object;
20 - (oneway void)release;
25 - (id)copyWithZone:(NSZone *)zone;
27 @protocol NSMutableCopying
28 - (id)mutableCopyWithZone:(NSZone *)zone;
32 - (void)encodeWithCoder:(NSCoder *)aCoder;
34 @interface NSObject <NSObject> {}
38 typedef struct {} NSFastEnumerationState;
39 @protocol NSFastEnumeration
40 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
42 @interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
44 @interface NSArray (NSArrayCreation)
45 + (id)arrayWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
46 - (id)initWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
48 @interface NSDictionary : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
50 @interface NSDictionary (NSDictionaryCreation)
51 + (id)dictionaryWithObjectsAndKeys:(id)firstObject, ... __attribute__((sentinel(0,1)));
52 - (id)initWithObjectsAndKeys:(id)firstObject, ... __attribute__((sentinel(0,1)));
54 @interface NSSet : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
56 @interface NSSet (NSSetCreation)
57 + (id)setWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
58 - (id)initWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
60 @interface NSOrderedSet : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
62 @interface NSOrderedSet (NSOrderedSetCreation)
63 + (id)orderedSetWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
64 - (id)initWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
69 typedef struct FooType * __attribute__ ((NSObject)) FooType;
70 typedef struct BarType * BarType;
73 void 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];
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 *'}}
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-warning
85 [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", kCGImageSourceShouldCache, nil] autorelease]; // no-warning
86 [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", fooType, nil] autorelease]; // no-warning
87 [[[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 *'}}
92 // This previously crashed the variadic argument checker.
94 - (void)rdar9273215:(id)x, ...;
97 void test_rdar9273215(id<RDar9273215> y) {
98 return [y rdar9273215:y, y];