Debian Codegraph @

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