libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / builtin-snprintf-8.c
blob95b0b44bcf07b4994257659db7b57d533c3b0913
1 /* Test to verify that snprintf can determine the correct range
2 of lengths of string arguments based on the results of prior
3 calls to strlen.
4 { dg-do compile }
5 { dg-options "-O2 -Wall -fdump-tree-optimized" } */
7 typedef __SIZE_TYPE__ size_t;
9 void abort (void);
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))
17 abort ();
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))
24 abort ();
27 void one_str_maxlen (const char *str)
29 if (2 >= strlen (str))
30 if (2 < snprintf (0, 0, "%s", str))
31 abort ();
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))
38 abort ();
41 /* { dg-final { scan-tree-dump-not "abort" "optimized" } } */