| 1 |
// RUN: %clang_cc1 -Wcstring-format-directive -verify -fsyntax-only %s |
| 2 |
|
| 3 |
typedef __builtin_va_list __darwin_va_list; |
| 4 |
typedef __builtin_va_list va_list; |
| 5 |
|
| 6 |
va_list argList; |
| 7 |
|
| 8 |
typedef const struct __CFString * CFStringRef; |
| 9 |
typedef struct __CFString * CFMutableStringRef; |
| 10 |
typedef const struct __CFAllocator * CFAllocatorRef; |
| 11 |
|
| 12 |
|
| 13 |
typedef const struct __CFDictionary * CFDictionaryRef; |
| 14 |
|
| 15 |
CFStringRef CFSTR ( const char *cStr ); |
| 16 |
|
| 17 |
|
| 18 |
extern |
| 19 |
CFStringRef CStringCreateWithFormat(CFAllocatorRef alloc, CFDictionaryRef formatOptions, const char* format, ...) __attribute__((format(os_trace, 3, 4))); |
| 20 |
|
| 21 |
extern |
| 22 |
CFStringRef CStringCreateWithFormatAndArguments(CFAllocatorRef alloc, CFDictionaryRef formatOptions, const char* format, va_list arguments) __attribute__((format(os_trace, 3, 0))); |
| 23 |
|
| 24 |
extern |
| 25 |
void CStringAppendFormat(CFMutableStringRef theString, CFDictionaryRef formatOptions, const char* format, ...) __attribute__((format(os_trace, 3, 4))); |
| 26 |
|
| 27 |
extern |
| 28 |
void CStringAppendFormatAndArguments(CFMutableStringRef theString, CFDictionaryRef formatOptions, const char* format, va_list arguments) __attribute__((format(os_trace, 3, 0))); |
| 29 |
|
| 30 |
void Test1(va_list argList) { |
| 31 |
CFAllocatorRef alloc; |
| 32 |
CStringCreateWithFormatAndArguments (alloc, 0, "%s\n", argList); |
| 33 |
CStringAppendFormatAndArguments ((CFMutableStringRef)@"AAAA", 0, "Hello %s there %d\n", argList); |
| 34 |
CStringCreateWithFormatAndArguments (alloc, 0, "%c\n", argList); |
| 35 |
CStringAppendFormatAndArguments ((CFMutableStringRef)@"AAAA", 0, "%d\n", argList); |
| 36 |
} |
| 37 |
|
| 38 |
extern void MyOSLog(const char* format, ...) __attribute__((format(os_trace, 1, 2))); |
| 39 |
extern void MyFStringCreateWithFormat(const char *format, ...) __attribute__((format(os_trace, 1, 2))); |
| 40 |
extern void XMyOSLog(int, const char* format, ...) __attribute__((format(os_trace, 2, 3))); |
| 41 |
extern void os_trace(const char *format, ...) __attribute__((format(os_trace, 1, 2))); |
| 42 |
|
| 43 |
void Test2(void) { |
| 44 |
MyOSLog("%s\n", "Hello"); |
| 45 |
|
| 46 |
MyFStringCreateWithFormat("%s", "Hello"); |
| 47 |
XMyOSLog(4, "%s\n", "Hello"); |
| 48 |
|
| 49 |
os_trace("testing %@, %s, %d, %@, %m", CFSTR("object"), "string", 3, "it"); // expected-warning {{format specifies type 'id' but the argument has type 'char *'}} |
| 50 |
|
| 51 |
os_trace("testing %@, %s, %d, %@, %m", CFSTR("object"), "string", 3, @"ok"); |
| 52 |
} |
| 53 |
|