1 // Test -Wsizeof-pointer-memaccess warnings.
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 // { dg-skip-if "" { *-*-* } { "*" } { "-O0" "-O2" } }
6 // { dg-skip-if "" { *-*-* } { "-flto" } { "" } }
7 // { dg-require-effective-target alloca }
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);
24 # define bos(ptr) __builtin_object_size (ptr, 1)
25 # define bos0(ptr) __builtin_object_size (ptr, 0)
27 __attribute__((__always_inline__, __gnu_inline__, __artificial__))
29 memset (void *dest, int c, size_t len)
31 return __builtin___memset_chk (dest, c, len, bos0 (dest));
34 __attribute__((__always_inline__, __gnu_inline__, __artificial__))
36 memcpy (void *__restrict dest, const void *__restrict src, size_t len)
38 return __builtin___memcpy_chk (dest, src, len, bos0 (dest));
41 __attribute__((__always_inline__, __gnu_inline__, __artificial__))
43 memmove (void *dest, const void *src, size_t len)
45 return __builtin___memmove_chk (dest, src, len, bos0 (dest));
48 __attribute__((__always_inline__, __gnu_inline__, __artificial__))
50 strncpy (char *__restrict dest, const char *__restrict src, size_t len)
52 return __builtin___strncpy_chk (dest, src, len, bos (dest));
55 __attribute__((__always_inline__, __gnu_inline__, __artificial__))
57 strncat (char *dest, const char *src, size_t len)
59 return __builtin___strncat_chk (dest, src, len, bos (dest));
62 __attribute__((__always_inline__, __gnu_inline__, __artificial__))
64 stpncpy (char *__restrict dest, const char *__restrict src, size_t len)
66 return __builtin___stpncpy_chk (dest, src, len, bos (dest));
72 struct A { short a, b; int c, d; long e, f; };
80 typedef int X[3][3][3];
85 struct A a, *pa1 = &a;
89 memset (&a, 0, sizeof (&a)); // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
90 memset (pa1, 0, sizeof (pa1)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
91 memset (pa2, 0, sizeof pa2); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
92 memset (pa3, 0, sizeof (pa3)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
93 memset (pa4, 0, sizeof pa4); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
94 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" }
95 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" }
96 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" }
97 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 memcpy (&a, x, sizeof (&a)); // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
100 memcpy (pa1, x, sizeof (pa1)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
101 memcpy (pa2, x, sizeof pa2); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
102 memcpy (pa3, x, sizeof (pa3)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
103 memcpy (pa4, x, sizeof pa4); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
104 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" }
105 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" }
106 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" }
107 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 memcpy (x, &a, sizeof (&a)); // { dg-warning "call is the same expression as the source; did you mean to remove the addressof" }
110 memcpy (x, pa1, sizeof (pa1)); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
111 memcpy (x, pa2, sizeof pa2); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
112 memcpy (x, pa3, sizeof (pa3)); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
113 memcpy (x, pa4, sizeof pa4); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
114 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" }
115 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" }
116 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" }
117 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 memmove (&a, x, sizeof (&a)); // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
120 memmove (pa1, x, sizeof (pa1)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
121 memmove (pa2, x, sizeof pa2); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
122 memmove (pa3, x, sizeof (pa3)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
123 memmove (pa4, x, sizeof pa4); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
124 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" }
125 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" }
126 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" }
127 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 memmove (x, &a, sizeof (&a)); // { dg-warning "call is the same expression as the source; did you mean to remove the addressof" }
130 memmove (x, pa1, sizeof (pa1)); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
131 memmove (x, pa2, sizeof pa2); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
132 memmove (x, pa3, sizeof (pa3)); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
133 memmove (x, pa4, sizeof pa4); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
134 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" }
135 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" }
136 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" }
137 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 z += memcmp (&a, x, sizeof (&a)); // { dg-warning "call is the same expression as the first source; did you mean to remove the addressof" }
140 z += memcmp (pa1, x, sizeof (pa1)); // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
141 z += memcmp (pa2, x, sizeof pa2); // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
142 z += memcmp (pa3, x, sizeof (pa3)); // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
143 z += memcmp (pa4, x, sizeof pa4); // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
144 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" }
145 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" }
146 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 z += memcmp (x, &a, sizeof (&a)); // { dg-warning "call is the same expression as the second source; did you mean to remove the addressof" }
149 z += memcmp (x, pa1, sizeof (pa1)); // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
150 z += memcmp (x, pa2, sizeof pa2); // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
151 z += memcmp (x, pa3, sizeof (pa3)); // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
152 z += memcmp (x, pa4, sizeof pa4); // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
153 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" }
154 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" }
155 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 // These are correct, no warning.
158 memset (&a, 0, sizeof a);
159 memset (&a, 0, sizeof (a));
160 memset (&a, 0, sizeof (struct A));
161 memset (&a, 0, sizeof (const struct A));
162 memset (&a, 0, sizeof (volatile struct A));
163 memset (&a, 0, sizeof (volatile const struct A));
164 memset (&a, 0, sizeof (TA));
165 memset (&a, 0, sizeof (__typeof (*&a)));
166 memset (pa1, 0, sizeof (*pa1));
167 memset (pa2, 0, sizeof (*pa3));
168 memset (pa3, 0, sizeof (__typeof (*pa3)));
169 // These are probably broken, but obfuscated, no warning.
170 memset ((void *) &a, 0, sizeof (&a));
171 memset ((char *) &a, 0, sizeof (&a));
172 memset (&a, 0, sizeof (&a) + 0);
173 memset (&a, 0, 0 + sizeof (&a));
175 // These are correct, no warning.
176 memcpy (&a, x, sizeof a);
177 memcpy (&a, x, sizeof (a));
178 memcpy (&a, x, sizeof (struct A));
179 memcpy (&a, x, sizeof (const struct A));
180 memcpy (&a, x, sizeof (volatile struct A));
181 memcpy (&a, x, sizeof (volatile const struct A));
182 memcpy (&a, x, sizeof (TA));
183 memcpy (&a, x, sizeof (__typeof (*&a)));
184 memcpy (pa1, x, sizeof (*pa1));
185 memcpy (pa2, x, sizeof (*pa3));
186 memcpy (pa3, x, sizeof (__typeof (*pa3)));
187 // These are probably broken, but obfuscated, no warning.
188 memcpy ((void *) &a, x, sizeof (&a));
189 memcpy ((char *) &a, x, sizeof (&a));
190 memcpy (&a, x, sizeof (&a) + 0);
191 memcpy (&a, x, 0 + sizeof (&a));
193 // These are correct, no warning.
194 memcpy (x, &a, sizeof a);
195 memcpy (x, &a, sizeof (a));
196 memcpy (x, &a, sizeof (struct A));
197 memcpy (x, &a, sizeof (const struct A));
198 memcpy (x, &a, sizeof (volatile struct A));
199 memcpy (x, &a, sizeof (volatile const struct A));
200 memcpy (x, &a, sizeof (TA));
201 memcpy (x, &a, sizeof (__typeof (*&a)));
202 memcpy (x, pa1, sizeof (*pa1));
203 memcpy (x, pa2, sizeof (*pa3));
204 memcpy (x, pa3, sizeof (__typeof (*pa3)));
205 // These are probably broken, but obfuscated, no warning.
206 memcpy (x, (void *) &a, sizeof (&a));
207 memcpy (x, (char *) &a, sizeof (&a));
208 memcpy (x, &a, sizeof (&a) + 0);
209 memcpy (x, &a, 0 + sizeof (&a));
211 // These are correct, no warning.
212 memmove (&a, x, sizeof a);
213 memmove (&a, x, sizeof (a));
214 memmove (&a, x, sizeof (struct A));
215 memmove (&a, x, sizeof (const struct A));
216 memmove (&a, x, sizeof (volatile struct A));
217 memmove (&a, x, sizeof (volatile const struct A));
218 memmove (&a, x, sizeof (TA));
219 memmove (&a, x, sizeof (__typeof (*&a)));
220 memmove (pa1, x, sizeof (*pa1));
221 memmove (pa2, x, sizeof (*pa3));
222 memmove (pa3, x, sizeof (__typeof (*pa3)));
223 // These are probably broken, but obfuscated, no warning.
224 memmove ((void *) &a, x, sizeof (&a));
225 memmove ((char *) &a, x, sizeof (&a));
226 memmove (&a, x, sizeof (&a) + 0);
227 memmove (&a, x, 0 + sizeof (&a));
229 // These are correct, no warning.
230 memmove (x, &a, sizeof a);
231 memmove (x, &a, sizeof (a));
232 memmove (x, &a, sizeof (struct A));
233 memmove (x, &a, sizeof (const struct A));
234 memmove (x, &a, sizeof (volatile struct A));
235 memmove (x, &a, sizeof (volatile const struct A));
236 memmove (x, &a, sizeof (TA));
237 memmove (x, &a, sizeof (__typeof (*&a)));
238 memmove (x, pa1, sizeof (*pa1));
239 memmove (x, pa2, sizeof (*pa3));
240 memmove (x, pa3, sizeof (__typeof (*pa3)));
241 // These are probably broken, but obfuscated, no warning.
242 memmove (x, (void *) &a, sizeof (&a));
243 memmove (x, (char *) &a, sizeof (&a));
244 memmove (x, &a, sizeof (&a) + 0);
245 memmove (x, &a, 0 + sizeof (&a));
247 // These are correct, no warning.
248 z += memcmp (&a, x, sizeof a);
249 z += memcmp (&a, x, sizeof (a));
250 z += memcmp (&a, x, sizeof (struct A));
251 z += memcmp (&a, x, sizeof (const struct A));
252 z += memcmp (&a, x, sizeof (volatile struct A));
253 z += memcmp (&a, x, sizeof (volatile const struct A));
254 z += memcmp (&a, x, sizeof (TA));
255 z += memcmp (&a, x, sizeof (__typeof (*&a)));
256 z += memcmp (pa1, x, sizeof (*pa1));
257 z += memcmp (pa2, x, sizeof (*pa3));
258 z += memcmp (pa3, x, sizeof (__typeof (*pa3)));
259 // These are probably broken, but obfuscated, no warning.
260 z += memcmp ((void *) &a, x, sizeof (&a));
261 z += memcmp ((char *) &a, x, sizeof (&a));
262 z += memcmp (&a, x, sizeof (&a) + 0);
263 z += memcmp (&a, x, 0 + sizeof (&a));
265 // These are correct, no warning.
266 z += memcmp (x, &a, sizeof a);
267 z += memcmp (x, &a, sizeof (a));
268 z += memcmp (x, &a, sizeof (struct A));
269 z += memcmp (x, &a, sizeof (const struct A));
270 z += memcmp (x, &a, sizeof (volatile struct A));
271 z += memcmp (x, &a, sizeof (volatile const struct A));
272 z += memcmp (x, &a, sizeof (TA));
273 z += memcmp (x, &a, sizeof (__typeof (*&a)));
274 z += memcmp (x, pa1, sizeof (*pa1));
275 z += memcmp (x, pa2, sizeof (*pa3));
276 z += memcmp (x, pa3, sizeof (__typeof (*pa3)));
277 // These are probably broken, but obfuscated, no warning.
278 z += memcmp (x, (void *) &a, sizeof (&a));
279 z += memcmp (x, (char *) &a, sizeof (&a));
280 z += memcmp (x, &a, sizeof (&a) + 0);
281 z += memcmp (x, &a, 0 + sizeof (&a));
289 struct B b, *pb1 = &b;
293 memset (&b, 0, sizeof (&b)); // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
294 memset (pb1, 0, sizeof (pb1)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
295 memset (pb2, 0, sizeof pb2); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
296 memset (pb3, 0, sizeof (pb3)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
297 memset (pb4, 0, sizeof pb4); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
298 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" }
299 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" }
300 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" }
301 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" }
303 memcpy (&b, x, sizeof (&b)); // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
304 memcpy (pb1, x, sizeof (pb1)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
305 memcpy (pb2, x, sizeof pb2); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
306 memcpy (pb3, x, sizeof (pb3)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
307 memcpy (pb4, x, sizeof pb4); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
308 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" }
309 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" }
310 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" }
311 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" }
313 memcpy (x, &b, sizeof (&b)); // { dg-warning "call is the same expression as the source; did you mean to remove the addressof" }
314 memcpy (x, pb1, sizeof (pb1)); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
315 memcpy (x, pb2, sizeof pb2); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
316 memcpy (x, pb3, sizeof (pb3)); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
317 memcpy (x, pb4, sizeof pb4); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
318 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" }
319 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" }
320 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" }
321 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" }
323 memmove (&b, x, sizeof (&b)); // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
324 memmove (pb1, x, sizeof (pb1)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
325 memmove (pb2, x, sizeof pb2); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
326 memmove (pb3, x, sizeof (pb3)); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
327 memmove (pb4, x, sizeof pb4); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
328 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" }
329 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" }
330 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" }
331 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" }
333 memmove (x, &b, sizeof (&b)); // { dg-warning "call is the same expression as the source; did you mean to remove the addressof" }
334 memmove (x, pb1, sizeof (pb1)); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
335 memmove (x, pb2, sizeof pb2); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
336 memmove (x, pb3, sizeof (pb3)); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
337 memmove (x, pb4, sizeof pb4); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
338 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" }
339 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" }
340 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" }
341 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" }
343 z += memcmp (&b, x, sizeof (&b)); // { dg-warning "call is the same expression as the first source; did you mean to remove the addressof" }
344 z += memcmp (pb1, x, sizeof (pb1)); // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
345 z += memcmp (pb2, x, sizeof pb2); // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
346 z += memcmp (pb3, x, sizeof (pb3)); // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
347 z += memcmp (pb4, x, sizeof pb4); // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
348 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" }
349 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" }
350 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" }
352 z += memcmp (x, &b, sizeof (&b)); // { dg-warning "call is the same expression as the second source; did you mean to remove the addressof" }
353 z += memcmp (x, pb1, sizeof (pb1)); // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
354 z += memcmp (x, pb2, sizeof pb2); // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
355 z += memcmp (x, pb3, sizeof (pb3)); // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
356 z += memcmp (x, pb4, sizeof pb4); // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
357 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" }
358 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" }
359 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" }
361 // These are correct, no warning.
362 memset (&b, 0, sizeof b);
363 memset (&b, 0, sizeof (b));
364 memset (&b, 0, sizeof (struct B));
365 memset (&b, 0, sizeof (const struct B));
366 memset (&b, 0, sizeof (volatile struct B));
367 memset (&b, 0, sizeof (volatile const struct B));
368 memset (&b, 0, sizeof (TB));
369 memset (&b, 0, sizeof (__typeof (*&b)));
370 memset (pb1, 0, sizeof (*pb1));
371 memset (pb2, 0, sizeof (*pb3));
372 memset (pb3, 0, sizeof (__typeof (*pb3)));
373 // These are probably broken, but obfuscated, no warning.
374 memset ((void *) &b, 0, sizeof (&b));
375 memset ((char *) &b, 0, sizeof (&b));
376 memset (&b, 0, sizeof (&b) + 0);
377 memset (&b, 0, 0 + sizeof (&b));
379 // These are correct, no warning.
380 memcpy (&b, x, sizeof b);
381 memcpy (&b, x, sizeof (b));
382 memcpy (&b, x, sizeof (struct B));
383 memcpy (&b, x, sizeof (const struct B));
384 memcpy (&b, x, sizeof (volatile struct B));
385 memcpy (&b, x, sizeof (volatile const struct B));
386 memcpy (&b, x, sizeof (TB));
387 memcpy (&b, x, sizeof (__typeof (*&b)));
388 memcpy (pb1, x, sizeof (*pb1));
389 memcpy (pb2, x, sizeof (*pb3));
390 memcpy (pb3, x, sizeof (__typeof (*pb3)));
391 // These are probably broken, but obfuscated, no warning.
392 memcpy ((void *) &b, x, sizeof (&b));
393 memcpy ((char *) &b, x, sizeof (&b));
394 memcpy (&b, x, sizeof (&b) + 0);
395 memcpy (&b, x, 0 + sizeof (&b));
397 // These are correct, no warning.
398 memcpy (x, &b, sizeof b);
399 memcpy (x, &b, sizeof (b));
400 memcpy (x, &b, sizeof (struct B));
401 memcpy (x, &b, sizeof (const struct B));
402 memcpy (x, &b, sizeof (volatile struct B));
403 memcpy (x, &b, sizeof (volatile const struct B));
404 memcpy (x, &b, sizeof (TB));
405 memcpy (x, &b, sizeof (__typeof (*&b)));
406 memcpy (x, pb1, sizeof (*pb1));
407 memcpy (x, pb2, sizeof (*pb3));
408 memcpy (x, pb3, sizeof (__typeof (*pb3)));
409 // These are probably broken, but obfuscated, no warning.
410 memcpy (x, (void *) &b, sizeof (&b));
411 memcpy (x, (char *) &b, sizeof (&b));
412 memcpy (x, &b, sizeof (&b) + 0);
413 memcpy (x, &b, 0 + sizeof (&b));
415 // These are correct, no warning.
416 memmove (&b, x, sizeof b);
417 memmove (&b, x, sizeof (b));
418 memmove (&b, x, sizeof (struct B));
419 memmove (&b, x, sizeof (const struct B));
420 memmove (&b, x, sizeof (volatile struct B));
421 memmove (&b, x, sizeof (volatile const struct B));
422 memmove (&b, x, sizeof (TB));
423 memmove (&b, x, sizeof (__typeof (*&b)));
424 memmove (pb1, x, sizeof (*pb1));
425 memmove (pb2, x, sizeof (*pb3));
426 memmove (pb3, x, sizeof (__typeof (*pb3)));
427 // These are probably broken, but obfuscated, no warning.
428 memmove ((void *) &b, x, sizeof (&b));
429 memmove ((char *) &b, x, sizeof (&b));
430 memmove (&b, x, sizeof (&b) + 0);
431 memmove (&b, x, 0 + sizeof (&b));
433 // These are correct, no warning.
434 memmove (x, &b, sizeof b);
435 memmove (x, &b, sizeof (b));
436 memmove (x, &b, sizeof (struct B));
437 memmove (x, &b, sizeof (const struct B));
438 memmove (x, &b, sizeof (volatile struct B));
439 memmove (x, &b, sizeof (volatile const struct B));
440 memmove (x, &b, sizeof (TB));
441 memmove (x, &b, sizeof (__typeof (*&b)));
442 memmove (x, pb1, sizeof (*pb1));
443 memmove (x, pb2, sizeof (*pb3));
444 memmove (x, pb3, sizeof (__typeof (*pb3)));
445 // These are probably broken, but obfuscated, no warning.
446 memmove (x, (void *) &b, sizeof (&b));
447 memmove (x, (char *) &b, sizeof (&b));
448 memmove (x, &b, sizeof (&b) + 0);
449 memmove (x, &b, 0 + sizeof (&b));
451 // These are correct, no warning.
452 z += memcmp (&b, x, sizeof b);
453 z += memcmp (&b, x, sizeof (b));
454 z += memcmp (&b, x, sizeof (struct B));
455 z += memcmp (&b, x, sizeof (const struct B));
456 z += memcmp (&b, x, sizeof (volatile struct B));
457 z += memcmp (&b, x, sizeof (volatile const struct B));
458 z += memcmp (&b, x, sizeof (TB));
459 z += memcmp (&b, x, sizeof (__typeof (*&b)));
460 z += memcmp (pb1, x, sizeof (*pb1));
461 z += memcmp (pb2, x, sizeof (*pb3));
462 z += memcmp (pb3, x, sizeof (__typeof (*pb3)));
463 // These are probably broken, but obfuscated, no warning.
464 z += memcmp ((void *) &b, x, sizeof (&b));
465 z += memcmp ((char *) &b, x, sizeof (&b));
466 z += memcmp (&b, x, sizeof (&b) + 0);
467 z += memcmp (&b, x, 0 + sizeof (&b));
469 // These are correct, no warning.
470 z += memcmp (x, &b, sizeof b);
471 z += memcmp (x, &b, sizeof (b));
472 z += memcmp (x, &b, sizeof (struct B));
473 z += memcmp (x, &b, sizeof (const struct B));
474 z += memcmp (x, &b, sizeof (volatile struct B));
475 z += memcmp (x, &b, sizeof (volatile const struct B));
476 z += memcmp (x, &b, sizeof (TB));
477 z += memcmp (x, &b, sizeof (__typeof (*&b)));
478 z += memcmp (x, pb1, sizeof (*pb1));
479 z += memcmp (x, pb2, sizeof (*pb3));
480 z += memcmp (x, pb3, sizeof (__typeof (*pb3)));
481 // These are probably broken, but obfuscated, no warning.
482 z += memcmp (x, (void *) &b, sizeof (&b));
483 z += memcmp (x, (char *) &b, sizeof (&b));
484 z += memcmp (x, &b, sizeof (&b) + 0);
485 z += memcmp (x, &b, 0 + sizeof (&b));
491 f3 (void *x, char *y, int z, X w)
493 unsigned char *y1 = (unsigned char *) __builtin_alloca (z + 16);
495 signed char buf2[z + 32];
498 signed char *y2 = buf2;
501 memset (y, 0, sizeof (y)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
502 memset (y1, 0, sizeof (y1)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
503 memset (y2, 0, sizeof (y2)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
504 memset (&c, 0, sizeof (&c)); // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
505 memset (w, 0, sizeof w); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
507 memcpy (y, x, sizeof (y)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
508 memcpy (y1, x, sizeof (y1)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
509 memcpy (y2, x, sizeof (y2)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
510 memcpy (&c, x, sizeof (&c)); // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
511 memcpy (w, x, sizeof w); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
513 memcpy (x, y, sizeof (y)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
514 memcpy (x, y1, sizeof (y1)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
515 memcpy (x, y2, sizeof (y2)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
516 memcpy (x, &c, sizeof (&c)); // { dg-warning "call is the same expression as the source; did you mean to remove the addressof" }
517 memcpy (x, w, sizeof w); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
519 memmove (y, x, sizeof (y)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
520 memmove (y1, x, sizeof (y1)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
521 memmove (y2, x, sizeof (y2)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
522 memmove (&c, x, sizeof (&c)); // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
523 memmove (w, x, sizeof w); // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
525 memmove (x, y, sizeof (y)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
526 memmove (x, y1, sizeof (y1)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
527 memmove (x, y2, sizeof (y2)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
528 memmove (x, &c, sizeof (&c)); // { dg-warning "call is the same expression as the source; did you mean to remove the addressof" }
529 memmove (x, w, sizeof w); // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
531 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" }
532 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" }
533 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" }
534 z += memcmp (&c, x, sizeof (&c)); // { dg-warning "call is the same expression as the first source; did you mean to remove the addressof" }
535 z += memcmp (w, x, sizeof w); // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
537 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" }
538 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" }
539 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" }
540 z += memcmp (x, &c, sizeof (&c)); // { dg-warning "call is the same expression as the second source; did you mean to remove the addressof" }
541 z += memcmp (x, w, sizeof w); // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
543 // These are correct, no warning.
544 memset (y, 0, sizeof (*y));
545 memset (y1, 0, sizeof (*y2));
546 memset (buf1, 0, sizeof buf1);
547 memset (buf3, 0, sizeof (buf3));
548 memset (&buf3[0], 0, sizeof (buf3));
549 memset (&buf4[0], 0, sizeof (buf4));
550 memset (w, 0, sizeof (X));
551 // These are probably broken, but obfuscated, no warning.
552 memset ((void *) y, 0, sizeof (y));
553 memset ((char *) y1, 0, sizeof (y2));
554 memset (y, 0, sizeof (y) + 0);
555 memset (y1, 0, 0 + sizeof (y2));
556 memset ((void *) &c, 0, sizeof (&c));
557 memset ((signed char *) &c, 0, sizeof (&c));
558 memset (&c, 0, sizeof (&c) + 0);
559 memset (&c, 0, 0 + sizeof (&c));
561 // These are correct, no warning.
562 memcpy (y, x, sizeof (*y));
563 memcpy (y1, x, sizeof (*y2));
564 memcpy (buf1, x, sizeof buf1);
565 memcpy (buf3, x, sizeof (buf3));
566 memcpy (&buf3[0], x, sizeof (buf3));
567 memcpy (&buf4[0], x, sizeof (buf4));
568 memcpy (&y3, y, sizeof (y3));
569 memcpy ((char *) &y3, y, sizeof (y3));
570 memcpy (w, x, sizeof (X));
571 // These are probably broken, but obfuscated, no warning.
572 memcpy ((void *) y, x, sizeof (y));
573 memcpy ((char *) y1, x, sizeof (y2));
574 memcpy (y, x, sizeof (y) + 0);
575 memcpy (y1, x, 0 + sizeof (y2));
576 memcpy ((void *) &c, x, sizeof (&c));
577 memcpy ((signed char *) &c, x, sizeof (&c));
578 memcpy (&c, x, sizeof (&c) + 0);
579 memcpy (&c, x, 0 + sizeof (&c));
581 // These are correct, no warning.
582 memcpy (x, y, sizeof (*y));
583 memcpy (x, y1, sizeof (*y2));
584 memcpy (x, buf1, sizeof buf1);
585 memcpy (x, buf3, sizeof (buf3));
586 memcpy (x, &buf3[0], sizeof (buf3));
587 memcpy (x, &buf4[0], sizeof (buf4));
588 memcpy (y, &y3, sizeof (y3));
589 memcpy (y, (char *) &y3, sizeof (y3));
590 memcpy (x, w, sizeof (X));
591 // These are probably broken, but obfuscated, no warning.
592 memcpy (x, (void *) y, sizeof (y));
593 memcpy (x, (char *) y1, sizeof (y2));
594 memcpy (x, y, sizeof (y) + 0);
595 memcpy (x, y1, 0 + sizeof (y2));
596 memcpy (x, (void *) &c, sizeof (&c));
597 memcpy (x, (signed char *) &c, sizeof (&c));
598 memcpy (x, &c, sizeof (&c) + 0);
599 memcpy (x, &c, 0 + sizeof (&c));
601 // These are correct, no warning.
602 memmove (y, x, sizeof (*y));
603 memmove (y1, x, sizeof (*y2));
604 memmove (buf1, x, sizeof buf1);
605 memmove (buf3, x, sizeof (buf3));
606 memmove (&buf3[0], x, sizeof (buf3));
607 memmove (&buf4[0], x, sizeof (buf4));
608 memmove (&y3, y, sizeof (y3));
609 memmove ((char *) &y3, y, sizeof (y3));
610 memmove (w, x, sizeof (X));
611 // These are probably broken, but obfuscated, no warning.
612 memmove ((void *) y, x, sizeof (y));
613 memmove ((char *) y1, x, sizeof (y2));
614 memmove (y, x, sizeof (y) + 0);
615 memmove (y1, x, 0 + sizeof (y2));
616 memmove ((void *) &c, x, sizeof (&c));
617 memmove ((signed char *) &c, x, sizeof (&c));
618 memmove (&c, x, sizeof (&c) + 0);
619 memmove (&c, x, 0 + sizeof (&c));
621 // These are correct, no warning.
622 memmove (x, y, sizeof (*y));
623 memmove (x, y1, sizeof (*y2));
624 memmove (x, buf1, sizeof buf1);
625 memmove (x, buf3, sizeof (buf3));
626 memmove (x, &buf3[0], sizeof (buf3));
627 memmove (x, &buf4[0], sizeof (buf4));
628 memmove (y, &y3, sizeof (y3));
629 memmove (y, (char *) &y3, sizeof (y3));
630 memmove (x, w, sizeof (X));
631 // These are probably broken, but obfuscated, no warning.
632 memmove (x, (void *) y, sizeof (y));
633 memmove (x, (char *) y1, sizeof (y2));
634 memmove (x, y, sizeof (y) + 0);
635 memmove (x, y1, 0 + sizeof (y2));
636 memmove (x, (void *) &c, sizeof (&c));
637 memmove (x, (signed char *) &c, sizeof (&c));
638 memmove (x, &c, sizeof (&c) + 0);
639 memmove (x, &c, 0 + sizeof (&c));
641 // These are correct, no warning.
642 z += memcmp (y, x, sizeof (*y));
643 z += memcmp (y1, x, sizeof (*y2));
644 z += memcmp (buf1, x, sizeof buf1);
645 z += memcmp (buf3, x, sizeof (buf3));
646 z += memcmp (&buf3[0], x, sizeof (buf3));
647 z += memcmp (&buf4[0], x, sizeof (buf4));
648 z += memcmp (&y3, y, sizeof (y3));
649 z += memcmp ((char *) &y3, y, sizeof (y3));
650 z += memcmp (w, x, sizeof (X));
651 // These are probably broken, but obfuscated, no warning.
652 z += memcmp ((void *) y, x, sizeof (y));
653 z += memcmp ((char *) y1, x, sizeof (y2));
654 z += memcmp (y, x, sizeof (y) + 0);
655 z += memcmp (y1, x, 0 + sizeof (y2));
656 z += memcmp ((void *) &c, x, sizeof (&c));
657 z += memcmp ((signed char *) &c, x, sizeof (&c));
658 z += memcmp (&c, x, sizeof (&c) + 0);
659 z += memcmp (&c, x, 0 + sizeof (&c));
661 // These are correct, no warning.
662 z += memcmp (x, y, sizeof (*y));
663 z += memcmp (x, y1, sizeof (*y2));
664 z += memcmp (x, buf1, sizeof buf1);
665 z += memcmp (x, buf3, sizeof (buf3));
666 z += memcmp (x, &buf3[0], sizeof (buf3));
667 z += memcmp (x, &buf4[0], sizeof (buf4));
668 z += memcmp (y, &y3, sizeof (y3));
669 z += memcmp (y, (char *) &y3, sizeof (y3));
670 z += memcmp (x, w, sizeof (X));
671 // These are probably broken, but obfuscated, no warning.
672 z += memcmp (x, (void *) y, sizeof (y));
673 z += memcmp (x, (char *) y1, sizeof (y2));
674 z += memcmp (x, y, sizeof (y) + 0);
675 z += memcmp (x, y1, 0 + sizeof (y2));
676 z += memcmp (x, (void *) &c, sizeof (&c));
677 z += memcmp (x, (signed char *) &c, sizeof (&c));
678 z += memcmp (x, &c, sizeof (&c) + 0);
679 z += memcmp (x, &c, 0 + sizeof (&c));
685 f4 (char *x, char **y, int z, char w[64])
687 const char *s1 = "foobarbaz";
688 const char *s2 = "abcde12345678";
689 strncpy (x, s1, sizeof (s1)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
690 strncat (x, s2, sizeof (s2)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
691 stpncpy (x, s1, sizeof (s1)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
692 y[0] = strndup (s1, sizeof (s1)); // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
693 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" }
694 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" }
695 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" }
696 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" }
698 strncpy (w, s1, sizeof (w)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
699 strncat (w, s2, sizeof (w)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
700 stpncpy (w, s1, sizeof (w)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
702 const char s3[] = "foobarbaz";
703 const char s4[] = "abcde12345678";
705 // These are pointless when the destination is large enough, and
706 // cause overflow otherwise. They might as well be replaced by
707 // strcpy() or memcpy().
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?" }
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));
722 // { dg-prune-output "\[\n\r\]*overflows\[\n\r\]*" }