• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_cc1 -Wcstring-format-directive -verify -fsyntax-only %s
2// rdar://19904147
3
4typedef __builtin_va_list __darwin_va_list;
5typedef __builtin_va_list va_list;
6
7va_list argList;
8
9typedef const struct __CFString * CFStringRef;
10typedef struct __CFString * CFMutableStringRef;
11typedef const struct __CFAllocator * CFAllocatorRef;
12
13
14typedef const struct __CFDictionary * CFDictionaryRef;
15
16CFStringRef CFSTR ( const char *cStr );
17
18
19extern
20CFStringRef CStringCreateWithFormat(CFAllocatorRef alloc, CFDictionaryRef formatOptions, const char* format, ...) __attribute__((format(os_trace, 3, 4)));
21
22extern
23CFStringRef CStringCreateWithFormatAndArguments(CFAllocatorRef alloc, CFDictionaryRef formatOptions, const char* format, va_list arguments) __attribute__((format(os_trace, 3, 0)));
24
25extern
26void CStringAppendFormat(CFMutableStringRef theString, CFDictionaryRef formatOptions, const char* format, ...) __attribute__((format(os_trace, 3, 4)));
27
28extern
29void CStringAppendFormatAndArguments(CFMutableStringRef theString, CFDictionaryRef formatOptions, const char* format, va_list arguments) __attribute__((format(os_trace, 3, 0)));
30
31void 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
39extern void MyOSLog(const char* format, ...) __attribute__((format(os_trace, 1, 2)));
40extern void MyFStringCreateWithFormat(const char *format, ...) __attribute__((format(os_trace, 1, 2)));
41extern void XMyOSLog(int, const char* format, ...) __attribute__((format(os_trace, 2, 3)));
42extern void os_trace(const char *format, ...) __attribute__((format(os_trace, 1, 2)));
43
44void 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