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