2018-04-09 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / pr47917.c
blob725bc01c8a0d34d57dc9f64751abfd7659de3927
1 /* PR middle-end/47917 */
2 /* { dg-do compile } */
3 /* { dg-options "-O2 -fdump-tree-optimized" } */
5 extern int snprintf (char *, __SIZE_TYPE__, const char *, ...);
6 extern int memcmp (const void *, const void *, __SIZE_TYPE__);
7 extern void abort (void);
9 char buf1[6], buf2[6], buf3[4], buf4[4];
10 int i;
12 int
13 foo (void)
15 int ret = snprintf (buf1, sizeof buf1, "abcde");
16 ret += snprintf (buf2, sizeof buf2, "abcdef") * 16;
17 ret += snprintf (buf3, sizeof buf3, "%s", i++ < 6 ? "abc" : "def") * 256;
18 ret += snprintf (buf4, sizeof buf4, "%s", i++ > 10 ? "abcde" : "defgh") * 4096;
19 return ret;
22 int
23 main (void)
25 if (foo () != 5 + 6 * 16 + 3 * 256 + 5 * 4096)
26 abort ();
27 if (memcmp (buf1, "abcde", 6) != 0
28 || memcmp (buf2, "abcde", 6) != 0
29 || memcmp (buf3, "abc", 4) != 0
30 || memcmp (buf4, "def", 4) != 0
31 || i != 2)
32 abort ();
33 return 0;
36 /* { dg-final { scan-tree-dump-times "snprintf" 2 "optimized" } } */
37 /* { dg-final { scan-tree-dump-times "sprintf" 0 "optimized" } } */