• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,osx.cocoa.VariadicMethodTypes -analyzer-store=region -fblocks -verify %s
2
3//===----------------------------------------------------------------------===//
4// The following code is reduced using delta-debugging from
5// 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*)0
13typedef 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 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@interface NSOrderedSet : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
61@end
62@interface NSOrderedSet (NSOrderedSetCreation)
63+ (id)orderedSetWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
64- (id)initWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
65@end
66@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-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 *'}}
90}
91
92// This previously crashed the variadic argument checker.
93@protocol RDar9273215
94- (void)rdar9273215:(id)x, ...;
95@end
96
97void test_rdar9273215(id<RDar9273215> y) {
98  return [y rdar9273215:y, y];
99}
100
101