annotate clang/test/SemaObjC/format-strings-oslog.m @ 180:680fa57a2f20

fix compile errors.
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 30 May 2020 17:44:06 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 #include <stdarg.h>
anatofuz
parents:
diff changeset
4 #include <stddef.h>
anatofuz
parents:
diff changeset
5 #define __need_wint_t
anatofuz
parents:
diff changeset
6 #include <stddef.h> // For wint_t and wchar_t
anatofuz
parents:
diff changeset
7
anatofuz
parents:
diff changeset
8 int printf(const char *restrict, ...);
anatofuz
parents:
diff changeset
9
anatofuz
parents:
diff changeset
10 @interface NSString
anatofuz
parents:
diff changeset
11 @end
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 void test_os_log_format(const char *pc, int i, void *p, void *buf) {
anatofuz
parents:
diff changeset
14 __builtin_os_log_format(buf, "");
anatofuz
parents:
diff changeset
15 __builtin_os_log_format(buf, "%d"); // expected-warning {{more '%' conversions than data arguments}}
anatofuz
parents:
diff changeset
16 __builtin_os_log_format(buf, "%d", i);
anatofuz
parents:
diff changeset
17 __builtin_os_log_format(buf, "%P", p); // expected-warning {{using '%P' format specifier without precision}}
anatofuz
parents:
diff changeset
18 __builtin_os_log_format(buf, "%.10P", p);
anatofuz
parents:
diff changeset
19 __builtin_os_log_format(buf, "%.*P", p); // expected-warning {{field precision should have type 'int', but argument has type 'void *'}}
anatofuz
parents:
diff changeset
20 __builtin_os_log_format(buf, "%.*P", i, p);
anatofuz
parents:
diff changeset
21 __builtin_os_log_format(buf, "%.*P", i, i); // expected-warning {{format specifies type 'void *' but the argument has type 'int'}}
anatofuz
parents:
diff changeset
22 __builtin_os_log_format(buf, "%n"); // expected-error {{os_log() '%n' format specifier is not allowed}}
anatofuz
parents:
diff changeset
23 __builtin_os_log_format(buf, pc); // expected-error {{os_log() format argument is not a string constant}}
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 printf("%{private}s", pc); // expected-warning {{using 'private' format specifier annotation outside of os_log()/os_trace()}}
anatofuz
parents:
diff changeset
26 __builtin_os_log_format(buf, "%{private}s", pc);
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28 // <rdar://problem/23835805>
anatofuz
parents:
diff changeset
29 __builtin_os_log_format_buffer_size("no-args");
anatofuz
parents:
diff changeset
30 __builtin_os_log_format(buf, "%s", "hi");
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 // <rdar://problem/24828090>
anatofuz
parents:
diff changeset
33 wchar_t wc = 'a';
anatofuz
parents:
diff changeset
34 __builtin_os_log_format(buf, "%C", wc);
anatofuz
parents:
diff changeset
35 printf("%C", wc);
anatofuz
parents:
diff changeset
36 wchar_t wcs[] = {'a', 0};
anatofuz
parents:
diff changeset
37 __builtin_os_log_format(buf, "%S", wcs);
anatofuz
parents:
diff changeset
38 printf("%S", wcs);
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40 struct { char data[0x100]; } toobig;
anatofuz
parents:
diff changeset
41 __builtin_os_log_format(buf, "%s", toobig); // expected-error {{os_log() argument 2 is too big (256 bytes, max 255)}}
anatofuz
parents:
diff changeset
42
anatofuz
parents:
diff changeset
43 __builtin_os_log_format(buf, "%{mask.xyz}s", "abc");
anatofuz
parents:
diff changeset
44 __builtin_os_log_format(buf, "%{mask.}s", "abc"); // expected-error {{mask type size must be between 1-byte and 8-bytes}}
anatofuz
parents:
diff changeset
45 __builtin_os_log_format(buf, "%{mask.abcdefghi}s", "abc"); // expected-error {{mask type size must be between 1-byte and 8-bytes}}
anatofuz
parents:
diff changeset
46 }
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 // Test os_log_format primitive with ObjC string literal format argument.
anatofuz
parents:
diff changeset
49 void test_objc(const char *pc, int i, void *p, void *buf, NSString *nss) {
anatofuz
parents:
diff changeset
50 __builtin_os_log_format(buf, @"");
anatofuz
parents:
diff changeset
51 __builtin_os_log_format(buf, @"%d"); // expected-warning {{more '%' conversions than data arguments}}
anatofuz
parents:
diff changeset
52 __builtin_os_log_format(buf, @"%d", i);
anatofuz
parents:
diff changeset
53 __builtin_os_log_format(buf, @"%P", p); // expected-warning {{using '%P' format specifier without precision}}
anatofuz
parents:
diff changeset
54 __builtin_os_log_format(buf, @"%.10P", p);
anatofuz
parents:
diff changeset
55 __builtin_os_log_format(buf, @"%.*P", p); // expected-warning {{field precision should have type 'int', but argument has type 'void *'}}
anatofuz
parents:
diff changeset
56 __builtin_os_log_format(buf, @"%.*P", i, p);
anatofuz
parents:
diff changeset
57 __builtin_os_log_format(buf, @"%.*P", i, i); // expected-warning {{format specifies type 'void *' but the argument has type 'int'}}
anatofuz
parents:
diff changeset
58
anatofuz
parents:
diff changeset
59 __builtin_os_log_format(buf, @"%{private}s", pc);
anatofuz
parents:
diff changeset
60 __builtin_os_log_format(buf, @"%@", nss);
anatofuz
parents:
diff changeset
61 }
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 // Test the os_log format attribute.
anatofuz
parents:
diff changeset
64 void MyOSLog(const char *format, ...) __attribute__((format(os_log, 1, 2)));
anatofuz
parents:
diff changeset
65 void test_attribute(void *p) {
anatofuz
parents:
diff changeset
66 MyOSLog("%s\n", "Hello");
anatofuz
parents:
diff changeset
67 MyOSLog("%d"); // expected-warning {{more '%' conversions than data arguments}}
anatofuz
parents:
diff changeset
68 MyOSLog("%P", p); // expected-warning {{using '%P' format specifier without precision}}
anatofuz
parents:
diff changeset
69 }