1 /* PR tree-optimization/77671 - missing -Wformat-overflow warning
2 on sprintf overflow with "%s"
4 { dg-options "-O2 -Wformat -Wno-format-zero-length -fdump-tree-optimized" } */
10 /* String exactly 4100 characters long (plus the terminating NUL). */
11 extern const char s4100
[4101];
13 void test_sprintf (const char *s
)
15 #define IGN(...) __builtin_sprintf (buffer, __VA_ARGS__); sink (buffer)
17 /* Each of the following calls is expected to be transformed into
18 one of memcpy or strcpy. */
22 /* FIXME: Transform to strcpy/memcpy. */
23 /* IGN (s4100 + 5); */
29 IGN ("%s", s4100
+ 5);
31 /* FIXME: This can be transformed into strcpy. */
37 void test_snprintf (void)
40 #define IGN(N, ...) __builtin_snprintf (buffer, N, __VA_ARGS__); sink (buffer)
42 /* Each of the following calls is expected to be transformed into
43 one of memcpy or strcpy. */
48 /* FIXME: Transform to strcpy/memcpy. */
49 /* IGN (4096, s4100 + 5); */
53 IGN (8, "%s", "1234567");
55 IGN (4096, "%s", s4100
+ 5);
58 #if 0 /* FIXME: Implement vs{,n}printf optimization. */
60 void test_vsprintf (__builtin_va_list va
)
63 #define IGN(fmt) __builtin_vsprintf (buffer, fmt, va); sink (buffer)
65 /* Each of the following calls is expected to be transformed into
66 one of memcpy or strcpy. */
75 void test_vsnprintf (__builtin_va_list va
)
78 #define IGN(N, fmt) __builtin_vsnprintf (buffer, N, fmt, va); sink (buffer)
80 /* Each of the following calls is expected to be transformed into
81 one of memcpy or strcpy. */
85 IGN (4096, s4100
+ 5);
90 /* { dg-final { scan-tree-dump-not "builtin_sprintf" "optimized" } }
91 { dg-final { scan-tree-dump-not "builtin_snprintf" "optimized" } }
92 { dg-final { scan-tree-dump-not "builtin_vsprintf" "optimized" } }
93 { dg-final { scan-tree-dump-not "builtin_vsnprintf" "optimized" } } */
95 #define S10 "0123456789"
96 #define S100 S10 S10 S10 S10 S10 S10 S10 S10 S10 S10
97 #define S1000 S100 S100 S100 S100 S100 S100 S100 S100 S100 S100
99 const char s4100
[4101] = S1000 S1000 S1000 S1000 S100
;