libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / builtin-snprintf-warn-5.c
blobbecba05277b5159ec4963e48c220df6540b0032b
1 /* Test to verify that --param ssa_name_def_chain_limit can be used to
2 limit the maximum number of SSA_NAME assignments the built-in code
3 follows.
4 { dg-do compile }
5 { dg-options "-O2 -Wall -Wformat-truncation=2 --param ssa-name-def-chain-limit=4 -fdump-tree-optimized" } */
7 typedef __SIZE_TYPE__ size_t;
9 int snprintf (char * restrict, size_t, const char *restrict, ...);
11 void sink (const char*, ...);
13 const char a0[] = "";
14 const char a1[] = "1";
15 const char a2[] = "12";
16 const char a3[] = "123";
17 const char a4[] = "1234";
18 const char a5[] = "12345";
19 const char a6[] = "123456";
20 const char a7[] = "1234567";
21 const char a8[] = "12345678";
22 const char a9[] = "123456789";
24 int i0, i1, i2, i3, i4, i5, i6, i7, i8;
26 void g1 (char *d)
28 const char *p0 = i0 ? a0 : a1;
29 const char *p1 = i1 ? p0 : a2;
31 sink (p0, p1);
33 snprintf (d, 1, "%s", p1); // { dg-warning "\\\[-Wformat-truncation" }
36 void g2 (char *d)
38 const char *p0 = i0 ? a0 : a1;
39 const char *p1 = i1 ? p0 : a2;
40 const char *p2 = i2 ? p1 : a3;
42 sink (p0, p1, p2);
44 snprintf (d, 2, "%s", p2); // { dg-warning "\\\[-Wformat-truncation" }
47 void g3 (char *d)
49 const char *p0 = i0 ? a0 : a1;
50 const char *p1 = i1 ? p0 : a2;
51 const char *p2 = i2 ? p1 : a3;
52 const char *p3 = i3 ? p2 : a4;
54 sink (p0, p1, p2, p3);
56 snprintf (d, 3, "%s", p3); // { dg-warning "\\\[-Wformat-truncation" }
59 void g4 (char *d)
61 const char *p0 = i0 ? a0 : a1;
62 const char *p1 = i1 ? p0 : a2;
63 const char *p2 = i2 ? p1 : a3;
64 const char *p3 = i3 ? p2 : a4;
65 const char *p4 = i4 ? p3 : a5;
67 sink (p0, p1, p2, p3, p4);
69 // p4 below is the result of the following five PHI assignments
70 // and with the limit set to 4 the snprintf call is not diagnosed
71 // iftmp.0_7 = PHI <&a0(2), &a1(3)>
72 // iftmp.2_8 = PHI <iftmp.0_7(4), &a2(5)>
73 // iftmp.4_9 = PHI <iftmp.2_8(6), &a3(7)>
74 // iftmp.6_10 = PHI <iftmp.4_9(8), &a4(9)>
75 // iftmp.8_17 = PHI <iftmp.6_10(10), &a5(11)>
76 // p4 = iftmp.8_17
77 snprintf (d, 4, "%s", p4);
80 void g5 (char *d)
82 const char *p0 = i0 ? a0 : a1;
83 const char *p1 = i1 ? p0 : a2;
84 const char *p2 = i2 ? p1 : a3;
85 const char *p3 = i3 ? p2 : a4;
86 const char *p4 = i4 ? p3 : a5;
87 const char *p5 = i5 ? p4 : a6;
89 sink (p0, p1, p2, p3, p4, p5);
91 snprintf (d, 5, "%s", p5);
94 void g6 (char *d)
96 const char *p0 = i0 ? a0 : a1;
97 const char *p1 = i1 ? p0 : a2;
98 const char *p2 = i2 ? p1 : a3;
99 const char *p3 = i3 ? p2 : a4;
100 const char *p4 = i4 ? p3 : a5;
101 const char *p5 = i5 ? p4 : a6;
102 const char *p6 = i6 ? p5 : a7;
104 sink (p0, p1, p2, p3, p4, p5, p6);
106 snprintf (d, 6, "%s", p6);
109 void g7 (char *d)
111 const char *p0 = i0 ? a0 : a1;
112 const char *p1 = i1 ? p0 : a2;
113 const char *p2 = i2 ? p1 : a3;
114 const char *p3 = i3 ? p2 : a4;
115 const char *p4 = i4 ? p3 : a5;
116 const char *p5 = i5 ? p4 : a6;
117 const char *p6 = i6 ? p5 : a7;
118 const char *p7 = i7 ? p6 : a8;
120 sink (p0, p1, p2, p3, p4, p5, p6, p7);
122 snprintf (d, 7, "%s", p7);
125 void g8 (char *d)
127 const char *p0 = i0 ? a0 : a1;
128 const char *p1 = i1 ? p0 : a2;
129 const char *p2 = i2 ? p1 : a3;
130 const char *p3 = i3 ? p2 : a4;
131 const char *p4 = i4 ? p3 : a5;
132 const char *p5 = i5 ? p4 : a6;
133 const char *p6 = i6 ? p5 : a7;
134 const char *p7 = i7 ? p6 : a8;
135 const char *p8 = i8 ? p7 : a9;
137 sink (p0, p1, p2, p3, p4, p5, p6, p7, p8);
139 snprintf (d, 8, "%s", p8);