variadic-method-types.m revision 928c415d5dde89b7c01e41f0dfa8a782cbfa8e7d
1// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,cocoa.VariadicMethodTypes -analyzer-store=basic -fblocks -verify %s
2// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,cocoa.VariadicMethodTypes -analyzer-store=region -fblocks -verify %s
3
4//===----------------------------------------------------------------------===//
5// The following code is reduced using delta-debugging from
6// Foundation.h (Mac OS X).
7//
8// It includes the basic definitions for the test cases below.
9// Not directly including Foundation.h directly makes this test case 
10// both svelte and portable to non-Mac platforms.
11//===----------------------------------------------------------------------===//
12
13#define nil (void*)0
14typedef const struct __CFString * CFStringRef;
15extern const CFStringRef kCGImageSourceShouldCache __attribute__((visibility("default")));
16typedef signed char BOOL;
17typedef struct _NSZone NSZone;
18typedef unsigned int NSUInteger;
19@protocol NSObject
20- (BOOL)isEqual:(id)object;
21- (oneway void)release;
22- (id)retain;
23- (id)autorelease;
24@end
25@protocol NSCopying
26- (id)copyWithZone:(NSZone *)zone;
27@end
28@protocol NSMutableCopying
29- (id)mutableCopyWithZone:(NSZone *)zone;
30@end
31@class NSCoder;
32@protocol NSCoding
33- (void)encodeWithCoder:(NSCoder *)aCoder;
34@end
35@interface NSObject <NSObject> {}
36- (id)init;
37+ (id)alloc;
38@end
39typedef struct {} NSFastEnumerationState;
40@protocol NSFastEnumeration
41- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
42@end
43@interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
44@end
45@interface NSArray (NSArrayCreation)
46+ (id)arrayWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
47- (id)initWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
48@end
49@interface NSDictionary : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
50@end
51@interface NSDictionary (NSDictionaryCreation)
52+ (id)dictionaryWithObjectsAndKeys:(id)firstObject, ... __attribute__((sentinel(0,1)));
53- (id)initWithObjectsAndKeys:(id)firstObject, ... __attribute__((sentinel(0,1)));
54@end
55@interface NSSet : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
56@end
57@interface NSSet (NSSetCreation)
58+ (id)setWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
59- (id)initWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
60@end
61@protocol P;
62@class C;
63
64void f(id a, id<P> b, C* c, C<P> *d) {
65  [NSArray arrayWithObjects:@"Hello", a, b, c, d, nil];
66
67  [NSArray arrayWithObjects:@"Foo", "Bar", "Baz", nil]; // expected-warning 2 {{Argument to 'NSArray' method 'arrayWithObjects:' should be an Objective-C pointer type, not 'char *'}}
68  [NSDictionary dictionaryWithObjectsAndKeys:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSDictionary' method 'dictionaryWithObjectsAndKeys:' should be an Objective-C pointer type, not 'char *'}}
69  [NSSet setWithObjects:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSSet' method 'setWithObjects:' should be an Objective-C pointer type, not 'char *'}}
70
71  [[[NSArray alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}}
72  [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjectsAndKeys:' should be an Objective-C pointer type, not 'char *'}}
73  [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", (void*) 0, nil] autorelease]; // no-warning
74  [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", kCGImageSourceShouldCache, nil] autorelease]; // no-warning
75  [[[NSSet alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}}
76}
77
78int main() {
79  f(nil, nil, nil, nil);
80}
81