Debian Codegraph @

gcc/testsuite/g++.dg/torture/Wsizeof-pointer-memaccess2.C

raw
1 // Test -Wsizeof-pointer-memaccess warnings.
2 // { dg-do compile }
3 // { dg-options "-Wall -Wno-array-bounds -Wno-sizeof-array-argument -Wno-stringop-overflow -Wno-stringop-overread -Wno-stringop-truncation" }
4 // Test just twice, once with -O0 non-fortified, once with -O2 fortified,
5 // suppressing buffer overflow warnings.
6 // { dg-skip-if "" { *-*-* } { "*" } { "-O0" "-O2" } }
7 // { dg-skip-if "" { *-*-* } { "-flto" } { "" } }
8
9 extern "C" {
10
11 typedef __SIZE_TYPE__ size_t;
12 extern void *memset (void *, int, size_t);
13 extern void *memcpy (void *__restrict, const void *__restrict, size_t);
14 extern void *memmove (void *__restrict, const void *__restrict, size_t);
15 extern int memcmp (const void *, const void *, size_t);
16 extern char *strncpy (char *__restrict, const char *__restrict, size_t);
17 extern char *strncat (char *__restrict, const char *__restrict, size_t);
18 extern char *stpncpy (char *__restrict, const char *__restrict, size_t);
19 extern char *strndup (const char *, size_t);
20 extern int strncmp (const char *, const char *, size_t);
21 extern int strncasecmp (const char *, const char *, size_t);
22
23 #ifdef __OPTIMIZE__
24 # define bos(ptr) __builtin_object_size (ptr, 1)
25 # define bos0(ptr) __builtin_object_size (ptr, 0)
26
27 __attribute__((__always_inline__, __gnu_inline__, __artificial__))
28 extern inline void *
29 memset (void *dest, int c, size_t len)
30 {
31 return __builtin___memset_chk (dest, c, len, bos0 (dest));
32 }
33
34 __attribute__((__always_inline__, __gnu_inline__, __artificial__))
35 extern inline void *
36 memcpy (void *__restrict dest, const void *__restrict src, size_t len)
37 {
38 return __builtin___memcpy_chk (dest, src, len, bos0 (dest));
39 }
40
41 __attribute__((__always_inline__, __gnu_inline__, __artificial__))
42 extern inline void *
43 memmove (void *dest, const void *src, size_t len)
44 {
45 return __builtin___memmove_chk (dest, src, len, bos0 (dest));
46 }
47
48 __attribute__((__always_inline__, __gnu_inline__, __artificial__))
49 extern inline char *
50 strncpy (char *__restrict dest, const char *__restrict src, size_t len)
51 {
52 return __builtin___strncpy_chk (dest, src, len, bos (dest));
53 }
54
55 __attribute__((__always_inline__, __gnu_inline__, __artificial__))
56 extern inline char *
57 strncat (char *dest, const char *src, size_t len)
58 {
59 return __builtin___strncat_chk (dest, src, len, bos (dest));
60 }
61
62 __attribute__((__always_inline__, __gnu_inline__, __artificial__))
63 extern inline char *
64 stpncpy (char *__restrict dest, const char *__restrict src, size_t len)
65 {
66 return __builtin___stpncpy_chk (dest, src, len, bos (dest));
67 }
68 #endif
69
70 }
71
72 struct A { short a, b; int c, d; long e, f; };
73 typedef struct A TA;
74 typedef struct A *PA;
75 typedef TA *PTA;
76 struct B {};
77 typedef struct B TB;
78 typedef struct B *PB;
79 typedef TB *PTB;
80 typedef int X[3][3][3];
81
82 template <int N>
83 int
84 f1 (void *x, int z)
85 {
86 struct A a, *pa1 = &a;
87 TA *pa2 = &a;
88 PA pa3 = &a;
89 PTA pa4 = &a;
90 memset (&a, 0, sizeof (&a)); // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
91 memset (pa1, 0, sizeof (pa1)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
92 memset (pa2, 0, sizeof pa2); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
93 memset (pa3, 0, sizeof (pa3)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
94 memset (pa4, 0, sizeof pa4); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
95 memset (pa1, 0, sizeof (struct A *)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
96 memset (pa2, 0, sizeof (PTA)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
97 memset (pa3, 0, sizeof (PA)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
98 memset (pa4, 0, sizeof (__typeof (pa4))); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
99
100 memcpy (&a, x, sizeof (&a)); // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
101 memcpy (pa1, x, sizeof (pa1)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
102 memcpy (pa2, x, sizeof pa2); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
103 memcpy (pa3, x, sizeof (pa3)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
104 memcpy (pa4, x, sizeof pa4); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
105 memcpy (pa1, x, sizeof (struct A *)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
106 memcpy (pa2, x, sizeof (PTA)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
107 memcpy (pa3, x, sizeof (PA)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
108 memcpy (pa4, x, sizeof (__typeof (pa4))); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
109
110 memcpy (x, &a, sizeof (&a)); // { dg-warning "call is the same expression as the source; did you mean to remove the addressof" }
111 memcpy (x, pa1, sizeof (pa1)); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
112 memcpy (x, pa2, sizeof pa2); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
113 memcpy (x, pa3, sizeof (pa3)); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
114 memcpy (x, pa4, sizeof pa4); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
115 memcpy (x, pa1, sizeof (struct A *)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" }
116 memcpy (x, pa2, sizeof (PTA)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" }
117 memcpy (x, pa3, sizeof (PA)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" }
118 memcpy (x, pa4, sizeof (__typeof (pa4))); // { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" }
119
120 memmove (&a, x, sizeof (&a)); // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
121 memmove (pa1, x, sizeof (pa1)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
122 memmove (pa2, x, sizeof pa2); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
123 memmove (pa3, x, sizeof (pa3)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
124 memmove (pa4, x, sizeof pa4); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
125 memmove (pa1, x, sizeof (struct A *)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
126 memmove (pa2, x, sizeof (PTA)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
127 memmove (pa3, x, sizeof (PA)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
128 memmove (pa4, x, sizeof (__typeof (pa4)));// { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
129
130 memmove (x, &a, sizeof (&a)); // { dg-warning "call is the same expression as the source; did you mean to remove the addressof" }
131 memmove (x, pa1, sizeof (pa1)); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
132 memmove (x, pa2, sizeof pa2); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
133 memmove (x, pa3, sizeof (pa3)); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
134 memmove (x, pa4, sizeof pa4); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
135 memmove (x, pa1, sizeof (struct A *)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" }
136 memmove (x, pa2, sizeof (PTA)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" }
137 memmove (x, pa3, sizeof (PA)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" }
138 memmove (x, pa4, sizeof (__typeof (pa4)));// { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" }
139
140 z += memcmp (&a, x, sizeof (&a)); // { dg-warning "call is the same expression as the first source; did you mean to remove the addressof" }
141 z += memcmp (pa1, x, sizeof (pa1)); // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
142 z += memcmp (pa2, x, sizeof pa2); // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
143 z += memcmp (pa3, x, sizeof (pa3)); // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
144 z += memcmp (pa4, x, sizeof pa4); // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
145 z += memcmp (pa1, x, sizeof (struct A *));// { dg-warning "call is the same pointer type \[^\n\r\]* as the first source; expected \[^\n\r\]* or an explicit length" }
146 z += memcmp (pa2, x, sizeof (PTA)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the first source; expected \[^\n\r\]* or an explicit length" }
147 z += memcmp (pa3, x, sizeof (PA)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the first source; expected \[^\n\r\]* or an explicit length" }
148
149 z += memcmp (x, &a, sizeof (&a)); // { dg-warning "call is the same expression as the second source; did you mean to remove the addressof" }
150 z += memcmp (x, pa1, sizeof (pa1)); // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
151 z += memcmp (x, pa2, sizeof pa2); // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
152 z += memcmp (x, pa3, sizeof (pa3)); // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
153 z += memcmp (x, pa4, sizeof pa4); // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
154 z += memcmp (x, pa1, sizeof (struct A *));// { dg-warning "call is the same pointer type \[^\n\r\]* as the second source; expected \[^\n\r\]* or an explicit length" }
155 z += memcmp (x, pa2, sizeof (PTA)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the second source; expected \[^\n\r\]* or an explicit length" }
156 z += memcmp (x, pa3, sizeof (PA)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the second source; expected \[^\n\r\]* or an explicit length" }
157
158 // These are correct, no warning.
159 memset (&a, 0, sizeof a);
160 memset (&a, 0, sizeof (a));
161 memset (&a, 0, sizeof (struct A));
162 memset (&a, 0, sizeof (const struct A));
163 memset (&a, 0, sizeof (volatile struct A));
164 memset (&a, 0, sizeof (volatile const struct A));
165 memset (&a, 0, sizeof (TA));
166 memset (&a, 0, sizeof (__typeof (*&a)));
167 memset (pa1, 0, sizeof (*pa1));
168 memset (pa2, 0, sizeof (*pa3));
169 memset (pa3, 0, sizeof (__typeof (*pa3)));
170 // These are probably broken, but obfuscated, no warning.
171 memset ((void *) &a, 0, sizeof (&a));
172 memset ((char *) &a, 0, sizeof (&a));
173 memset (&a, 0, sizeof (&a) + 0);
174 memset (&a, 0, 0 + sizeof (&a));
175
176 // These are correct, no warning.
177 memcpy (&a, x, sizeof a);
178 memcpy (&a, x, sizeof (a));
179 memcpy (&a, x, sizeof (struct A));
180 memcpy (&a, x, sizeof (const struct A));
181 memcpy (&a, x, sizeof (volatile struct A));
182 memcpy (&a, x, sizeof (volatile const struct A));
183 memcpy (&a, x, sizeof (TA));
184 memcpy (&a, x, sizeof (__typeof (*&a)));
185 memcpy (pa1, x, sizeof (*pa1));
186 memcpy (pa2, x, sizeof (*pa3));
187 memcpy (pa3, x, sizeof (__typeof (*pa3)));
188 // These are probably broken, but obfuscated, no warning.
189 memcpy ((void *) &a, x, sizeof (&a));
190 memcpy ((char *) &a, x, sizeof (&a));
191 memcpy (&a, x, sizeof (&a) + 0);
192 memcpy (&a, x, 0 + sizeof (&a));
193
194 // These are correct, no warning.
195 memcpy (x, &a, sizeof a);
196 memcpy (x, &a, sizeof (a));
197 memcpy (x, &a, sizeof (struct A));
198 memcpy (x, &a, sizeof (const struct A));
199 memcpy (x, &a, sizeof (volatile struct A));
200 memcpy (x, &a, sizeof (volatile const struct A));
201 memcpy (x, &a, sizeof (TA));
202 memcpy (x, &a, sizeof (__typeof (*&a)));
203 memcpy (x, pa1, sizeof (*pa1));
204 memcpy (x, pa2, sizeof (*pa3));
205 memcpy (x, pa3, sizeof (__typeof (*pa3)));
206 // These are probably broken, but obfuscated, no warning.
207 memcpy (x, (void *) &a, sizeof (&a));
208 memcpy (x, (char *) &a, sizeof (&a));
209 memcpy (x, &a, sizeof (&a) + 0);
210 memcpy (x, &a, 0 + sizeof (&a));
211
212 // These are correct, no warning.
213 memmove (&a, x, sizeof a);
214 memmove (&a, x, sizeof (a));
215 memmove (&a, x, sizeof (struct A));
216 memmove (&a, x, sizeof (const struct A));
217 memmove (&a, x, sizeof (volatile struct A));
218 memmove (&a, x, sizeof (volatile const struct A));
219 memmove (&a, x, sizeof (TA));
220 memmove (&a, x, sizeof (__typeof (*&a)));
221 memmove (pa1, x, sizeof (*pa1));
222 memmove (pa2, x, sizeof (*pa3));
223 memmove (pa3, x, sizeof (__typeof (*pa3)));
224 // These are probably broken, but obfuscated, no warning.
225 memmove ((void *) &a, x, sizeof (&a));
226 memmove ((char *) &a, x, sizeof (&a));
227 memmove (&a, x, sizeof (&a) + 0);
228 memmove (&a, x, 0 + sizeof (&a));
229
230 // These are correct, no warning.
231 memmove (x, &a, sizeof a);
232 memmove (x, &a, sizeof (a));
233 memmove (x, &a, sizeof (struct A));
234 memmove (x, &a, sizeof (const struct A));
235 memmove (x, &a, sizeof (volatile struct A));
236 memmove (x, &a, sizeof (volatile const struct A));
237 memmove (x, &a, sizeof (TA));
238 memmove (x, &a, sizeof (__typeof (*&a)));
239 memmove (x, pa1, sizeof (*pa1));
240 memmove (x, pa2, sizeof (*pa3));
241 memmove (x, pa3, sizeof (__typeof (*pa3)));
242 // These are probably broken, but obfuscated, no warning.
243 memmove (x, (void *) &a, sizeof (&a));
244 memmove (x, (char *) &a, sizeof (&a));
245 memmove (x, &a, sizeof (&a) + 0);
246 memmove (x, &a, 0 + sizeof (&a));
247
248 // These are correct, no warning.
249 z += memcmp (&a, x, sizeof a);
250 z += memcmp (&a, x, sizeof (a));
251 z += memcmp (&a, x, sizeof (struct A));
252 z += memcmp (&a, x, sizeof (const struct A));
253 z += memcmp (&a, x, sizeof (volatile struct A));
254 z += memcmp (&a, x, sizeof (volatile const struct A));
255 z += memcmp (&a, x, sizeof (TA));
256 z += memcmp (&a, x, sizeof (__typeof (*&a)));
257 z += memcmp (pa1, x, sizeof (*pa1));
258 z += memcmp (pa2, x, sizeof (*pa3));
259 z += memcmp (pa3, x, sizeof (__typeof (*pa3)));
260 // These are probably broken, but obfuscated, no warning.
261 z += memcmp ((void *) &a, x, sizeof (&a));
262 z += memcmp ((char *) &a, x, sizeof (&a));
263 z += memcmp (&a, x, sizeof (&a) + 0);
264 z += memcmp (&a, x, 0 + sizeof (&a));
265
266 // These are correct, no warning.
267 z += memcmp (x, &a, sizeof a);
268 z += memcmp (x, &a, sizeof (a));
269 z += memcmp (x, &a, sizeof (struct A));
270 z += memcmp (x, &a, sizeof (const struct A));
271 z += memcmp (x, &a, sizeof (volatile struct A));
272 z += memcmp (x, &a, sizeof (volatile const struct A));
273 z += memcmp (x, &a, sizeof (TA));
274 z += memcmp (x, &a, sizeof (__typeof (*&a)));
275 z += memcmp (x, pa1, sizeof (*pa1));
276 z += memcmp (x, pa2, sizeof (*pa3));
277 z += memcmp (x, pa3, sizeof (__typeof (*pa3)));
278 // These are probably broken, but obfuscated, no warning.
279 z += memcmp (x, (void *) &a, sizeof (&a));
280 z += memcmp (x, (char *) &a, sizeof (&a));
281 z += memcmp (x, &a, sizeof (&a) + 0);
282 z += memcmp (x, &a, 0 + sizeof (&a));
283
284 return z;
285 }
286
287 template <int N>
288 int
289 f2 (void *x, int z)
290 {
291 struct B b, *pb1 = &b;
292 TB *pb2 = &b;
293 PB pb3 = &b;
294 PTB pb4 = &b;
295 memset (&b, 0, sizeof (&b)); // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
296 memset (pb1, 0, sizeof (pb1)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
297 memset (pb2, 0, sizeof pb2); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
298 memset (pb3, 0, sizeof (pb3)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
299 memset (pb4, 0, sizeof pb4); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
300 memset (pb1, 0, sizeof (struct B *)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
301 memset (pb2, 0, sizeof (PTB)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
302 memset (pb3, 0, sizeof (PB)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
303 memset (pb4, 0, sizeof (__typeof (pb4))); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
304
305 memcpy (&b, x, sizeof (&b)); // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
306 memcpy (pb1, x, sizeof (pb1)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
307 memcpy (pb2, x, sizeof pb2); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
308 memcpy (pb3, x, sizeof (pb3)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
309 memcpy (pb4, x, sizeof pb4); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
310 memcpy (pb1, x, sizeof (struct B *)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
311 memcpy (pb2, x, sizeof (PTB)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
312 memcpy (pb3, x, sizeof (PB)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
313 memcpy (pb4, x, sizeof (__typeof (pb4))); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
314
315 memcpy (x, &b, sizeof (&b)); // { dg-warning "call is the same expression as the source; did you mean to remove the addressof" }
316 memcpy (x, pb1, sizeof (pb1)); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
317 memcpy (x, pb2, sizeof pb2); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
318 memcpy (x, pb3, sizeof (pb3)); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
319 memcpy (x, pb4, sizeof pb4); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
320 memcpy (x, pb1, sizeof (struct B *)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" }
321 memcpy (x, pb2, sizeof (PTB)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" }
322 memcpy (x, pb3, sizeof (PB)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" }
323 memcpy (x, pb4, sizeof (__typeof (pb4))); // { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" }
324
325 memmove (&b, x, sizeof (&b)); // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
326 memmove (pb1, x, sizeof (pb1)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
327 memmove (pb2, x, sizeof pb2); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
328 memmove (pb3, x, sizeof (pb3)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
329 memmove (pb4, x, sizeof pb4); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
330 memmove (pb1, x, sizeof (struct B *)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
331 memmove (pb2, x, sizeof (PTB)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
332 memmove (pb3, x, sizeof (PB)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
333 memmove (pb4, x, sizeof (__typeof (pb4)));// { dg-warning "call is the same pointer type \[^\n\r\]* as the destination; expected \[^\n\r\]* or an explicit length" }
334
335 memmove (x, &b, sizeof (&b)); // { dg-warning "call is the same expression as the source; did you mean to remove the addressof" }
336 memmove (x, pb1, sizeof (pb1)); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
337 memmove (x, pb2, sizeof pb2); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
338 memmove (x, pb3, sizeof (pb3)); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
339 memmove (x, pb4, sizeof pb4); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
340 memmove (x, pb1, sizeof (struct B *)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" }
341 memmove (x, pb2, sizeof (PTB)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" }
342 memmove (x, pb3, sizeof (PB)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" }
343 memmove (x, pb4, sizeof (__typeof (pb4)));// { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" }
344
345 z += memcmp (&b, x, sizeof (&b)); // { dg-warning "call is the same expression as the first source; did you mean to remove the addressof" }
346 z += memcmp (pb1, x, sizeof (pb1)); // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
347 z += memcmp (pb2, x, sizeof pb2); // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
348 z += memcmp (pb3, x, sizeof (pb3)); // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
349 z += memcmp (pb4, x, sizeof pb4); // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
350 z += memcmp (pb1, x, sizeof (struct B *));// { dg-warning "call is the same pointer type \[^\n\r\]* as the first source; expected \[^\n\r\]* or an explicit length" }
351 z += memcmp (pb2, x, sizeof (PTB)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the first source; expected \[^\n\r\]* or an explicit length" }
352 z += memcmp (pb3, x, sizeof (PB)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the first source; expected \[^\n\r\]* or an explicit length" }
353
354 z += memcmp (x, &b, sizeof (&b)); // { dg-warning "call is the same expression as the second source; did you mean to remove the addressof" }
355 z += memcmp (x, pb1, sizeof (pb1)); // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
356 z += memcmp (x, pb2, sizeof pb2); // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
357 z += memcmp (x, pb3, sizeof (pb3)); // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
358 z += memcmp (x, pb4, sizeof pb4); // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
359 z += memcmp (x, pb1, sizeof (struct B *));// { dg-warning "call is the same pointer type \[^\n\r\]* as the second source; expected \[^\n\r\]* or an explicit length" }
360 z += memcmp (x, pb2, sizeof (PTB)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the second source; expected \[^\n\r\]* or an explicit length" }
361 z += memcmp (x, pb3, sizeof (PB)); // { dg-warning "call is the same pointer type \[^\n\r\]* as the second source; expected \[^\n\r\]* or an explicit length" }
362
363 // These are correct, no warning.
364 memset (&b, 0, sizeof b);
365 memset (&b, 0, sizeof (b));
366 memset (&b, 0, sizeof (struct B));
367 memset (&b, 0, sizeof (const struct B));
368 memset (&b, 0, sizeof (volatile struct B));
369 memset (&b, 0, sizeof (volatile const struct B));
370 memset (&b, 0, sizeof (TB));
371 memset (&b, 0, sizeof (__typeof (*&b)));
372 memset (pb1, 0, sizeof (*pb1));
373 memset (pb2, 0, sizeof (*pb3));
374 memset (pb3, 0, sizeof (__typeof (*pb3)));
375 // These are probably broken, but obfuscated, no warning.
376 memset ((void *) &b, 0, sizeof (&b));
377 memset ((char *) &b, 0, sizeof (&b));
378 memset (&b, 0, sizeof (&b) + 0);
379 memset (&b, 0, 0 + sizeof (&b));
380
381 // These are correct, no warning.
382 memcpy (&b, x, sizeof b);
383 memcpy (&b, x, sizeof (b));
384 memcpy (&b, x, sizeof (struct B));
385 memcpy (&b, x, sizeof (const struct B));
386 memcpy (&b, x, sizeof (volatile struct B));
387 memcpy (&b, x, sizeof (volatile const struct B));
388 memcpy (&b, x, sizeof (TB));
389 memcpy (&b, x, sizeof (__typeof (*&b)));
390 memcpy (pb1, x, sizeof (*pb1));
391 memcpy (pb2, x, sizeof (*pb3));
392 memcpy (pb3, x, sizeof (__typeof (*pb3)));
393 // These are probably broken, but obfuscated, no warning.
394 memcpy ((void *) &b, x, sizeof (&b));
395 memcpy ((char *) &b, x, sizeof (&b));
396 memcpy (&b, x, sizeof (&b) + 0);
397 memcpy (&b, x, 0 + sizeof (&b));
398
399 // These are correct, no warning.
400 memcpy (x, &b, sizeof b);
401 memcpy (x, &b, sizeof (b));
402 memcpy (x, &b, sizeof (struct B));
403 memcpy (x, &b, sizeof (const struct B));
404 memcpy (x, &b, sizeof (volatile struct B));
405 memcpy (x, &b, sizeof (volatile const struct B));
406 memcpy (x, &b, sizeof (TB));
407 memcpy (x, &b, sizeof (__typeof (*&b)));
408 memcpy (x, pb1, sizeof (*pb1));
409 memcpy (x, pb2, sizeof (*pb3));
410 memcpy (x, pb3, sizeof (__typeof (*pb3)));
411 // These are probably broken, but obfuscated, no warning.
412 memcpy (x, (void *) &b, sizeof (&b));
413 memcpy (x, (char *) &b, sizeof (&b));
414 memcpy (x, &b, sizeof (&b) + 0);
415 memcpy (x, &b, 0 + sizeof (&b));
416
417 // These are correct, no warning.
418 memmove (&b, x, sizeof b);
419 memmove (&b, x, sizeof (b));
420 memmove (&b, x, sizeof (struct B));
421 memmove (&b, x, sizeof (const struct B));
422 memmove (&b, x, sizeof (volatile struct B));
423 memmove (&b, x, sizeof (volatile const struct B));
424 memmove (&b, x, sizeof (TB));
425 memmove (&b, x, sizeof (__typeof (*&b)));
426 memmove (pb1, x, sizeof (*pb1));
427 memmove (pb2, x, sizeof (*pb3));
428 memmove (pb3, x, sizeof (__typeof (*pb3)));
429 // These are probably broken, but obfuscated, no warning.
430 memmove ((void *) &b, x, sizeof (&b));
431 memmove ((char *) &b, x, sizeof (&b));
432 memmove (&b, x, sizeof (&b) + 0);
433 memmove (&b, x, 0 + sizeof (&b));
434
435 // These are correct, no warning.
436 memmove (x, &b, sizeof b);
437 memmove (x, &b, sizeof (b));
438 memmove (x, &b, sizeof (struct B));
439 memmove (x, &b, sizeof (const struct B));
440 memmove (x, &b, sizeof (volatile struct B));
441 memmove (x, &b, sizeof (volatile const struct B));
442 memmove (x, &b, sizeof (TB));
443 memmove (x, &b, sizeof (__typeof (*&b)));
444 memmove (x, pb1, sizeof (*pb1));
445 memmove (x, pb2, sizeof (*pb3));
446 memmove (x, pb3, sizeof (__typeof (*pb3)));
447 // These are probably broken, but obfuscated, no warning.
448 memmove (x, (void *) &b, sizeof (&b));
449 memmove (x, (char *) &b, sizeof (&b));
450 memmove (x, &b, sizeof (&b) + 0);
451 memmove (x, &b, 0 + sizeof (&b));
452
453 // These are correct, no warning.
454 z += memcmp (&b, x, sizeof b);
455 z += memcmp (&b, x, sizeof (b));
456 z += memcmp (&b, x, sizeof (struct B));
457 z += memcmp (&b, x, sizeof (const struct B));
458 z += memcmp (&b, x, sizeof (volatile struct B));
459 z += memcmp (&b, x, sizeof (volatile const struct B));
460 z += memcmp (&b, x, sizeof (TB));
461 z += memcmp (&b, x, sizeof (__typeof (*&b)));
462 z += memcmp (pb1, x, sizeof (*pb1));
463 z += memcmp (pb2, x, sizeof (*pb3));
464 z += memcmp (pb3, x, sizeof (__typeof (*pb3)));
465 // These are probably broken, but obfuscated, no warning.
466 z += memcmp ((void *) &b, x, sizeof (&b));
467 z += memcmp ((char *) &b, x, sizeof (&b));
468 z += memcmp (&b, x, sizeof (&b) + 0);
469 z += memcmp (&b, x, 0 + sizeof (&b));
470
471 // These are correct, no warning.
472 z += memcmp (x, &b, sizeof b);
473 z += memcmp (x, &b, sizeof (b));
474 z += memcmp (x, &b, sizeof (struct B));
475 z += memcmp (x, &b, sizeof (const struct B));
476 z += memcmp (x, &b, sizeof (volatile struct B));
477 z += memcmp (x, &b, sizeof (volatile const struct B));
478 z += memcmp (x, &b, sizeof (TB));
479 z += memcmp (x, &b, sizeof (__typeof (*&b)));
480 z += memcmp (x, pb1, sizeof (*pb1));
481 z += memcmp (x, pb2, sizeof (*pb3));
482 z += memcmp (x, pb3, sizeof (__typeof (*pb3)));
483 // These are probably broken, but obfuscated, no warning.
484 z += memcmp (x, (void *) &b, sizeof (&b));
485 z += memcmp (x, (char *) &b, sizeof (&b));
486 z += memcmp (x, &b, sizeof (&b) + 0);
487 z += memcmp (x, &b, 0 + sizeof (&b));
488
489 return z;
490 }
491
492 template <int N>
493 int
494 f3 (void *x, char *y, int z, X w)
495 {
496 unsigned char *y1 = (unsigned char *) __builtin_alloca (z + 16);
497 char buf1[7];
498 signed char buf2[z + 32];
499 long buf3[17];
500 int *buf4[9];
501 signed char *y2 = buf2;
502 char c;
503 char *y3;
504 memset (y, 0, sizeof (y)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
505 memset (y1, 0, sizeof (y1)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
506 memset (y2, 0, sizeof (y2)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
507 memset (&c, 0, sizeof (&c)); // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
508 memset (w, 0, sizeof w); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
509
510 memcpy (y, x, sizeof (y)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
511 memcpy (y1, x, sizeof (y1)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
512 memcpy (y2, x, sizeof (y2)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
513 memcpy (&c, x, sizeof (&c)); // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
514 memcpy (w, x, sizeof w); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
515
516 memcpy (x, y, sizeof (y)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
517 memcpy (x, y1, sizeof (y1)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
518 memcpy (x, y2, sizeof (y2)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
519 memcpy (x, &c, sizeof (&c)); // { dg-warning "call is the same expression as the source; did you mean to remove the addressof" }
520 memcpy (x, w, sizeof w); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
521
522 memmove (y, x, sizeof (y)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
523 memmove (y1, x, sizeof (y1)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
524 memmove (y2, x, sizeof (y2)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
525 memmove (&c, x, sizeof (&c)); // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
526 memmove (w, x, sizeof w); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
527
528 memmove (x, y, sizeof (y)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
529 memmove (x, y1, sizeof (y1)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
530 memmove (x, y2, sizeof (y2)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
531 memmove (x, &c, sizeof (&c)); // { dg-warning "call is the same expression as the source; did you mean to remove the addressof" }
532 memmove (x, w, sizeof w); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
533
534 z += memcmp (y, x, sizeof (y)); // { dg-warning "call is the same expression as the first source; did you mean to provide an explicit length" }
535 z += memcmp (y1, x, sizeof (y1)); // { dg-warning "call is the same expression as the first source; did you mean to provide an explicit length" }
536 z += memcmp (y2, x, sizeof (y2)); // { dg-warning "call is the same expression as the first source; did you mean to provide an explicit length" }
537 z += memcmp (&c, x, sizeof (&c)); // { dg-warning "call is the same expression as the first source; did you mean to remove the addressof" }
538 z += memcmp (w, x, sizeof w); // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
539
540 z += memcmp (x, y, sizeof (y)); // { dg-warning "call is the same expression as the second source; did you mean to provide an explicit length" }
541 z += memcmp (x, y1, sizeof (y1)); // { dg-warning "call is the same expression as the second source; did you mean to provide an explicit length" }
542 z += memcmp (x, y2, sizeof (y2)); // { dg-warning "call is the same expression as the second source; did you mean to provide an explicit length" }
543 z += memcmp (x, &c, sizeof (&c)); // { dg-warning "call is the same expression as the second source; did you mean to remove the addressof" }
544 z += memcmp (x, w, sizeof w); // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
545
546 // These are correct, no warning.
547 memset (y, 0, sizeof (*y));
548 memset (y1, 0, sizeof (*y2));
549 memset (buf1, 0, sizeof buf1);
550 memset (buf3, 0, sizeof (buf3));
551 memset (&buf3[0], 0, sizeof (buf3));
552 memset (&buf4[0], 0, sizeof (buf4));
553 memset (w, 0, sizeof (X));
554 // These are probably broken, but obfuscated, no warning.
555 memset ((void *) y, 0, sizeof (y));
556 memset ((char *) y1, 0, sizeof (y2));
557 memset (y, 0, sizeof (y) + 0);
558 memset (y1, 0, 0 + sizeof (y2));
559 memset ((void *) &c, 0, sizeof (&c));
560 memset ((signed char *) &c, 0, sizeof (&c));
561 memset (&c, 0, sizeof (&c) + 0);
562 memset (&c, 0, 0 + sizeof (&c));
563
564 // These are correct, no warning.
565 memcpy (y, x, sizeof (*y));
566 memcpy (y1, x, sizeof (*y2));
567 memcpy (buf1, x, sizeof buf1);
568 memcpy (buf3, x, sizeof (buf3));
569 memcpy (&buf3[0], x, sizeof (buf3));
570 memcpy (&buf4[0], x, sizeof (buf4));
571 memcpy (&y3, y, sizeof (y3));
572 memcpy ((char *) &y3, y, sizeof (y3));
573 memcpy (w, x, sizeof (X));
574 // These are probably broken, but obfuscated, no warning.
575 memcpy ((void *) y, x, sizeof (y));
576 memcpy ((char *) y1, x, sizeof (y2));
577 memcpy (y, x, sizeof (y) + 0);
578 memcpy (y1, x, 0 + sizeof (y2));
579 memcpy ((void *) &c, x, sizeof (&c));
580 memcpy ((signed char *) &c, x, sizeof (&c));
581 memcpy (&c, x, sizeof (&c) + 0);
582 memcpy (&c, x, 0 + sizeof (&c));
583
584 // These are correct, no warning.
585 memcpy (x, y, sizeof (*y));
586 memcpy (x, y1, sizeof (*y2));
587 memcpy (x, buf1, sizeof buf1);
588 memcpy (x, buf3, sizeof (buf3));
589 memcpy (x, &buf3[0], sizeof (buf3));
590 memcpy (x, &buf4[0], sizeof (buf4));
591 memcpy (y, &y3, sizeof (y3));
592 memcpy (y, (char *) &y3, sizeof (y3));
593 memcpy (x, w, sizeof (X));
594 // These are probably broken, but obfuscated, no warning.
595 memcpy (x, (void *) y, sizeof (y));
596 memcpy (x, (char *) y1, sizeof (y2));
597 memcpy (x, y, sizeof (y) + 0);
598 memcpy (x, y1, 0 + sizeof (y2));
599 memcpy (x, (void *) &c, sizeof (&c));
600 memcpy (x, (signed char *) &c, sizeof (&c));
601 memcpy (x, &c, sizeof (&c) + 0);
602 memcpy (x, &c, 0 + sizeof (&c));
603
604 // These are correct, no warning.
605 memmove (y, x, sizeof (*y));
606 memmove (y1, x, sizeof (*y2));
607 memmove (buf1, x, sizeof buf1);
608 memmove (buf3, x, sizeof (buf3));
609 memmove (&buf3[0], x, sizeof (buf3));
610 memmove (&buf4[0], x, sizeof (buf4));
611 memmove (&y3, y, sizeof (y3));
612 memmove ((char *) &y3, y, sizeof (y3));
613 memmove (w, x, sizeof (X));
614 // These are probably broken, but obfuscated, no warning.
615 memmove ((void *) y, x, sizeof (y));
616 memmove ((char *) y1, x, sizeof (y2));
617 memmove (y, x, sizeof (y) + 0);
618 memmove (y1, x, 0 + sizeof (y2));
619 memmove ((void *) &c, x, sizeof (&c));
620 memmove ((signed char *) &c, x, sizeof (&c));
621 memmove (&c, x, sizeof (&c) + 0);
622 memmove (&c, x, 0 + sizeof (&c));
623
624 // These are correct, no warning.
625 memmove (x, y, sizeof (*y));
626 memmove (x, y1, sizeof (*y2));
627 memmove (x, buf1, sizeof buf1);
628 memmove (x, buf3, sizeof (buf3));
629 memmove (x, &buf3[0], sizeof (buf3));
630 memmove (x, &buf4[0], sizeof (buf4));
631 memmove (y, &y3, sizeof (y3));
632 memmove (y, (char *) &y3, sizeof (y3));
633 memmove (x, w, sizeof (X));
634 // These are probably broken, but obfuscated, no warning.
635 memmove (x, (void *) y, sizeof (y));
636 memmove (x, (char *) y1, sizeof (y2));
637 memmove (x, y, sizeof (y) + 0);
638 memmove (x, y1, 0 + sizeof (y2));
639 memmove (x, (void *) &c, sizeof (&c));
640 memmove (x, (signed char *) &c, sizeof (&c));
641 memmove (x, &c, sizeof (&c) + 0);
642 memmove (x, &c, 0 + sizeof (&c));
643
644 // These are correct, no warning.
645 z += memcmp (y, x, sizeof (*y));
646 z += memcmp (y1, x, sizeof (*y2));
647 z += memcmp (buf1, x, sizeof buf1);
648 z += memcmp (buf3, x, sizeof (buf3));
649 z += memcmp (&buf3[0], x, sizeof (buf3));
650 z += memcmp (&buf4[0], x, sizeof (buf4));
651 z += memcmp (&y3, y, sizeof (y3));
652 z += memcmp ((char *) &y3, y, sizeof (y3));
653 z += memcmp (w, x, sizeof (X));
654 // These are probably broken, but obfuscated, no warning.
655 z += memcmp ((void *) y, x, sizeof (y));
656 z += memcmp ((char *) y1, x, sizeof (y2));
657 z += memcmp (y, x, sizeof (y) + 0);
658 z += memcmp (y1, x, 0 + sizeof (y2));
659 z += memcmp ((void *) &c, x, sizeof (&c));
660 z += memcmp ((signed char *) &c, x, sizeof (&c));
661 z += memcmp (&c, x, sizeof (&c) + 0);
662 z += memcmp (&c, x, 0 + sizeof (&c));
663
664 // These are correct, no warning.
665 z += memcmp (x, y, sizeof (*y));
666 z += memcmp (x, y1, sizeof (*y2));
667 z += memcmp (x, buf1, sizeof buf1);
668 z += memcmp (x, buf3, sizeof (buf3));
669 z += memcmp (x, &buf3[0], sizeof (buf3));
670 z += memcmp (x, &buf4[0], sizeof (buf4));
671 z += memcmp (y, &y3, sizeof (y3));
672 z += memcmp (y, (char *) &y3, sizeof (y3));
673 z += memcmp (x, w, sizeof (X));
674 // These are probably broken, but obfuscated, no warning.
675 z += memcmp (x, (void *) y, sizeof (y));
676 z += memcmp (x, (char *) y1, sizeof (y2));
677 z += memcmp (x, y, sizeof (y) + 0);
678 z += memcmp (x, y1, 0 + sizeof (y2));
679 z += memcmp (x, (void *) &c, sizeof (&c));
680 z += memcmp (x, (signed char *) &c, sizeof (&c));
681 z += memcmp (x, &c, sizeof (&c) + 0);
682 z += memcmp (x, &c, 0 + sizeof (&c));
683
684 return z;
685 }
686
687 template <int N>
688 int
689 f4 (char *x, char **y, int z, char w[64])
690 {
691 const char *s1 = "foobarbaz";
692 const char *s2 = "abcde12345678";
693 strncpy (x, s1, sizeof (s1)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
694 strncat (x, s2, sizeof (s2)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
695 stpncpy (x, s1, sizeof (s1)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
696 y[0] = strndup (s1, sizeof (s1)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
697 z += strncmp (s1, s2, sizeof (s1)); // { dg-warning "call is the same expression as the first source; did you mean to provide an explicit length" }
698 z += strncmp (s1, s2, sizeof (s2)); // { dg-warning "call is the same expression as the second source; did you mean to provide an explicit length" }
699 z += strncasecmp (s1, s2, sizeof (s1)); // { dg-warning "call is the same expression as the first source; did you mean to provide an explicit length" }
700 z += strncasecmp (s1, s2, sizeof (s2)); // { dg-warning "call is the same expression as the second source; did you mean to provide an explicit length" }
701
702 strncpy (w, s1, sizeof (w)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
703 strncat (w, s2, sizeof (w)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
704 stpncpy (w, s1, sizeof (w)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
705
706 const char s3[] = "foobarbaz";
707 const char s4[] = "abcde12345678";
708 strncpy (x, s3, sizeof (s3)); // { dg-warning "call is the same expression as the source; did you mean to use the size of the destination" }
709 strncat (x, s4, sizeof (s4)); // { dg-warning "call is the same expression as the source; did you mean to use the size of the destination" }
710 stpncpy (x, s3, sizeof (s3)); // { dg-warning "call is the same expression as the source; did you mean to use the size of the destination" }
711
712 // These are safe, no warning.
713 y[1] = strndup (s3, sizeof (s3));
714 z += strncmp (s3, s4, sizeof (s3));
715 z += strncmp (s3, s4, sizeof (s4));
716 z += strncasecmp (s3, s4, sizeof (s3));
717 z += strncasecmp (s3, s4, sizeof (s4));
718
719 return z;
720 }
721
722 int
723 f (void *x, char *y, int z, X w, char **u, char v[64])
724 {
725 z += f1<0> (x, z);
726 z += f2<0> (x, z);
727 z += f3<0> (x, y, z, w);
728 z += f4<0> (y, u, z, v);
729 return z;
730 }
731
732 // { dg-prune-output "\[\n\r\]*will always overflow\[\n\r\]*" }