Lines Matching +full:docs +full:- +full:clang +full:- +full:man
1 // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs %s
2 // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -fno-signe…
3 // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -triple=x8…
4 // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -triple=x8…
13 int printf(const char *restrict, ...); // expected-note{{passing argument to parameter here}}
21 int vsprintf(char *restrict, const char *restrict, va_list); // expected-note{{passing argument to …
33 printf(s); // expected-warning {{format string is not a string literal}} in check_string_literal()
34 // expected-note@-1{{treat the string as an argument to avoid this}} in check_string_literal()
35 vprintf(s,ap); // expected-warning {{format string is not a string literal}} in check_string_literal()
36 fprintf(fp,s); // expected-warning {{format string is not a string literal}} in check_string_literal()
37 // expected-note@-1{{treat the string as an argument to avoid this}} in check_string_literal()
38 vfprintf(fp,s,ap); // expected-warning {{format string is not a string literal}} in check_string_literal()
39 asprintf(&b,s); // expected-warning {{format string is not a string lit}} in check_string_literal()
40 // expected-note@-1{{treat the string as an argument to avoid this}} in check_string_literal()
41 vasprintf(&b,s,ap); // expected-warning {{format string is not a string literal}} in check_string_literal()
42 sprintf(buf,s); // expected-warning {{format string is not a string literal}} in check_string_literal()
43 // expected-note@-1{{treat the string as an argument to avoid this}} in check_string_literal()
44 snprintf(buf,2,s); // expected-warning {{format string is not a string lit}} in check_string_literal()
45 // expected-note@-1{{treat the string as an argument to avoid this}} in check_string_literal()
46 __builtin___sprintf_chk(buf,0,-1,s); // expected-warning {{format string is not a string literal}} in check_string_literal()
47 // expected-note@-1{{treat the string as an argument to avoid this}} in check_string_literal()
48 __builtin___snprintf_chk(buf,2,0,-1,s); // expected-warning {{format string is not a string lit}} in check_string_literal()
49 // expected-note@-1{{treat the string as an argument to avoid this}} in check_string_literal()
50 vsprintf(buf,s,ap); // expected-warning {{format string is not a string lit}} in check_string_literal()
51 vsnprintf(buf,2,s,ap); // expected-warning {{format string is not a string lit}} in check_string_literal()
52 vsnprintf(buf,2,global_fmt,ap); // expected-warning {{format string is not a string literal}} in check_string_literal()
53 …__builtin___vsnprintf_chk(buf,2,0,-1,s,ap); // expected-warning {{format string is not a string li… in check_string_literal()
54 …__builtin___vsnprintf_chk(buf,2,0,-1,global_fmt,ap); // expected-warning {{format string is not a … in check_string_literal()
56 vscanf(s, ap); // expected-warning {{format string is not a string literal}} in check_string_literal()
58 const char *const fmt = "%d"; // FIXME -- defined here in check_string_literal()
59 printf(fmt, 1, 2); // expected-warning{{data argument not used}} in check_string_literal()
62 "%*d", 1, 1); // no-warning in check_string_literal()
65 "%*d", 1, 1); // no-warning in check_string_literal()
70 printf("%*d", (unsigned) 1, 1); // no-warning in check_string_literal()
73 // When calling a non-variadic format function (vprintf, vscanf, NSLogv, ...),
82 printf(s); // expected-warning {{format string is not a string literal}} in check_string_literal2()
83 // expected-note@-1{{treat the string as an argument to avoid this}} in check_string_literal2()
84 vprintf(s,ap); // no-warning in check_string_literal2()
85 fprintf(fp,s); // expected-warning {{format string is not a string literal}} in check_string_literal2()
86 // expected-note@-1{{treat the string as an argument to avoid this}} in check_string_literal2()
87 vfprintf(fp,s,ap); // no-warning in check_string_literal2()
88 asprintf(&b,s); // expected-warning {{format string is not a string lit}} in check_string_literal2()
89 // expected-note@-1{{treat the string as an argument to avoid this}} in check_string_literal2()
90 vasprintf(&b,s,ap); // no-warning in check_string_literal2()
91 sprintf(buf,s); // expected-warning {{format string is not a string literal}} in check_string_literal2()
92 // expected-note@-1{{treat the string as an argument to avoid this}} in check_string_literal2()
93 snprintf(buf,2,s); // expected-warning {{format string is not a string lit}} in check_string_literal2()
94 // expected-note@-1{{treat the string as an argument to avoid this}} in check_string_literal2()
95 __builtin___vsnprintf_chk(buf,2,0,-1,s,ap); // no-warning in check_string_literal2()
97 vscanf(s, ap); // expected-warning {{format string is not a string literal}} in check_string_literal2()
101 printf(i == 1 ? "yes" : "no"); // no-warning in check_conditional_literal()
102 printf(i == 0 ? (i == 1 ? "yes" : "no") : "dont know"); // no-warning in check_conditional_literal()
103 …printf(i == 0 ? (i == 1 ? s : "no") : "dont know"); // expected-warning{{format string is not a st… in check_conditional_literal()
104 // expected-note@-1{{treat the string as an argument to avoid this}} in check_conditional_literal()
105 printf("yes" ?: "no %d", 1); // expected-warning{{data argument not used by format string}} in check_conditional_literal()
106 printf(0 ? "yes %s" : "no %d", 1); // no-warning in check_conditional_literal()
107 printf(0 ? "yes %d" : "no %s", 1); // expected-warning{{format specifies type 'char *'}} in check_conditional_literal()
109 printf(0 ? "yes" : "no %d", 1); // no-warning in check_conditional_literal()
110 printf(0 ? "yes %d" : "no", 1); // expected-warning{{data argument not used by format string}} in check_conditional_literal()
111 printf(1 ? "yes" : "no %d", 1); // expected-warning{{data argument not used by format string}} in check_conditional_literal()
112 printf(1 ? "yes %d" : "no", 1); // no-warning in check_conditional_literal()
113 printf(i ? "yes" : "no %d", 1); // no-warning in check_conditional_literal()
114 printf(i ? "yes %s" : "no %d", 1); // expected-warning{{format specifies type 'char *'}} in check_conditional_literal()
115 printf(i ? "yes" : "no %d", 1, 2); // expected-warning{{data argument not used by format string}} in check_conditional_literal()
117 printf(i ? "%*s" : "-", i, s); // no-warning in check_conditional_literal()
118 …printf(i ? "yes" : 0 ? "no %*d" : "dont know %d", 1, 2); // expected-warning{{data argument not us… in check_conditional_literal()
119 …printf(i ? "%i\n" : "%i %s %s\n", i, s); // expected-warning{{more '%' conversions than data argum… in check_conditional_literal()
128 …printf("%n", b); // expected-warning{{format specifies type 'int *' but the argument has type 'cha… in check_writeback_specifier()
129 printf("%n", &x); // no-warning in check_writeback_specifier()
131 printf("%hhn", (signed char*)0); // no-warning in check_writeback_specifier()
132 printf("%hhn", (char*)0); // no-warning in check_writeback_specifier()
133 printf("%hhn", (unsigned char*)0); // no-warning in check_writeback_specifier()
134 …printf("%hhn", (int*)0); // expected-warning{{format specifies type 'signed char *' but the argume… in check_writeback_specifier()
136 printf("%hn", (short*)0); // no-warning in check_writeback_specifier()
137 printf("%hn", (unsigned short*)0); // no-warning in check_writeback_specifier()
138 …printf("%hn", (int*)0); // expected-warning{{format specifies type 'short *' but the argument has … in check_writeback_specifier()
140 printf("%n", (int*)0); // no-warning in check_writeback_specifier()
141 printf("%n", (unsigned int*)0); // no-warning in check_writeback_specifier()
142 …printf("%n", (char*)0); // expected-warning{{format specifies type 'int *' but the argument has ty… in check_writeback_specifier()
144 printf("%ln", (long*)0); // no-warning in check_writeback_specifier()
145 printf("%ln", (unsigned long*)0); // no-warning in check_writeback_specifier()
146 …printf("%ln", (int*)0); // expected-warning{{format specifies type 'long *' but the argument has t… in check_writeback_specifier()
148 printf("%lln", (long long*)0); // no-warning in check_writeback_specifier()
149 printf("%lln", (unsigned long long*)0); // no-warning in check_writeback_specifier()
150 …printf("%lln", (int*)0); // expected-warning{{format specifies type 'long long *' but the argument… in check_writeback_specifier()
152 printf("%qn", (long long*)0); // no-warning in check_writeback_specifier()
153 printf("%qn", (unsigned long long*)0); // no-warning in check_writeback_specifier()
154 …printf("%qn", (int*)0); // expected-warning{{format specifies type 'long long *' but the argument … in check_writeback_specifier()
156 …printf("%Ln", 0); // expected-warning{{length modifier 'L' results in undefined behavior or no eff… in check_writeback_specifier()
157 // expected-note@-1{{did you mean to use 'll'?}} in check_writeback_specifier()
165 printf("%n", &x); // expected-warning{{'%n' specifier not supported on this platform}} in check_writeback_specifier()
167 …printf("%hhn", (signed char*)0); // expected-warning{{'%n' specifier not supported on this platfor… in check_writeback_specifier()
168 printf("%hhn", (char*)0); // expected-warning{{'%n' specifier not supported on this platform}} in check_writeback_specifier()
169 …printf("%hhn", (unsigned char*)0); // expected-warning{{'%n' specifier not supported on this platf… in check_writeback_specifier()
170 …printf("%hhn", (int*)0); // expected-warning{{format specifies type 'signed char *' but the argume… in check_writeback_specifier()
171 // expected-warning@-1 {{'%n' specifier not supported on this platform}} in check_writeback_specifier()
173 printf("%hn", (short*)0); // expected-warning{{'%n' specifier not supported on this platform}} in check_writeback_specifier()
174 …printf("%hn", (unsigned short*)0); // expected-warning{{'%n' specifier not supported on this platf… in check_writeback_specifier()
175 …printf("%hn", (int*)0); // expected-warning{{format specifies type 'short *' but the argument has … in check_writeback_specifier()
176 // expected-warning@-1 {{'%n' specifier not supported on this platform}} in check_writeback_specifier()
178 printf("%n", (int*)0); // expected-warning{{'%n' specifier not supported on this platform}} in check_writeback_specifier()
179 …printf("%n", (unsigned int*)0); // expected-warning{{'%n' specifier not supported on this platform… in check_writeback_specifier()
180 …printf("%n", (char*)0); // expected-warning{{format specifies type 'int *' but the argument has ty… in check_writeback_specifier()
181 // expected-warning@-1 {{'%n' specifier not supported on this platform}} in check_writeback_specifier()
183 printf("%ln", (long*)0); // expected-warning{{'%n' specifier not supported on this platform}} in check_writeback_specifier()
184 …printf("%ln", (unsigned long*)0); // expected-warning{{'%n' specifier not supported on this platfo… in check_writeback_specifier()
185 …printf("%ln", (int*)0); // expected-warning{{format specifies type 'long *' but the argument has t… in check_writeback_specifier()
186 // expected-warning@-1 {{'%n' specifier not supported on this platform}} in check_writeback_specifier()
188 …printf("%lln", (long long*)0); // expected-warning{{'%n' specifier not supported on this platform}} in check_writeback_specifier()
189 …printf("%lln", (unsigned long long*)0); // expected-warning{{'%n' specifier not supported on this … in check_writeback_specifier()
190 …printf("%lln", (int*)0); // expected-warning{{format specifies type 'long long *' but the argument… in check_writeback_specifier()
191 // expected-warning@-1 {{'%n' specifier not supported on this platform}} in check_writeback_specifier()
193 printf("%qn", (long long*)0); // expected-warning{{'%n' specifier not supported on this platform}} in check_writeback_specifier()
194 …printf("%qn", (unsigned long long*)0); // expected-warning{{'%n' specifier not supported on this p… in check_writeback_specifier()
201 …printf("%s%lv%d","unix",10,20); // expected-warning {{invalid conversion specifier 'v'}} expected-… in check_invalid_specifier()
202 fprintf(fp,"%%%l"); // expected-warning {{incomplete format specifier}} in check_invalid_specifier()
203 …sprintf(buf,"%%%%%ld%d%d", 1, 2, 3); // expected-warning{{format specifies type 'long' but the arg… in check_invalid_specifier()
204 …expected-warning{{format specifies type 'long' but the argument has type 'int'}} expected-warning … in check_invalid_specifier()
205 …// expected-warning{{'snprintf' will always be truncated; specified size is 2, but format string e… in check_invalid_specifier()
210 printf("\0this is bogus%d",1); // expected-warning {{string contains '\0'}} in check_null_char_string()
211 snprintf(b,10,"%%%%%d\0%d",1,2); // expected-warning {{string contains '\0'}} in check_null_char_string()
212 printf("%\0d",1); // expected-warning {{string contains '\0'}} in check_null_char_string()
219 vprintf("",ap); // expected-warning {{format string is empty}} in check_empty_format_string()
220 sprintf(buf, "", 1); // expected-warning {{format string is empty}} in check_empty_format_string()
223 // This can arise from macro expansions and non-standard format string in check_empty_format_string()
225 sprintf(buf, ""); // no-warning in check_empty_format_string()
233 …printf(L"foo %d",2); // expected-warning {{incompatible pointer types}}, expected-warning {{should… in check_wide_string()
234 …vsprintf(b,L"bar %d",ap); // expected-warning {{incompatible pointer types}}, expected-warning {{s… in check_wide_string()
238 …printf("%*d"); // expected-warning {{'*' specified field width is missing a matching 'int' argumen… in check_asterisk_precision_width()
239 …printf("%.*d"); // expected-warning {{'.*' specified field precision is missing a matching 'int' a… in check_asterisk_precision_width()
240 printf("%*d",12,x); // no-warning in check_asterisk_precision_width()
241 …printf("%*d","foo",x); // expected-warning {{field width should have type 'int', but argument has … in check_asterisk_precision_width()
242 …printf("%.*d","foo",x); // expected-warning {{field precision should have type 'int', but argument… in check_asterisk_precision_width()
258 printf(s1); // no-warning in test_constant_bindings()
259 printf(s2); // no-warning in test_constant_bindings()
260 printf(s3); // expected-warning{{not a string literal}} in test_constant_bindings()
261 // expected-note@-1{{treat the string as an argument to avoid this}} in test_constant_bindings()
262 printf(s4); // expected-warning{{not a string literal}} in test_constant_bindings()
263 // expected-note@-1{{treat the string as an argument to avoid this}} in test_constant_bindings()
264 printf(s5); // expected-warning{{not a string literal}} in test_constant_bindings()
265 // expected-note@-1{{treat the string as an argument to avoid this}} in test_constant_bindings()
269 // Test what happens when -Wformat-security only.
270 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
271 #pragma GCC diagnostic warning "-Wformat-security"
275 printf(P); // expected-warning {{format string is not a string literal (potentially insecure)}} in test9()
276 // expected-note@-1{{treat the string as an argument to avoid this}} in test9()
281 vprintf ("%*.*d", v8); // no-warning in torture()
286 printf("%s"); // expected-warning{{more '%' conversions than data arguments}} in test10()
287 printf("%@", 12); // expected-warning{{invalid conversion specifier '@'}} in test10()
288 printf("\0"); // expected-warning{{format string contains '\0' within the string body}} in test10()
289 printf("xs\0"); // expected-warning{{format string contains '\0' within the string body}} in test10()
290 …printf("%*d\n"); // expected-warning{{'*' specified field width is missing a matching 'int' argume… in test10()
291 …printf("%*.*d\n", x); // expected-warning{{'.*' specified field precision is missing a matching 'i… in test10()
292 …printf("%*d\n", f, x); // expected-warning{{field width should have type 'int', but argument has t… in test10()
293 …printf("%*.*d\n", x, f, x); // expected-warning{{field precision should have type 'int', but argum… in test10()
294 printf("%**\n"); // expected-warning{{invalid conversion specifier '*'}} in test10()
295 printf("%d%d\n", x); // expected-warning{{more '%' conversions than data arguments}} in test10()
296 printf("%d\n", x, x); // expected-warning{{data argument not used by format string}} in test10()
297 …printf("%W%d\n", x, x); // expected-warning{{invalid conversion specifier 'W'}} expected-warning … in test10()
298 printf("%"); // expected-warning{{incomplete format specifier}} in test10()
299 printf("%.d", x); // no-warning in test10()
300 printf("%.", x); // expected-warning{{incomplete format specifier}} in test10()
301 …printf("%f", 4); // expected-warning{{format specifies type 'double' but the argument has type 'in… in test10()
302 printf("%qd", lli); // no-warning in test10()
303 …printf("%qd", x); // expected-warning{{format specifies type 'long long' but the argument has type… in test10()
304 …printf("%qp", (void *)0); // expected-warning{{length modifier 'q' results in undefined behavior o… in test10()
305 printf("hhX %hhX", (unsigned char)10); // no-warning in test10()
306 printf("llX %llX", (long long) 10); // no-warning in test10()
307 printf("%lb %lB", (long) 10, (long) 10); // no-warning in test10()
308 printf("%llb %llB", (long long) 10, (long long) 10); // no-warning in test10()
310 printf("%d", (unsigned char) 10); // no-warning in test10()
311 …printf("%d", (long long) 10); // expected-warning{{format specifies type 'int' but the argument ha… in test10()
312 printf("%Lf\n", (long double) 1.0); // no-warning in test10()
313 …printf("%f\n", (long double) 1.0); // expected-warning{{format specifies type 'double' but the arg… in test10()
314 // The man page says that a zero precision is okay. in test10()
315 printf("%.0Lf", (long double) 1.0); // no-warning in test10()
316 …printf("%c\n", "x"); // expected-warning{{format specifies type 'int' but the argument has type 'c… in test10()
317 …printf("%c\n", 1.23); // expected-warning{{format specifies type 'int' but the argument has type '… in test10()
318 printf("Format %d, is %! %f", 1, 4.4); // expected-warning{{invalid conversion specifier '!'}} in test10()
324 …printf("%hhu", (short) 10); // expected-warning{{format specifies type 'unsigned char' but the arg… in should_understand_small_integers()
325 printf("%hu\n", (unsigned char)1); // warning with -Wformat-pedantic only in should_understand_small_integers()
326 printf("%hu\n", (uint8_t)1); // warning with -Wformat-pedantic only in should_understand_small_integers()
330 printf("%p", p); // no-warning in test11()
331 …printf("%p", 123); // expected-warning{{format specifies type 'void *' but the argument has type '… in test11()
332 …printf("%.4p", p); // expected-warning{{precision used with 'p' conversion specifier, resulting in… in test11()
333 …printf("%+p", p); // expected-warning{{flag '+' results in undefined behavior with 'p' conversion … in test11()
334 …printf("% p", p); // expected-warning{{flag ' ' results in undefined behavior with 'p' conversion … in test11()
335 …printf("%0p", p); // expected-warning{{flag '0' results in undefined behavior with 'p' conversion … in test11()
336 printf("%s", s); // no-warning in test11()
337 …printf("%+s", p); // expected-warning{{flag '+' results in undefined behavior with 's' conversion … in test11()
338 … // expected-warning@-1 {{format specifies type 'char *' but the argument has type 'void *'}} in test11()
339 …printf("% s", p); // expected-warning{{flag ' ' results in undefined behavior with 's' conversion … in test11()
340 … // expected-warning@-1 {{format specifies type 'char *' but the argument has type 'void *'}} in test11()
341 …printf("%0s", p); // expected-warning{{flag '0' results in undefined behavior with 's' conversion … in test11()
342 … // expected-warning@-1 {{format specifies type 'char *' but the argument has type 'void *'}} in test11()
347 printf ("%.4s\n", buf); // no-warning in test12()
348 …printf ("%.4s\n", &buf); // expected-warning{{format specifies type 'char *' but the argument has … in test12()
351 …asprintf(&b, "%d", "asprintf"); // expected-warning{{format specifies type 'int' but the argument … in test12()
356 printf("bel: '0%hhd'\n", bel); // no-warning in test13()
357 …printf("x: '0%hhd'\n", x); // expected-warning {{format specifies type 'char' but the argument has… in test13()
364 asl_log(asl, 0, 3, "Error: %m"); // no-warning in test_asl()
365 asl_log(asl, 0, 3, "Error: %W"); // expected-warning{{invalid conversion specifier 'W'}} in test_asl()
375 printf("%S", s); // no-warning in test_unicode_conversions()
376 …printf("%s", s); // expected-warning{{format specifies type 'char *' but the argument has type 'wc… in test_unicode_conversions()
377 printf("%C", s[0]); // no-warning in test_unicode_conversions()
379 …printf("%c", s[0]); // expected-warning{{format specifies type 'int' but the argument has type 'wc… in test_unicode_conversions()
386 printf("%S", "hello"); // expected-warning{{but the argument has type 'char *'}} in test_unicode_conversions()
393 …printf("%0$", (int)2); // expected-warning{{position arguments in format strings start counting at… in test_positional_arguments()
394 …printf("%1$*0$d", (int) 2); // expected-warning{{position arguments in format strings start counti… in test_positional_arguments()
395 printf("%1$d", (int) 2); // no-warning in test_positional_arguments()
396 printf("%1$d", (int) 2, 2); // expected-warning{{data argument not used by format string}} in test_positional_arguments()
397 …printf("%1$d%1$f", (int) 2); // expected-warning{{format specifies type 'double' but the argument … in test_positional_arguments()
398 printf("%1$2.2d", (int) 2); // no-warning in test_positional_arguments()
399 printf("%2$*1$.2d", (int) 2, (int) 3); // no-warning in test_positional_arguments()
400 …printf("%2$*8$d", (int) 2, (int) 3); // expected-warning{{specified field width is missing a match… in test_positional_arguments()
401 printf("%%%1$d", (int) 2); // no-warning in test_positional_arguments()
402 printf("%1$d%%", (int) 2); // no-warning in test_positional_arguments()
405 // PR 6697 - Handle format strings where the data argument is not adjacent to the format string
408 myprintf_PR_6697("%s\n", 1, "foo"); // no-warning in test_pr_6697()
409 …myprintf_PR_6697("%s\n", 1, (int)0); // expected-warning{{format specifies type 'char *' but the a… in test_pr_6697()
412 myprintf_PR_6697("%1$s\n", 1, "foo"); // no-warning in test_pr_6697()
413 …myprintf_PR_6697("%2$s\n", 1, "foo"); // expected-warning{{data argument position '2' exceeds the … in test_pr_6697()
414 …myprintf_PR_6697("%18$s\n", 1, "foo"); // expected-warning{{data argument position '18' exceeds th… in test_pr_6697()
415 …myprintf_PR_6697("%1$s\n", 1, (int) 0); // expected-warning{{format specifies type 'char *' but th… in test_pr_6697()
419 fprintf(fp, "\%"); // expected-warning{{incomplete format specifier}} in rdar8026030()
424 …printf("%hhs", "foo"); // expected-warning{{length modifier 'hh' results in undefined behavior or … in bug7377_bad_length_mod_usage()
425 …printf("%1$zp", (void *)0); // expected-warning{{length modifier 'z' results in undefined behavior… in bug7377_bad_length_mod_usage()
426 printf("%ls", L"foo"); // no-warning in bug7377_bad_length_mod_usage()
427 printf("%#.2Lf", (long double)1.234); // no-warning in bug7377_bad_length_mod_usage()
430 …printf("%#p", (void *) 0); // expected-warning{{flag '#' results in undefined behavior with 'p' co… in bug7377_bad_length_mod_usage()
431 printf("%0d", -1); // no-warning in bug7377_bad_length_mod_usage()
432 printf("%0b%0B", -1u, -1u); // no-warning in bug7377_bad_length_mod_usage()
433 printf("%-p", (void *) 0); // no-warning in bug7377_bad_length_mod_usage()
435 …printf("%#n", (int *) 0); // expected-warning{{flag '#' results in undefined behavior with 'n' con… in bug7377_bad_length_mod_usage()
436 …printf("%-n", (int *) 0); // expected-warning{{flag '-' results in undefined behavior with 'n' con… in bug7377_bad_length_mod_usage()
438 …printf("%#n", (int *) 0); // expected-warning{{flag '#' results in undefined behavior with 'n' con… in bug7377_bad_length_mod_usage()
439 // expected-warning@-1 {{'%n' specifier not supported on this platform}} in bug7377_bad_length_mod_usage()
440 …printf("%-n", (int *) 0); // expected-warning{{flag '-' results in undefined behavior with 'n' con… in bug7377_bad_length_mod_usage()
441 // expected-warning@-1 {{'%n' specifier not supported on this platform}} in bug7377_bad_length_mod_usage()
445 …printf("%.2c", 'a'); // expected-warning{{precision used with 'c' conversion specifier, resulting … in bug7377_bad_length_mod_usage()
447 …printf("%1n", (int *) 0); // expected-warning{{field width used with 'n' conversion specifier, res… in bug7377_bad_length_mod_usage()
448 …printf("%.9n", (int *) 0); // expected-warning{{precision used with 'n' conversion specifier, resu… in bug7377_bad_length_mod_usage()
450 …printf("%1n", (int *) 0); // expected-warning{{field width used with 'n' conversion specifier, res… in bug7377_bad_length_mod_usage()
451 // expected-warning@-1 {{'%n' specifier not supported on this platform}} in bug7377_bad_length_mod_usage()
452 …printf("%.9n", (int *) 0); // expected-warning{{precision used with 'n' conversion specifier, resu… in bug7377_bad_length_mod_usage()
453 // expected-warning@-1 {{'%n' specifier not supported on this platform}} in bug7377_bad_length_mod_usage()
457 printf("% +f", 1.23); // expected-warning{{flag ' ' is ignored when flag '+' is present}} in bug7377_bad_length_mod_usage()
458 printf("%+ f", 1.23); // expected-warning{{flag ' ' is ignored when flag '+' is present}} in bug7377_bad_length_mod_usage()
459 printf("%0-f", 1.23); // expected-warning{{flag '0' is ignored when flag '-' is present}} in bug7377_bad_length_mod_usage()
460 printf("%-0f", 1.23); // expected-warning{{flag '0' is ignored when flag '-' is present}} in bug7377_bad_length_mod_usage()
461 printf("%-+f", 1.23); // no-warning in bug7377_bad_length_mod_usage()
464 // PR 7981 - handle '%lc' (wint_t)
467 printf("%lc", c); // no-warning in pr7981()
468 printf("%lc", 1.0); // expected-warning{{the argument has type 'double'}} in pr7981()
470 printf("%lc", (char) 1); // no-warning in pr7981()
472 printf("%lc", (char) 1); // expected-warning{{the argument has type 'char'}} in pr7981()
474 printf("%lc", &c); // expected-warning{{the argument has type 'wint_t *'}} in pr7981()
479 printf("%lc", c2); // no-warning in pr7981()
483 // -Wformat-security says NULL is not a string literal
485 // This is likely to crash in most cases, but -Wformat-nonliteral technically in rdar8269537()
487 printf(0); // no-warning in rdar8269537()
496 rdar8332221_vprintf_scanf("%", ap, "%d", x); // expected-warning{{incomplete format specifier}} in rdar8332221()
508 printf("%'d\n", 123456789); // no-warning in posix_extensions()
509 printf("%'i\n", 123456789); // no-warning in posix_extensions()
510 printf("%'f\n", (float) 1.0); // no-warning in posix_extensions()
511 …printf("%'p\n", (void*) 0); // expected-warning{{results in undefined behavior with 'p' conversion… in posix_extensions()
512 …printf("%'b\n", 123456789); // expected-warning{{results in undefined behavior with 'b' conversion… in posix_extensions()
513 …printf("%'B\n", 123456789); // expected-warning{{results in undefined behavior with 'B' conversion… in posix_extensions()
518 // Test what happens when -Wformat is on, but -Wformat-security is off.
519 #pragma GCC diagnostic warning "-Wformat"
520 #pragma GCC diagnostic ignored "-Wformat-security"
523 …printf("%s", 1); // expected-warning{{format specifies type 'char *' but the argument has type 'in… in pr8486()
529 printf(__PRETTY_FUNCTION__); // no-warning in pr9314()
530 printf(__func__); // no-warning in pr9314()
536 …printf("%s", 2); // expected-warning{{format specifies type 'char *' but the argument has type 'in… in rdar9612060()
540 printf("%c", y); // no-warning in check_char()
541 printf("%hhu", x); // no-warning in check_char()
542 printf("%hhi", y); // no-warning in check_char()
543 printf("%hhi", x); // no-warning in check_char()
544 printf("%c", x); // no-warning in check_char()
545 printf("%hhu", y); // no-warning in check_char()
546 printf("%hhb %hhB", x, x); // no-warning in check_char()
552 #pragma clang diagnostic push in test_suppress_invalid_specifier()
553 #pragma clang diagnostic ignored "-Wformat-invalid-specifier" in test_suppress_invalid_specifier()
554 printf("%@", 12); // no-warning in test_suppress_invalid_specifier()
555 #pragma clang diagnostic pop in test_suppress_invalid_specifier()
559 #pragma GCC diagnostic warning "-Wformat"
560 #pragma GCC diagnostic warning "-Wformat-security"
565 const char kFormat1[] = "%d %d \n"; // expected-note{{format string is defined here}}} in pr9751()
566 printf(kFormat1, 0); // expected-warning{{more '%' conversions than data arguments}} in pr9751()
567 printf("%d %s\n", 0); // expected-warning{{more '%' conversions than data arguments}} in pr9751()
569 const char kFormat2[] = "%18$s\n"; // expected-note{{format string is defined here}} in pr9751()
570 …printf(kFormat2, 1, "foo"); // expected-warning{{data argument position '18' exceeds the number of… in pr9751()
571 …printf("%18$s\n", 1, "foo"); // expected-warning{{data argument position '18' exceeds the number o… in pr9751()
573 const char kFormat4[] = "%y"; // expected-note{{format string is defined here}} in pr9751()
574 printf(kFormat4, 5); // expected-warning{{invalid conversion specifier 'y'}} in pr9751()
575 printf("%y", 5); // expected-warning{{invalid conversion specifier 'y'}} in pr9751()
577 const char kFormat5[] = "%."; // expected-note{{format string is defined here}} in pr9751()
578 printf(kFormat5, 5); // expected-warning{{incomplete format specifier}} in pr9751()
579 printf("%.", 5); // expected-warning{{incomplete format specifier}} in pr9751()
581 const char kFormat6[] = "%s"; // expected-note{{format string is defined here}} in pr9751()
582 …printf(kFormat6, 5); // expected-warning{{format specifies type 'char *' but the argument has type… in pr9751()
583 …printf("%s", 5); // expected-warning{{format specifies type 'char *' but the argument has type 'in… in pr9751()
585 const char kFormat7[] = "%0$"; // expected-note{{format string is defined here}} in pr9751()
586 …printf(kFormat7, 5); // expected-warning{{position arguments in format strings start counting at 1… in pr9751()
587 …printf("%0$", 5); // expected-warning{{position arguments in format strings start counting at 1 (n… in pr9751()
589 const char kFormat8[] = "%1$d %d"; // expected-note{{format string is defined here}} in pr9751()
590 …printf(kFormat8, 4, 4); // expected-warning{{cannot mix positional and non-positional arguments in… in pr9751()
591 …printf("%1$d %d", 4, 4); // expected-warning{{cannot mix positional and non-positional arguments i… in pr9751()
593 const char kFormat9[] = ""; // expected-note{{format string is defined here}} in pr9751()
594 printf(kFormat9, 4, 4); // expected-warning{{format string is empty}} in pr9751()
595 printf("", 4, 4); // expected-warning{{format string is empty}} in pr9751()
597 const char kFormat10[] = "\0%d"; // expected-note{{format string is defined here}} in pr9751()
598 printf(kFormat10, 4); // expected-warning{{format string contains '\0' within the string body}} in pr9751()
599 printf("\0%d", 4); // expected-warning{{format string contains '\0' within the string body}} in pr9751()
601 const char kFormat11[] = "%*d"; // expected-note{{format string is defined here}} in pr9751()
602 …printf(kFormat11); // expected-warning{{'*' specified field width is missing a matching 'int' argu… in pr9751()
603 …printf("%*d"); // expected-warning{{'*' specified field width is missing a matching 'int' argument… in pr9751()
605 const char kFormat12[] = "%*d"; // expected-note{{format string is defined here}} in pr9751()
606 …printf(kFormat12, 4.4); // expected-warning{{field width should have type 'int', but argument has … in pr9751()
607 …printf("%*d", 4.4); // expected-warning{{field width should have type 'int', but argument has type… in pr9751()
609 const char kFormat13[] = "%.3p"; // expected-note{{format string is defined here}} in pr9751()
611 …printf(kFormat13, p); // expected-warning{{precision used with 'p' conversion specifier, resulting… in pr9751()
612 …printf("%.3p", p); // expected-warning{{precision used with 'p' conversion specifier, resulting in… in pr9751()
614 const char kFormat14[] = "%0s"; // expected-note{{format string is defined here}} in pr9751()
615 …printf(kFormat14, "a"); // expected-warning{{flag '0' results in undefined behavior with 's' conve… in pr9751()
616 …printf("%0s", "a"); // expected-warning{{flag '0' results in undefined behavior with 's' conversio… in pr9751()
618 const char kFormat15[] = "%hhs"; // expected-note{{format string is defined here}} in pr9751()
619 …printf(kFormat15, "a"); // expected-warning{{length modifier 'hh' results in undefined behavior or… in pr9751()
620 …printf("%hhs", "a"); // expected-warning{{length modifier 'hh' results in undefined behavior or no… in pr9751()
622 const char kFormat16[] = "%-0d"; // expected-note{{format string is defined here}} in pr9751()
623 printf(kFormat16, 5); // expected-warning{{flag '0' is ignored when flag '-' is present}} in pr9751()
624 printf("%-0d", 5); // expected-warning{{flag '0' is ignored when flag '-' is present}} in pr9751()
628 printf(1 ? "yes %d" : "no %d"); // expected-warning{{more '%' conversions than data arguments}} in pr9751()
630 const char kFormat17[] = "%hu"; // expected-note{{format string is defined here}}} in pr9751()
631 …printf(kFormat17, (int[]){0}); // expected-warning{{format specifies type 'unsigned short' but the… in pr9751()
633 …printf("%a", (long double)0); // expected-warning{{format specifies type 'double' but the argument… in pr9751()
636 const char kFormat18[] = { "%lld" }; // expected-note{{format string is defined here}} in pr9751()
637 printf(kFormat18, 0); // expected-warning{{format specifies type}} in pr9751()
640 const char kFormat19[] = "%d"; // expected-note{{format string is defined here}} in pr9751()
642 0.0); // expected-warning{{format specifies}} in pr9751()
646 const char s1[] = "s\0%s"; // expected-note{{format string is defined here}} in pr18905()
647 const char s2[1] = "s"; // expected-note{{format string is defined here}} in pr18905()
648 const char s3[2] = "s\0%s"; // expected-warning{{initializer-string for char array is too long}} in pr18905()
650 const char s5[0] = "%s"; // expected-warning{{initializer-string for char array is too long}} in pr18905()
651 // expected-note@-1{{format string is defined here}} in pr18905()
653 printf(s1); // expected-warning{{format string contains '\0' within the string body}} in pr18905()
654 printf(s2); // expected-warning{{format string is not null-terminated}} in pr18905()
655 printf(s3); // no-warning in pr18905()
656 printf(s4); // no-warning in pr18905()
657 printf(s5); // expected-warning{{format string is not null-terminated}} in pr18905()
666 monformat("", 1); // expected-warning{{format string is empty}} in test_other_formats()
667 …monformat(str); // expected-warning{{format string is not a string literal (potentially insecure)}} in test_other_formats()
668 dateformat(""); // expected-warning{{format string is empty}} in test_other_formats()
669 dateformat(str); // no-warning (using strftime non-literal is not unsafe) in test_other_formats()
673 #include <format-unused-system-args.h>
675 PRINT1("%d\n", x); // no-warning{{extra argument is system header is OK}} in test_unused_system_args()
679 // This should not warn even with -fno-signed-char. in pr12761()
684 printf("%v4d", x); // expected-warning{{invalid conversion specifier 'v'}} in test_opencl_vector_format()
685 printf("%vd", x); // expected-warning{{invalid conversion specifier 'v'}} in test_opencl_vector_format()
686 printf("%0vd", x); // expected-warning{{invalid conversion specifier 'v'}} in test_opencl_vector_format()
687 printf("%hlf", x); // expected-warning{{invalid conversion specifier 'l'}} in test_opencl_vector_format()
688 printf("%hld", x); // expected-warning{{invalid conversion specifier 'l'}} in test_opencl_vector_format()
703 test14_foo("%", "%d", p); // expected-warning{{incomplete format specifier}} in test14_zed()
704 test14_bar("%", "%d", p); // expected-warning{{incomplete format specifier}} in test14_zed()
711 …printf("%n", cip); // expected-warning{{format specifies type 'int *' but the argument has type 'c… in test_qualifiers()
712 …printf("%n", cvip); // expected-warning{{format specifies type 'int *' but the argument has type '… in test_qualifiers()
722 …printf("%n", (cip_t)0); // expected-warning{{format specifies type 'int *' but the argument has ty… in test_qualifiers()
729 …printf("%n", cip); // expected-warning{{format specifies type 'int *' but the argument has type 'c… in test_qualifiers()
730 // expected-warning@-1 {{'%n' specifier not supported on this platform}} in test_qualifiers()
731 …printf("%n", cvip); // expected-warning{{format specifies type 'int *' but the argument has type '… in test_qualifiers()
732 // expected-warning@-1 {{'%n' specifier not supported on this platform}} in test_qualifiers()
734 printf("%n", vip); // expected-warning{{'%n' specifier not supported on this platform}} in test_qualifiers()
741 printf("%n", (ip_t)0); // expected-warning{{'%n' specifier not supported on this platform}} in test_qualifiers()
742 …printf("%n", (cip_t)0); // expected-warning{{format specifies type 'int *' but the argument has ty… in test_qualifiers()
743 // expected-warning@-1 {{'%n' specifier not supported on this platform}} in test_qualifiers()
748 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
749 #pragma GCC diagnostic warning "-Wformat-security"
753 …test_format_security_extra_args(string, 5); // expected-warning {{format string is not a string li… in test_format_security_pos()
754 // expected-note@-1{{treat the string as an argument to avoid this}} in test_format_security_pos()
756 #pragma GCC diagnostic warning "-Wformat-nonliteral"
762 …printf(s1 - 1); // expected-warning {{format string is not a string literal (potentially insecure… in test_char_pointer_arithmetic()
763 // expected-note@-1{{treat the string as an argument to avoid this}} in test_char_pointer_arithmetic()
765 printf(s1 + 2); // no-warning in test_char_pointer_arithmetic()
766 printf(s2 + 2); // no-warning in test_char_pointer_arithmetic()
769 printf((s3 + 2) - 2); // expected-warning{{more '%' conversions than data arguments}} in test_char_pointer_arithmetic()
770 // expected-note@-2{{format string is defined here}} in test_char_pointer_arithmetic()
771 printf(2 + s2); // no-warning in test_char_pointer_arithmetic()
772 printf(6 + s2 - 2); // no-warning in test_char_pointer_arithmetic()
773 printf(2 + (b ? s1 : s2)); // no-warning in test_char_pointer_arithmetic()
776 printf(2 + (b ? s2 : s5)); // expected-warning{{more '%' conversions than data arguments}} in test_char_pointer_arithmetic()
777 // expected-note@-2{{format string is defined here}} in test_char_pointer_arithmetic()
778 printf(2 + (b ? s2 : s5), ""); // no-warning in test_char_pointer_arithmetic()
779 printf(2 + (b ? s1 : s2 - 2), ""); // no-warning in test_char_pointer_arithmetic()
782 printf(2 + (b ? s1 : s6 - 2)); // expected-warning{{more '%' conversions than data arguments}} in test_char_pointer_arithmetic()
783 // expected-note@-2{{format string is defined here}} in test_char_pointer_arithmetic()
784 printf(1 ? s2 + 2 : s2); // no-warning in test_char_pointer_arithmetic()
785 printf(0 ? s2 : s2 + 2); // no-warning in test_char_pointer_arithmetic()
786 printf(2 + s2 + 5 * 3 - 16, ""); // expected-warning{{data argument not used}} in test_char_pointer_arithmetic()
789 printf(s7 + 3, ""); // expected-warning{{more '%' conversions than data arguments}} in test_char_pointer_arithmetic()
790 // expected-note@-2{{format string is defined here}} in test_char_pointer_arithmetic()
795 …-warning{{format string is not a string literal}} expected-error{{incompatible integer to pointer … in PR30481()
799 …printf("%s", op); // expected-warning{{format specifies type 'char *' but the argument has type 'v… in test_printf_opaque_ptr()
813 …printf_arg1("%s string\n", 123); // expected-warning{{format specifies type 'char *' but the argum… in test_block()
822 vprintf(not_fmt, ap); // expected-warning{{format string is not a string literal}} in test_block()
827 …printf_arg2("%s string\n", "foo", "bar"); // expected-warning{{data argument not used by format st… in test_block()
832 // https://github.com/llvm/llvm-project/issues/57102 in test_promotion()
833 // N2562: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2562.pdf in test_promotion()
841 printf("%hhd %hd %d %hhd %hd %d", i, i, i, sc, sc, sc); // no-warning in test_promotion()
842 printf("%hhd %hd %d %hhd %hd %d", uc, uc, uc, c, c, c); // no-warning in test_promotion()
845 …printf("%ld", i); // expected-warning{{format specifies type 'long' but the argument has type 'int… in test_promotion()
846 …printf("%lld", i); // expected-warning{{format specifies type 'long long' but the argument has typ… in test_promotion()
847 …printf("%ld", sc); // expected-warning{{format specifies type 'long' but the argument has type 'si… in test_promotion()
848 …printf("%lld", sc); // expected-warning{{format specifies type 'long long' but the argument has ty… in test_promotion()
849 …printf("%ld", uc); // expected-warning{{format specifies type 'long' but the argument has type 'un… in test_promotion()
850 …printf("%lld", uc); // expected-warning{{format specifies type 'long long' but the argument has ty… in test_promotion()
851 …printf("%llx", i); // expected-warning{{format specifies type 'unsigned long long' but the argumen… in test_promotion()
854 …printf("%hf", // expected-warning{{length modifier 'h' results in undefined behavior or no effect … in test_promotion()
855 sc); // expected-warning{{format specifies type 'double' but the argument has type 'signed char'}} in test_promotion()
858 printf("%hd", ss); // no-warning in test_promotion()
859 …printf("%hhd", ss); // expected-warning{{format specifies type 'char' but the argument has type 's… in test_promotion()
860 printf("%hu", us); // no-warning in test_promotion()
861 …printf("%hhu", ss); // expected-warning{{format specifies type 'unsigned char' but the argument ha… in test_promotion()
864 …printf("%f", i); // expected-warning{{format specifies type 'double' but the argument has type 'in… in test_promotion()
865 …printf("%f", sc); // expected-warning{{format specifies type 'double' but the argument has type 's… in test_promotion()
866 …printf("%f", uc); // expected-warning{{format specifies type 'double' but the argument has type 'u… in test_promotion()
867 …printf("%f", c); // expected-warning{{format specifies type 'double' but the argument has type 'ch… in test_promotion()
868 …printf("%f", ss); // expected-warning{{format specifies type 'double' but the argument has type 's… in test_promotion()
869 …printf("%f", us); // expected-warning{{format specifies type 'double' but the argument has type 'u… in test_promotion()
873 printf("%hhu", 'a'); // no-warning in test_promotion()
874 printf("%hhd", 'a'); // no-warning in test_promotion()
875 …printf("%hd", 'a'); // expected-warning{{format specifies type 'short' but the argument has type '… in test_promotion()
876 …printf("%hu", 'a'); // expected-warning{{format specifies type 'unsigned short' but the argument h… in test_promotion()
877 printf("%d", 'a'); // no-warning in test_promotion()
878 printf("%u", 'a'); // no-warning in test_promotion()
881 …printf("%s", i); // expected-warning{{format specifies type 'char *' but the argument has type 'in… in test_promotion()