]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gcc.dg/tree-ssa/builtin-snprintf-warn-6.c
Fix profile update in tree_transform_and_unroll_loop
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / builtin-snprintf-warn-6.c
CommitLineData
639ece7a
MS
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" } */
5
6typedef __SIZE_TYPE__ size_t;
7
8extern int snprintf (char*, size_t, const char*, ...);
9
10
11void f (unsigned j, char *p)
12{
13 if (j > 999)
14 j = 0;
15
16 snprintf (p, 4, "%3u", j);
17}
18
19void g (unsigned j, char *p)
20{
21 if (j > 999)
22 return;
23
24 snprintf (p, 4, "%3u", j); // { dg-bogus "-Wformat-truncation" }
25}
26
27
28void pr78969_c4 (char * p /* NNN\0" */)
29{
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" }
33 }
34}
35
36
37void sink (int, ...);
38
39char d[4];
40
41void pr78969_c12 (unsigned i)
42{
43 if (i >= 1000 && i < 10000)
44 snprintf (d, 4, "%3d", i / 10); // { dg-bogus "-Wformat-truncation" }
45 else
46 sink (i / 10 % 10);
47}