brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.7 KiB · af5aef3 Raw
71 lines · plain
1// RUN: %clang_cc1 -fsyntax-only -verify %s2 3#include <stdarg.h>4#include <stddef.h>5#define __need_wint_t6#include <stddef.h> // For wint_t and wchar_t7 8int printf(const char *restrict, ...);9 10@interface NSString11@end12 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  __builtin_os_log_format_buffer_size("no-args");29  __builtin_os_log_format(buf, "%s", "hi");30 31  wchar_t wc = 'a';32  __builtin_os_log_format(buf, "%C", wc);33  printf("%C", wc);34  wchar_t wcs[] = {'a', 0};35  __builtin_os_log_format(buf, "%S", wcs);36  printf("%S", wcs);37 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)}}40 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}}44}45 46// Test os_log_format primitive with ObjC string literal format argument.47void test_objc(const char *pc, int i, void *p, void *buf, NSString *nss, id obj) {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 52  __builtin_os_log_format(buf, @"%P", p); // expected-warning {{using '%P' format specifier without precision}}53  __builtin_os_log_format(buf, @"%.10P", p);54  __builtin_os_log_format(buf, @"%.*P", p); // expected-warning {{field precision should have type 'int', but argument has type 'void *'}}55  __builtin_os_log_format(buf, @"%.*P", i, p);56  __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, @"%.8P", nss);    // expected-warning {{using '%P' format specifier with an Objective-C pointer results in dumping runtime object structure, not object value}}58  __builtin_os_log_format(buf, @"%.*P", i, obj); // expected-warning {{using '%P' format specifier with an Objective-C pointer results in dumping runtime object structure, not object value}}59 60  __builtin_os_log_format(buf, @"%{private}s", pc);61  __builtin_os_log_format(buf, @"%@", nss);62}63 64// Test the os_log format attribute.65void MyOSLog(const char *format, ...) __attribute__((format(os_log, 1, 2)));66void test_attribute(void *p) {67  MyOSLog("%s\n", "Hello");68  MyOSLog("%d");    // expected-warning {{more '%' conversions than data arguments}}69  MyOSLog("%P", p); // expected-warning {{using '%P' format specifier without precision}}70}71