xref: /llvm-project/clang/test/SemaObjC/format-ostrace-warning.m (revision 0f1c1be1968076d6f96f8a7bcc4a15cf195ecd97)
1// RUN: %clang_cc1 -Wcstring-format-directive -verify -fsyntax-only %s
2
3typedef __builtin_va_list __darwin_va_list;
4typedef __builtin_va_list va_list;
5
6va_list argList;
7
8typedef const struct __CFString * CFStringRef;
9typedef struct __CFString * CFMutableStringRef;
10typedef const struct __CFAllocator * CFAllocatorRef;
11
12
13typedef const struct __CFDictionary * CFDictionaryRef;
14
15CFStringRef CFSTR ( const char *cStr );
16
17
18extern
19CFStringRef CStringCreateWithFormat(CFAllocatorRef alloc, CFDictionaryRef formatOptions, const char* format, ...) __attribute__((format(os_trace, 3, 4)));
20
21extern
22CFStringRef CStringCreateWithFormatAndArguments(CFAllocatorRef alloc, CFDictionaryRef formatOptions, const char* format, va_list arguments) __attribute__((format(os_trace, 3, 0)));
23
24extern
25void CStringAppendFormat(CFMutableStringRef theString, CFDictionaryRef formatOptions, const char* format, ...) __attribute__((format(os_trace, 3, 4)));
26
27extern
28void CStringAppendFormatAndArguments(CFMutableStringRef theString, CFDictionaryRef formatOptions, const char* format, va_list arguments) __attribute__((format(os_trace, 3, 0)));
29
30void 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
38extern void MyOSLog(const char* format, ...) __attribute__((format(os_trace, 1, 2)));
39extern void MyFStringCreateWithFormat(const char *format, ...) __attribute__((format(os_trace, 1, 2)));
40extern void XMyOSLog(int, const char* format, ...) __attribute__((format(os_trace, 2, 3)));
41extern void os_trace(const char *format, ...) __attribute__((format(os_trace, 1, 2)));
42
43void 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
54