libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / builtin-snprintf-warn-6.c
blob2857e83369f6323c0b4a33a24efa02be47a2106b
1 /* PR tree-optimization/78969 - bogus snprintf truncation warning due to
2 missing range info
3 { dg-do compile }
4 { dg-options "-O2 -Wall -Wformat-truncation=2" } */
6 typedef __SIZE_TYPE__ size_t;
8 extern int snprintf (char*, size_t, const char*, ...);
11 void f (unsigned j, char *p)
13 if (j > 999)
14 j = 0;
16 snprintf (p, 4, "%3u", j);
19 void g (unsigned j, char *p)
21 if (j > 999)
22 return;
24 snprintf (p, 4, "%3u", j); // { dg-bogus "-Wformat-truncation" }
28 void pr78969_c4 (char * p /* NNN\0" */)
30 for (int idx = 0; idx < 1000; idx++) {
31 // guaranteed to be in [0-999] range
32 snprintf (p, 4, "%d", idx); // { dg-bogus "-Wformat-truncation" }
37 void sink (int, ...);
39 char d[4];
41 void pr78969_c12 (unsigned i)
43 if (i >= 1000 && i < 10000)
44 snprintf (d, 4, "%3d", i / 10); // { dg-bogus "-Wformat-truncation" }
45 else
46 sink (i / 10 % 10);