• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_cc1 -fsyntax-only -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 including Foundation.h directly makes this test case both svelt and
9// portable to non-Mac platforms.
10//===----------------------------------------------------------------------===//
11
12typedef signed char BOOL;
13typedef unsigned int NSUInteger;
14@class NSString, Protocol;
15extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
16typedef struct _NSZone NSZone;
17@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
18@protocol NSObject  - (BOOL)isEqual:(id)object; @end
19@protocol NSCopying  - (id)copyWithZone:(NSZone *)zone; @end
20@protocol NSMutableCopying  - (id)mutableCopyWithZone:(NSZone *)zone; @end
21@protocol NSCoding  - (void)encodeWithCoder:(NSCoder *)aCoder; @end
22@interface NSObject <NSObject> {} @end
23typedef float CGFloat;
24@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>    - (NSUInteger)length; @end
25@interface NSSimpleCString : NSString {} @end
26@interface NSConstantString : NSSimpleCString @end
27extern void *_NSConstantStringClassReference;
28
29typedef const struct __CFString * CFStringRef;
30extern void CFStringCreateWithFormat(CFStringRef format, ...) __attribute__((format(CFString, 1, 2)));
31
32int printf(const char * restrict, ...) ;
33
34//===----------------------------------------------------------------------===//
35// Test cases.
36//===----------------------------------------------------------------------===//
37
38void check_nslog(unsigned k) {
39  NSLog(@"%d%%", k); // no-warning
40  NSLog(@"%s%lb%d", "unix", 10,20); // expected-warning {{invalid conversion specifier 'b'}}
41}
42
43// Check type validation
44extern void NSLog2(int format, ...) __attribute__((format(__NSString__, 1, 2))); // expected-error {{format argument not an NSString}}
45extern void CFStringCreateWithFormat2(int *format, ...) __attribute__((format(CFString, 1, 2))); // expected-error {{format argument not a CFString}}
46
47// <rdar://problem/7068334> - Catch use of long long with int arguments.
48void rdar_7068334() {
49  long long test = 500;
50  printf("%i ",test); // expected-warning{{conversion specifies type 'int' but the argument has type 'long long'}}
51  NSLog(@"%i ",test); // expected-warning{{conversion specifies type 'int' but the argument has type 'long long'}}
52}
53
54// <rdar://problem/7697748>
55void rdar_7697748() {
56  NSLog(@"%@!"); // expected-warning{{more '%' conversions than data arguments}}
57}
58
59@protocol Foo;
60
61void test_p_conversion_with_objc_pointer(id x, id<Foo> y) {
62  printf("%p", x); // no-warning
63  printf("%p", y); // no-warning
64}
65
66