1 /* Test to verify that snprintf can determine the correct range
2 of lengths of string arguments based on the results of prior
5 { dg-options "-O2 -Wall -fdump-tree-optimized" } */
7 typedef __SIZE_TYPE__
size_t;
10 size_t strlen (const char *);
11 int snprintf (char * restrict
, size_t, const char *restrict
, ...);
13 void one_str_exact (const char *str
)
15 if (1 == strlen (str
))
16 if (1 != snprintf (0, 0, "%s", str
))
20 void two_str_exact (const char *s1
, const char *s2
)
22 if (1 == strlen (s1
) && 2 == strlen (s2
))
23 if (3 != snprintf (0, 0, "%s%s", s1
, s2
))
27 void one_str_maxlen (const char *str
)
29 if (2 >= strlen (str
))
30 if (2 < snprintf (0, 0, "%s", str
))
34 void two_str_maxlen (const char *s1
, const char *s2
)
36 if (2 >= strlen (s1
) && 3 >= strlen (s2
))
37 if (5 < snprintf (0, 0, "%s%s", s1
, s2
))
41 /* { dg-final { scan-tree-dump-not "abort" "optimized" } } */