1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
/* 78696 - -fprintf-return-value misoptimizes %.Ng where N is greater than 10
Test to verify the correctness of ranges of output computed for floating
point directives.
{ dg-do compile }
{ dg-options "-O2 -Wformat -Wformat-length -ftrack-macro-expansion=0" } */
typedef __builtin_va_list va_list;
char dst[1];
extern void sink (int, void*);
/* Macro to test either width or precision specified by the asterisk
(but not both). */
#define T1(fmt, a) sink (__builtin_sprintf (dst + 1, fmt, a, x), dst)
/* Macro to test both width and precision specified by the asterisk. */
#define T2(fmt, w, p) sink (__builtin_sprintf (dst + 1, fmt, w, p, x), dst)
/* Macro to test vsprintf with both width and precision specified by
the asterisk. */
#define T(fmt) sink (__builtin_vsprintf (dst + 1, fmt, va), dst)
/* Exercise %a. */
void test_a (int w, int p, double x)
{
T1 ("%.*a", 0); /* { dg-warning "between 6 and 10 bytes" } */
T1 ("%.*a", 1); /* { dg-warning "between 8 and 12 bytes" } */
T1 ("%.*a", 2); /* { dg-warning "between 9 and 13 bytes" } */
T1 ("%.*a", 99); /* { dg-warning "between 106 and 110 bytes" } */
T1 ("%.*a", 199); /* { dg-warning "between 206 and 210 bytes" } */
T1 ("%.*a", 1099); /* { dg-warning "between 1106 and 1110 bytes" } */
T1 ("%*.a", 0); /* { dg-warning "between 6 and 10 bytes" } */
T1 ("%*.a", 1); /* { dg-warning "between 6 and 10 bytes" } */
T1 ("%*.a", 3); /* { dg-warning "between 6 and 10 bytes" } */
T1 ("%*.a", 6); /* { dg-warning "between 6 and 10 bytes" } */
T1 ("%*.a", 7); /* { dg-warning "between 7 and 10 bytes" } */
T1 ("%*.a", w); /* { dg-warning "writing 6 or more bytes" } */
T1 ("%*.0a", w); /* { dg-warning "writing 6 or more bytes" } */
T1 ("%*.1a", w); /* { dg-warning "writing 8 or more bytes" } */
T1 ("%*.2a", w); /* { dg-warning "writing 9 or more bytes" } */
T1 ("%.*a", p); /* { dg-warning "writing 6 or more bytes" } */
T1 ("%1.*a", p); /* { dg-warning "writing 6 or more bytes" } */
T1 ("%2.*a", p); /* { dg-warning "writing 6 or more bytes" } */
T1 ("%3.*a", p); /* { dg-warning "writing 6 or more bytes" } */
T2 ("%*.*a", w, p); /* { dg-warning "writing 6 or more bytes" } */
T2 ("%*.*a", w, p); /* { dg-warning "writing 6 or more bytes" } */
T2 ("%*.*a", w, p); /* { dg-warning "writing 6 or more bytes" } */
}
/* Exercise %e. */
void test_e (int w, int p, double x)
{
T1 ("%.*e", 0); /* { dg-warning "between 5 and 7 bytes" } */
T1 ("%.*e", 1); /* { dg-warning "between 7 and 9 bytes" } */
T1 ("%.*e", 2); /* { dg-warning "between 8 and 10 bytes" } */
T1 ("%.*e", 99); /* { dg-warning "between 105 and 107 bytes" } */
T1 ("%.*e", 199); /* { dg-warning "between 205 and 207 bytes" } */
T1 ("%.*e", 1099); /* { dg-warning "between 1105 and 1107 bytes" } */
T1 ("%*.e", 0); /* { dg-warning "between 5 and 7 bytes" } */
T1 ("%*.e", 1); /* { dg-warning "between 5 and 7 bytes" } */
T1 ("%*.e", 1); /* { dg-warning "between 5 and 7 bytes" } */
T1 ("%*.e", 3); /* { dg-warning "between 5 and 7 bytes" } */
T1 ("%*.e", 6); /* { dg-warning "between 6 and 7 bytes" } */
T1 ("%*.e", 7); /* { dg-warning "writing 7 bytes" } */
T1 ("%*.e", w); /* { dg-warning "writing 5 or more bytes" } */
T1 ("%*.0e", w); /* { dg-warning "writing 5 or more bytes" } */
T1 ("%*.1e", w); /* { dg-warning "writing 7 or more bytes" } */
T1 ("%*.2e", w); /* { dg-warning "writing 8 or more bytes" } */
T1 ("%.*e", p); /* { dg-warning "writing 5 or more bytes" } */
T1 ("%1.*e", p); /* { dg-warning "writing 5 or more bytes" } */
T1 ("%2.*e", p); /* { dg-warning "writing 5 or more bytes" } */
T1 ("%3.*e", p); /* { dg-warning "writing 5 or more bytes" } */
T2 ("%*.*e", w, p); /* { dg-warning "writing 5 or more bytes" } */
T2 ("%*.*e", w, p); /* { dg-warning "writing 5 or more bytes" } */
T2 ("%*.*e", w, p); /* { dg-warning "writing 5 or more bytes" } */
}
/* Exercise %f. */
void test_f (int w, int p, double x)
{
T1 ("%.*f", 0); /* { dg-warning "between 1 and 310 bytes" } */
T1 ("%.*f", 1); /* { dg-warning "between 3 and 312 bytes" } */
T1 ("%.*f", 2); /* { dg-warning "between 4 and 313 bytes" } */
T1 ("%.*f", 99); /* { dg-warning "between 101 and 410 bytes" } */
T1 ("%.*f", 199); /* { dg-warning "between 201 and 510 bytes" } */
T1 ("%.*f", 1099); /* { dg-warning "between 1101 and 1410 bytes" } */
T2 ("%*.*f", 0, 0); /* { dg-warning "between 1 and 310 bytes" } */
T2 ("%*.*f", 1, 0); /* { dg-warning "between 1 and 310 bytes" } */
T2 ("%*.*f", 2, 0); /* { dg-warning "between 2 and 310 bytes" } */
T2 ("%*.*f", 3, 0); /* { dg-warning "between 3 and 310 bytes" } */
T2 ("%*.*f", 310, 0); /* { dg-warning "writing 310 bytes" } */
T2 ("%*.*f", 311, 0); /* { dg-warning "writing 311 bytes" } */
T2 ("%*.*f", 312, 312); /* { dg-warning "between 314 and 623 bytes" } */
T2 ("%*.*f", 312, 313); /* { dg-warning "between 315 and 624 bytes" } */
T1 ("%*.f", w); /* { dg-warning "writing 1 or more bytes" } */
T1 ("%*.0f", w); /* { dg-warning "writing 1 or more bytes" } */
T1 ("%*.1f", w); /* { dg-warning "writing 3 or more bytes" } */
T1 ("%*.2f", w); /* { dg-warning "writing 4 or more bytes" } */
T1 ("%.*f", p); /* { dg-warning "writing 1 or more bytes" } */
T1 ("%1.*f", p); /* { dg-warning "writing 1 or more bytes" } */
T1 ("%2.*f", p); /* { dg-warning "writing 2 or more bytes" } */
T1 ("%3.*f", p); /* { dg-warning "writing 3 or more bytes" } */
T2 ("%*.*f", w, p); /* { dg-warning "writing 1 or more bytes" } */
T2 ("%*.*f", w, p); /* { dg-warning "writing 1 or more bytes" } */
T2 ("%*.*f", w, p); /* { dg-warning "writing 1 or more bytes" } */
}
/* Exercise %g. The expected output is the lesser of %e and %f. */
void test_g (double x)
{
T1 ("%.*g", 0); /* { dg-warning "between 1 and 7 bytes" } */
T1 ("%.*g", 1); /* { dg-warning "between 1 and 7 bytes" } */
T1 ("%.*g", 2); /* { dg-warning "between 1 and 9 bytes" } */
T1 ("%.*g", 99); /* { dg-warning "between 1 and 106 bytes" } */
T1 ("%.*g", 199); /* { dg-warning "between 1 and 206 bytes" } */
T1 ("%.*g", 1099); /* { dg-warning "between 1 and 310 bytes" } */
T2 ("%*.*g", 0, 0); /* { dg-warning "between 1 and 7 bytes" } */
T2 ("%*.*g", 1, 0); /* { dg-warning "between 1 and 7 bytes" } */
T2 ("%*.*g", 2, 0); /* { dg-warning "between 2 and 7 bytes" } */
T2 ("%*.*g", 3, 0); /* { dg-warning "between 3 and 7 bytes" } */
T2 ("%*.*g", 7, 0); /* { dg-warning "writing 7 bytes" } */
T2 ("%*.*g", 310, 0); /* { dg-warning "writing 310 bytes" } */
T2 ("%*.*g", 311, 0); /* { dg-warning "writing 311 bytes" } */
T2 ("%*.*g", 312, 312); /* { dg-warning "writing 312 bytes" } */
T2 ("%*.*g", 312, 313); /* { dg-warning "writing 312 bytes" } */
T2 ("%*.*g", 333, 999); /* { dg-warning "writing 333 bytes" } */
}
/* Exercise %a. */
void test_a_va (va_list va)
{
T ("%.0a"); /* { dg-warning "between 6 and 10 bytes" } */
T ("%.1a"); /* { dg-warning "between 8 and 12 bytes" } */
T ("%.2a"); /* { dg-warning "between 9 and 13 bytes" } */
T ("%.99a"); /* { dg-warning "between 106 and 110 bytes" } */
T ("%.199a"); /* { dg-warning "between 206 and 210 bytes" } */
T ("%.1099a"); /* { dg-warning "between 1106 and 1110 bytes" } */
T ("%0.a"); /* { dg-warning "between 6 and 10 bytes" } */
T ("%1.a"); /* { dg-warning "between 6 and 10 bytes" } */
T ("%3.a"); /* { dg-warning "between 6 and 10 bytes" } */
T ("%6.a"); /* { dg-warning "between 6 and 10 bytes" } */
T ("%7.a"); /* { dg-warning "between 7 and 10 bytes" } */
T ("%*.a"); /* { dg-warning "writing 6 or more bytes" } */
T ("%*.0a"); /* { dg-warning "writing 6 or more bytes" } */
T ("%*.1a"); /* { dg-warning "writing 8 or more bytes" } */
T ("%*.2a"); /* { dg-warning "writing 9 or more bytes" } */
T ("%.*a"); /* { dg-warning "writing 6 or more bytes" } */
T ("%1.*a"); /* { dg-warning "writing 6 or more bytes" } */
T ("%2.*a"); /* { dg-warning "writing 6 or more bytes" } */
T ("%6.*a"); /* { dg-warning "writing 6 or more bytes" } */
T ("%9.*a"); /* { dg-warning "writing 9 or more bytes" } */
T ("%*.*a"); /* { dg-warning "writing 6 or more bytes" } */
}
/* Exercise %e. */
void test_e_va (va_list va)
{
T ("%e"); /* { dg-warning "between 12 and 14 bytes" } */
T ("%+e"); /* { dg-warning "between 13 and 14 bytes" } */
T ("% e"); /* { dg-warning "between 13 and 14 bytes" } */
T ("%#e"); /* { dg-warning "between 12 and 14 bytes" } */
T ("%#+e"); /* { dg-warning "between 13 and 14 bytes" } */
T ("%# e"); /* { dg-warning "between 13 and 14 bytes" } */
T ("%.e"); /* { dg-warning "between 5 and 7 bytes" } */
T ("%.0e"); /* { dg-warning "between 5 and 7 bytes" } */
T ("%.1e"); /* { dg-warning "between 7 and 9 bytes" } */
T ("%.2e"); /* { dg-warning "between 8 and 10 bytes" } */
T ("%.99e"); /* { dg-warning "between 105 and 107 bytes" } */
T ("%.199e"); /* { dg-warning "between 205 and 207 bytes" } */
T ("%.1099e"); /* { dg-warning "between 1105 and 1107 bytes" } */
T ("%0.e"); /* { dg-warning "between 5 and 7 bytes" } */
T ("%1.e"); /* { dg-warning "between 5 and 7 bytes" } */
T ("%1.e"); /* { dg-warning "between 5 and 7 bytes" } */
T ("%3.e"); /* { dg-warning "between 5 and 7 bytes" } */
T ("%6.e"); /* { dg-warning "between 6 and 7 bytes" } */
T ("%7.e"); /* { dg-warning "writing 7 bytes" } */
T ("%.*e"); /* { dg-warning "writing 5 or more bytes" } */
T ("%1.*e"); /* { dg-warning "writing 5 or more bytes" } */
T ("%6.*e"); /* { dg-warning "writing 6 or more bytes" } */
T ("%9.*e"); /* { dg-warning "writing 9 or more bytes" } */
T ("%*.*e"); /* { dg-warning "writing 5 or more bytes" } */
}
/* Exercise %f. */
void test_f_va (va_list va)
{
T ("%f"); /* { dg-warning "between 8 and 317 bytes" } */
T ("%+f"); /* { dg-warning "between 9 and 317 bytes" } */
T ("% f"); /* { dg-warning "between 9 and 317 bytes" } */
T ("%#f"); /* { dg-warning "between 8 and 317 bytes" } */
T ("%+f"); /* { dg-warning "between 9 and 317 bytes" } */
T ("% f"); /* { dg-warning "between 9 and 317 bytes" } */
T ("%#+f"); /* { dg-warning "between 9 and 317 bytes" } */
T ("%# f"); /* { dg-warning "between 9 and 317 bytes" } */
T ("%.f"); /* { dg-warning "between 1 and 310 bytes" } */
T ("%.0f"); /* { dg-warning "between 1 and 310 bytes" } */
T ("%.1f"); /* { dg-warning "between 3 and 312 bytes" } */
T ("%.2f"); /* { dg-warning "between 4 and 313 bytes" } */
T ("%.99f"); /* { dg-warning "between 101 and 410 bytes" } */
T ("%.199f"); /* { dg-warning "between 201 and 510 bytes" } */
T ("%.1099f"); /* { dg-warning "between 1101 and 1410 bytes" } */
T ("%0.0f"); /* { dg-warning "between 1 and 310 bytes" } */
T ("%1.0f"); /* { dg-warning "between 1 and 310 bytes" } */
T ("%2.0f"); /* { dg-warning "between 2 and 310 bytes" } */
T ("%3.0f"); /* { dg-warning "between 3 and 310 bytes" } */
T ("%310.0f"); /* { dg-warning "writing 310 bytes" } */
T ("%311.0f"); /* { dg-warning "writing 311 bytes" } */
T ("%312.312f"); /* { dg-warning "between 314 and 623 bytes" } */
T ("%312.313f"); /* { dg-warning "between 315 and 624 bytes" } */
T ("%.*f"); /* { dg-warning "writing 1 or more bytes" } */
T ("%1.*f"); /* { dg-warning "writing 1 or more bytes" } */
T ("%3.*f"); /* { dg-warning "writing 3 or more bytes" } */
T ("%*.*f"); /* { dg-warning "writing 1 or more bytes" } */
}
/* Exercise %g. The expected output is the lesser of %e and %f. */
void test_g_va (va_list va)
{
T ("%g"); /* { dg-warning "between 1 and 13 bytes" } */
T ("%+g"); /* { dg-warning "between 2 and 13 bytes" } */
T ("% g"); /* { dg-warning "between 2 and 13 bytes" } */
T ("%#g"); /* { dg-warning "between 1 and 13 bytes" } */
T ("%#+g"); /* { dg-warning "between 2 and 13 bytes" } */
T ("%# g"); /* { dg-warning "between 2 and 13 bytes" } */
T ("%.g"); /* { dg-warning "between 1 and 7 bytes" } */
T ("%.0g"); /* { dg-warning "between 1 and 7 bytes" } */
T ("%.1g"); /* { dg-warning "between 1 and 7 bytes" } */
T ("%.2g"); /* { dg-warning "between 1 and 9 bytes" } */
T ("%.99g"); /* { dg-warning "between 1 and 106 bytes" } */
T ("%.199g"); /* { dg-warning "between 1 and 206 bytes" } */
T ("%.1099g"); /* { dg-warning "between 1 and 310 bytes" } */
T ("%0.0g"); /* { dg-warning "between 1 and 7 bytes" } */
T ("%1.0g"); /* { dg-warning "between 1 and 7 bytes" } */
T ("%2.0g"); /* { dg-warning "between 2 and 7 bytes" } */
T ("%3.0g"); /* { dg-warning "between 3 and 7 bytes" } */
T ("%7.0g"); /* { dg-warning "writing 7 bytes" } */
T ("%310.0g"); /* { dg-warning "writing 310 bytes" } */
T ("%311.0g"); /* { dg-warning "writing 311 bytes" } */
T ("%312.312g"); /* { dg-warning "writing 312 bytes" } */
T ("%312.313g"); /* { dg-warning "writing 312 bytes" } */
T ("%333.999g"); /* { dg-warning "writing 333 bytes" } */
T ("%.*g"); /* { dg-warning "writing 1 or more bytes" } */
T ("%1.*g"); /* { dg-warning "writing 1 or more bytes" } */
T ("%4.*g"); /* { dg-warning "writing 4 or more bytes" } */
T ("%*.*g"); /* { dg-warning "writing 1 or more bytes" } */
}
|