variadic-method-types.m revision d5fde2106af8e78cc1b97d6369ad0de5d0875491
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
14
15typedef signed char BOOL;
16typedef struct _NSZone NSZone;
17typedef unsigned int NSUInteger;
18@protocol NSObject
19- (BOOL)isEqual:(id)object;
20- (oneway void)release;
21- (id)retain;
22- (id)autorelease;
23@end
24@protocol NSCopying
25- (id)copyWithZone:(NSZone *)zone;
26@end
27@protocol NSMutableCopying
28- (id)mutableCopyWithZone:(NSZone *)zone;
29@end
30@class NSCoder;
31@protocol NSCoding
32- (void)encodeWithCoder:(NSCoder *)aCoder;
33@end
34@interface NSObject <NSObject> {}
35- (id)init;
36+ (id)alloc;
37@end
38typedef struct {} NSFastEnumerationState;
39@protocol NSFastEnumeration
40- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
41@end
42@interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
43@end
44@interface NSArray (NSArrayCreation)
45+ (id)arrayWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
46- (id)initWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
47@end
48@interface NSDictionary : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
49@end
50@interface NSDictionary (NSDictionaryCreation)
51+ (id)dictionaryWithObjectsAndKeys:(id)firstObject, ... __attribute__((sentinel(0,1)));
52- (id)initWithObjectsAndKeys:(id)firstObject, ... __attribute__((sentinel(0,1)));
53@end
54@interface NSSet : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
55@end
56@interface NSSet (NSSetCreation)
57+ (id)setWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
58- (id)initWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
59@end
60@protocol P;
61@class C;
62
63void f(id a, id<P> b, C* c, C<P> *d) {
64  [NSArray arrayWithObjects:@"Hello", a, b, c, d, nil];
65
66  [NSArray arrayWithObjects:@"Foo", "Bar", "Baz", nil]; // expected-warning 2 {{Argument to 'NSArray' method 'arrayWithObjects:' should be an Objective-C pointer type, not 'char *'}}
67  [NSDictionary dictionaryWithObjectsAndKeys:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSDictionary' method 'dictionaryWithObjectsAndKeys:' should be an Objective-C pointer type, not 'char *'}}
68  [NSSet setWithObjects:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSSet' method 'setWithObjects:' should be an Objective-C pointer type, not 'char *'}}
69
70  [[[NSArray alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}}
71  [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjectsAndKeys:' should be an Objective-C pointer type, not 'char *'}}
72  [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", (void*) 0, nil] autorelease]; // no-warning
73  [[[NSSet alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}}
74}
75
76int main() {
77  f(nil, nil, nil, nil);
78}
79