1// RUN: %clang_cc1 -fsyntax-only -verify %s 2 3#include <stdarg.h> 4#include <stddef.h> 5#define __need_wint_t 6#include <stddef.h> // For wint_t and wchar_t 7 8int printf(const char *restrict, ...); 9 10@interface NSString 11@end 12 13void 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}} 24 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); 27 28 // <rdar://problem/23835805> 29 __builtin_os_log_format_buffer_size("no-args"); 30 __builtin_os_log_format(buf, "%s", "hi"); 31 32 // <rdar://problem/24828090> 33 wchar_t wc = 'a'; 34 __builtin_os_log_format(buf, "%C", wc); 35 printf("%C", wc); 36 wchar_t wcs[] = {'a', 0}; 37 __builtin_os_log_format(buf, "%S", wcs); 38 printf("%S", wcs); 39 40 struct { char data[0x100]; } toobig; 41 __builtin_os_log_format(buf, "%s", toobig); // expected-error {{os_log() argument 2 is too big (256 bytes, max 255)}} 42 43 __builtin_os_log_format(buf, "%{mask.xyz}s", "abc"); 44 __builtin_os_log_format(buf, "%{mask.}s", "abc"); // expected-error {{mask type size must be between 1-byte and 8-bytes}} 45 __builtin_os_log_format(buf, "%{mask.abcdefghi}s", "abc"); // expected-error {{mask type size must be between 1-byte and 8-bytes}} 46} 47 48// Test os_log_format primitive with ObjC string literal format argument. 49void test_objc(const char *pc, int i, void *p, void *buf, NSString *nss) { 50 __builtin_os_log_format(buf, @""); 51 __builtin_os_log_format(buf, @"%d"); // expected-warning {{more '%' conversions than data arguments}} 52 __builtin_os_log_format(buf, @"%d", i); 53 __builtin_os_log_format(buf, @"%P", p); // expected-warning {{using '%P' format specifier without precision}} 54 __builtin_os_log_format(buf, @"%.10P", p); 55 __builtin_os_log_format(buf, @"%.*P", p); // expected-warning {{field precision should have type 'int', but argument has type 'void *'}} 56 __builtin_os_log_format(buf, @"%.*P", i, p); 57 __builtin_os_log_format(buf, @"%.*P", i, i); // expected-warning {{format specifies type 'void *' but the argument has type 'int'}} 58 59 __builtin_os_log_format(buf, @"%{private}s", pc); 60 __builtin_os_log_format(buf, @"%@", nss); 61} 62 63// Test the os_log format attribute. 64void MyOSLog(const char *format, ...) __attribute__((format(os_log, 1, 2))); 65void test_attribute(void *p) { 66 MyOSLog("%s\n", "Hello"); 67 MyOSLog("%d"); // expected-warning {{more '%' conversions than data arguments}} 68 MyOSLog("%P", p); // expected-warning {{using '%P' format specifier without precision}} 69} 70