1 // RUN: %clang_cc1 -fsyntax-only -verify %s
6 #include <stddef.h> // For wint_t and wchar_t
8 int printf(const char *restrict, ...);
13 void test_os_log_format(const char *pc, int i, void *p, void *buf) {
14 __builtin_os_log_format(buf, "");
15 __builtin_os_log_format(buf, "%d"); // expected-warning {{more '%' conversions than data arguments}}
16 __builtin_os_log_format(buf, "%d", i);
17 __builtin_os_log_format(buf, "%P", p); // expected-warning {{using '%P' format specifier without precision}}
18 __builtin_os_log_format(buf, "%.10P", p);
19 __builtin_os_log_format(buf, "%.*P", p); // expected-warning {{field precision should have type 'int', but argument has type 'void *'}}
20 __builtin_os_log_format(buf, "%.*P", i, p);
21 __builtin_os_log_format(buf, "%.*P", i, i); // expected-warning {{format specifies type 'void *' but the argument has type 'int'}}
22 __builtin_os_log_format(buf, "%n"); // expected-error {{os_log() '%n' format specifier is not allowed}}
23 __builtin_os_log_format(buf, pc); // expected-error {{os_log() format argument is not a string constant}}
25 printf("%{private}s", pc); // expected-warning {{using 'private' format specifier annotation outside of os_log()/os_trace()}}
26 __builtin_os_log_format(buf, "%{private}s", pc);
28 __builtin_os_log_format_buffer_size("no-args");
29 __builtin_os_log_format(buf, "%s", "hi");
32 __builtin_os_log_format(buf, "%C", wc);
34 wchar_t wcs[] = {'a', 0};
35 __builtin_os_log_format(buf, "%S", wcs);
38 struct { char data[0x100]; } toobig;
39 __builtin_os_log_format(buf, "%s", toobig); // expected-error {{os_log() argument 2 is too big (256 bytes, max 255)}}
41 __builtin_os_log_format(buf, "%{mask.xyz}s", "abc");
42 __builtin_os_log_format(buf, "%{mask.}s", "abc"); // expected-error {{mask type size must be between 1-byte and 8-bytes}}
43 __builtin_os_log_format(buf, "%{mask.abcdefghi}s", "abc"); // expected-error {{mask type size must be between 1-byte and 8-bytes}}
46 // Test os_log_format primitive with ObjC string literal format argument.
47 void test_objc(const char *pc, int i, void *p, void *buf, NSString *nss) {
48 __builtin_os_log_format(buf, @"");
49 __builtin_os_log_format(buf, @"%d"); // expected-warning {{more '%' conversions than data arguments}}
50 __builtin_os_log_format(buf, @"%d", i);
51 __builtin_os_log_format(buf, @"%P", p); // expected-warning {{using '%P' format specifier without precision}}
52 __builtin_os_log_format(buf, @"%.10P", p);
53 __builtin_os_log_format(buf, @"%.*P", p); // expected-warning {{field precision should have type 'int', but argument has type 'void *'}}
54 __builtin_os_log_format(buf, @"%.*P", i, p);
55 __builtin_os_log_format(buf, @"%.*P", i, i); // expected-warning {{format specifies type 'void *' but the argument has type 'int'}}
57 __builtin_os_log_format(buf, @"%{private}s", pc);
58 __builtin_os_log_format(buf, @"%@", nss);
61 // Test the os_log format attribute.
62 void MyOSLog(const char *format, ...) __attribute__((format(os_log, 1, 2)));
63 void test_attribute(void *p) {
64 MyOSLog("%s\n", "Hello");
65 MyOSLog("%d"); // expected-warning {{more '%' conversions than data arguments}}
66 MyOSLog("%P", p); // expected-warning {{using '%P' format specifier without precision}}