1 /* Test -Wsizeof-pointer-memaccess warnings. */
2 /* { dg-do compile } */
3 /* { dg-options "-Wall -O2" } */
5 #define bos(ptr) __builtin_object_size (ptr, 1)
6 #define bos0(ptr) __builtin_object_size (ptr, 0)
8 #define memset(dst, val, sz) __builtin___memset_chk (dst, val, sz, bos (dst))
9 #define memcpy(dst, src, sz) __builtin___memcpy_chk (dst, src, sz, bos (dst))
10 #define memmove(dst, src, sz) __builtin___memmove_chk (dst, src, sz, bos (dst))
11 #define strncpy(dst, src, sz) __builtin___strncpy_chk (dst, src, sz, bos (dst))
12 #define strncat(dst, src, sz) __builtin___strncat_chk (dst, src, sz, bos (dst))
13 #define stpncpy(dst, src, sz) __builtin___stpncpy_chk (dst, src, sz, bos (dst))
15 struct A
{ short a
, b
; int c
, d
; long e
, f
; };
23 typedef int X
[3][3][3];
28 struct A a
, *pa1
= &a
;
32 memset (&a
, 0, sizeof (&a
)); /* { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" } */
33 memset (pa1
, 0, sizeof (pa1
)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
34 memset (pa2
, 0, sizeof pa2
); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
35 memset (pa3
, 0, sizeof (pa3
)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
36 memset (pa4
, 0, sizeof pa4
); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
37 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" } */
38 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" } */
39 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" } */
40 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" } */
42 memcpy (&a
, x
, sizeof (&a
)); /* { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" } */
43 memcpy (pa1
, x
, sizeof (pa1
)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
44 memcpy (pa2
, x
, sizeof pa2
); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
45 memcpy (pa3
, x
, sizeof (pa3
)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
46 memcpy (pa4
, x
, sizeof pa4
); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
47 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" } */
48 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" } */
49 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" } */
50 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" } */
52 memcpy (x
, &a
, sizeof (&a
)); /* { dg-warning "call is the same expression as the source; did you mean to remove the addressof" } */
53 memcpy (x
, pa1
, sizeof (pa1
)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
54 memcpy (x
, pa2
, sizeof pa2
); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
55 memcpy (x
, pa3
, sizeof (pa3
)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
56 memcpy (x
, pa4
, sizeof pa4
); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
57 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" } */
58 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" } */
59 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" } */
60 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" } */
62 memmove (&a
, x
, sizeof (&a
)); /* { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" } */
63 memmove (pa1
, x
, sizeof (pa1
)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
64 memmove (pa2
, x
, sizeof pa2
); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
65 memmove (pa3
, x
, sizeof (pa3
)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
66 memmove (pa4
, x
, sizeof pa4
); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
67 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" } */
68 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" } */
69 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" } */
70 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" } */
72 memmove (x
, &a
, sizeof (&a
)); /* { dg-warning "call is the same expression as the source; did you mean to remove the addressof" } */
73 memmove (x
, pa1
, sizeof (pa1
)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
74 memmove (x
, pa2
, sizeof pa2
); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
75 memmove (x
, pa3
, sizeof (pa3
)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
76 memmove (x
, pa4
, sizeof pa4
); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
77 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" } */
78 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" } */
79 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" } */
80 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" } */
82 /* These are correct, no warning. */
83 memset (&a
, 0, sizeof a
);
84 memset (&a
, 0, sizeof (a
));
85 memset (&a
, 0, sizeof (struct A
));
86 memset (&a
, 0, sizeof (const struct A
));
87 memset (&a
, 0, sizeof (volatile struct A
));
88 memset (&a
, 0, sizeof (volatile const struct A
));
89 memset (&a
, 0, sizeof (TA
));
90 memset (&a
, 0, sizeof (__typeof (*&a
)));
91 memset (pa1
, 0, sizeof (*pa1
));
92 memset (pa2
, 0, sizeof (*pa3
));
93 memset (pa3
, 0, sizeof (__typeof (*pa3
)));
94 /* These are probably broken, but obfuscated, no warning. */
95 memset ((void *) &a
, 0, sizeof (&a
));
96 memset ((char *) &a
, 0, sizeof (&a
));
97 memset (&a
, 0, sizeof (&a
) + 0);
98 memset (&a
, 0, 0 + sizeof (&a
));
100 /* These are correct, no warning. */
101 memcpy (&a
, x
, sizeof a
);
102 memcpy (&a
, x
, sizeof (a
));
103 memcpy (&a
, x
, sizeof (struct A
));
104 memcpy (&a
, x
, sizeof (const struct A
));
105 memcpy (&a
, x
, sizeof (volatile struct A
));
106 memcpy (&a
, x
, sizeof (volatile const struct A
));
107 memcpy (&a
, x
, sizeof (TA
));
108 memcpy (&a
, x
, sizeof (__typeof (*&a
)));
109 memcpy (pa1
, x
, sizeof (*pa1
));
110 memcpy (pa2
, x
, sizeof (*pa3
));
111 memcpy (pa3
, x
, sizeof (__typeof (*pa3
)));
112 /* These are probably broken, but obfuscated, no warning. */
113 memcpy ((void *) &a
, x
, sizeof (&a
));
114 memcpy ((char *) &a
, x
, sizeof (&a
));
115 memcpy (&a
, x
, sizeof (&a
) + 0);
116 memcpy (&a
, x
, 0 + sizeof (&a
));
118 /* These are correct, no warning. */
119 memcpy (x
, &a
, sizeof a
);
120 memcpy (x
, &a
, sizeof (a
));
121 memcpy (x
, &a
, sizeof (struct A
));
122 memcpy (x
, &a
, sizeof (const struct A
));
123 memcpy (x
, &a
, sizeof (volatile struct A
));
124 memcpy (x
, &a
, sizeof (volatile const struct A
));
125 memcpy (x
, &a
, sizeof (TA
));
126 memcpy (x
, &a
, sizeof (__typeof (*&a
)));
127 memcpy (x
, pa1
, sizeof (*pa1
));
128 memcpy (x
, pa2
, sizeof (*pa3
));
129 memcpy (x
, pa3
, sizeof (__typeof (*pa3
)));
130 /* These are probably broken, but obfuscated, no warning. */
131 memcpy (x
, (void *) &a
, sizeof (&a
));
132 memcpy (x
, (char *) &a
, sizeof (&a
));
133 memcpy (x
, &a
, sizeof (&a
) + 0);
134 memcpy (x
, &a
, 0 + sizeof (&a
));
136 /* These are correct, no warning. */
137 memmove (&a
, x
, sizeof a
);
138 memmove (&a
, x
, sizeof (a
));
139 memmove (&a
, x
, sizeof (struct A
));
140 memmove (&a
, x
, sizeof (const struct A
));
141 memmove (&a
, x
, sizeof (volatile struct A
));
142 memmove (&a
, x
, sizeof (volatile const struct A
));
143 memmove (&a
, x
, sizeof (TA
));
144 memmove (&a
, x
, sizeof (__typeof (*&a
)));
145 memmove (pa1
, x
, sizeof (*pa1
));
146 memmove (pa2
, x
, sizeof (*pa3
));
147 memmove (pa3
, x
, sizeof (__typeof (*pa3
)));
148 /* These are probably broken, but obfuscated, no warning. */
149 memmove ((void *) &a
, x
, sizeof (&a
));
150 memmove ((char *) &a
, x
, sizeof (&a
));
151 memmove (&a
, x
, sizeof (&a
) + 0);
152 memmove (&a
, x
, 0 + sizeof (&a
));
154 /* These are correct, no warning. */
155 memmove (x
, &a
, sizeof a
);
156 memmove (x
, &a
, sizeof (a
));
157 memmove (x
, &a
, sizeof (struct A
));
158 memmove (x
, &a
, sizeof (const struct A
));
159 memmove (x
, &a
, sizeof (volatile struct A
));
160 memmove (x
, &a
, sizeof (volatile const struct A
));
161 memmove (x
, &a
, sizeof (TA
));
162 memmove (x
, &a
, sizeof (__typeof (*&a
)));
163 memmove (x
, pa1
, sizeof (*pa1
));
164 memmove (x
, pa2
, sizeof (*pa3
));
165 memmove (x
, pa3
, sizeof (__typeof (*pa3
)));
166 /* These are probably broken, but obfuscated, no warning. */
167 memmove (x
, (void *) &a
, sizeof (&a
));
168 memmove (x
, (char *) &a
, sizeof (&a
));
169 memmove (x
, &a
, sizeof (&a
) + 0);
170 memmove (x
, &a
, 0 + sizeof (&a
));
176 struct B b
, *pb1
= &b
;
180 memset (&b
, 0, sizeof (&b
)); /* { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" } */
181 memset (pb1
, 0, sizeof (pb1
)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
182 memset (pb2
, 0, sizeof pb2
); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
183 memset (pb3
, 0, sizeof (pb3
)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
184 memset (pb4
, 0, sizeof pb4
); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
185 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" } */
186 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" } */
187 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" } */
188 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" } */
190 memcpy (&b
, x
, sizeof (&b
)); /* { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" } */
191 memcpy (pb1
, x
, sizeof (pb1
)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
192 memcpy (pb2
, x
, sizeof pb2
); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
193 memcpy (pb3
, x
, sizeof (pb3
)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
194 memcpy (pb4
, x
, sizeof pb4
); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
195 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" } */
196 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" } */
197 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" } */
198 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" } */
200 memcpy (x
, &b
, sizeof (&b
)); /* { dg-warning "call is the same expression as the source; did you mean to remove the addressof" } */
201 memcpy (x
, pb1
, sizeof (pb1
)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
202 memcpy (x
, pb2
, sizeof pb2
); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
203 memcpy (x
, pb3
, sizeof (pb3
)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
204 memcpy (x
, pb4
, sizeof pb4
); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
205 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" } */
206 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" } */
207 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" } */
208 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" } */
210 memmove (&b
, x
, sizeof (&b
)); /* { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" } */
211 memmove (pb1
, x
, sizeof (pb1
)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
212 memmove (pb2
, x
, sizeof pb2
); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
213 memmove (pb3
, x
, sizeof (pb3
)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
214 memmove (pb4
, x
, sizeof pb4
); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
215 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" } */
216 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" } */
217 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" } */
218 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" } */
220 memmove (x
, &b
, sizeof (&b
)); /* { dg-warning "call is the same expression as the source; did you mean to remove the addressof" } */
221 memmove (x
, pb1
, sizeof (pb1
)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
222 memmove (x
, pb2
, sizeof pb2
); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
223 memmove (x
, pb3
, sizeof (pb3
)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
224 memmove (x
, pb4
, sizeof pb4
); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
225 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" } */
226 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" } */
227 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" } */
228 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" } */
230 /* These are correct, no warning. */
231 memset (&b
, 0, sizeof b
);
232 memset (&b
, 0, sizeof (b
));
233 memset (&b
, 0, sizeof (struct B
));
234 memset (&b
, 0, sizeof (const struct B
));
235 memset (&b
, 0, sizeof (volatile struct B
));
236 memset (&b
, 0, sizeof (volatile const struct B
));
237 memset (&b
, 0, sizeof (TB
));
238 memset (&b
, 0, sizeof (__typeof (*&b
)));
239 memset (pb1
, 0, sizeof (*pb1
));
240 memset (pb2
, 0, sizeof (*pb3
));
241 memset (pb3
, 0, sizeof (__typeof (*pb3
)));
242 /* These are probably broken, but obfuscated, no warning. */
243 memset ((void *) &b
, 0, sizeof (&b
));
244 memset ((char *) &b
, 0, sizeof (&b
));
245 memset (&b
, 0, sizeof (&b
) + 0);
246 memset (&b
, 0, 0 + sizeof (&b
));
248 /* These are correct, no warning. */
249 memcpy (&b
, x
, sizeof b
);
250 memcpy (&b
, x
, sizeof (b
));
251 memcpy (&b
, x
, sizeof (struct B
));
252 memcpy (&b
, x
, sizeof (const struct B
));
253 memcpy (&b
, x
, sizeof (volatile struct B
));
254 memcpy (&b
, x
, sizeof (volatile const struct B
));
255 memcpy (&b
, x
, sizeof (TB
));
256 memcpy (&b
, x
, sizeof (__typeof (*&b
)));
257 memcpy (pb1
, x
, sizeof (*pb1
));
258 memcpy (pb2
, x
, sizeof (*pb3
));
259 memcpy (pb3
, x
, sizeof (__typeof (*pb3
)));
260 /* These are probably broken, but obfuscated, no warning. */
261 memcpy ((void *) &b
, x
, sizeof (&b
));
262 memcpy ((char *) &b
, x
, sizeof (&b
));
263 memcpy (&b
, x
, sizeof (&b
) + 0);
264 memcpy (&b
, x
, 0 + sizeof (&b
));
266 /* These are correct, no warning. */
267 memcpy (x
, &b
, sizeof b
);
268 memcpy (x
, &b
, sizeof (b
));
269 memcpy (x
, &b
, sizeof (struct B
));
270 memcpy (x
, &b
, sizeof (const struct B
));
271 memcpy (x
, &b
, sizeof (volatile struct B
));
272 memcpy (x
, &b
, sizeof (volatile const struct B
));
273 memcpy (x
, &b
, sizeof (TB
));
274 memcpy (x
, &b
, sizeof (__typeof (*&b
)));
275 memcpy (x
, pb1
, sizeof (*pb1
));
276 memcpy (x
, pb2
, sizeof (*pb3
));
277 memcpy (x
, pb3
, sizeof (__typeof (*pb3
)));
278 /* These are probably broken, but obfuscated, no warning. */
279 memcpy (x
, (void *) &b
, sizeof (&b
));
280 memcpy (x
, (char *) &b
, sizeof (&b
));
281 memcpy (x
, &b
, sizeof (&b
) + 0);
282 memcpy (x
, &b
, 0 + sizeof (&b
));
284 /* These are correct, no warning. */
285 memmove (&b
, x
, sizeof b
);
286 memmove (&b
, x
, sizeof (b
));
287 memmove (&b
, x
, sizeof (struct B
));
288 memmove (&b
, x
, sizeof (const struct B
));
289 memmove (&b
, x
, sizeof (volatile struct B
));
290 memmove (&b
, x
, sizeof (volatile const struct B
));
291 memmove (&b
, x
, sizeof (TB
));
292 memmove (&b
, x
, sizeof (__typeof (*&b
)));
293 memmove (pb1
, x
, sizeof (*pb1
));
294 memmove (pb2
, x
, sizeof (*pb3
));
295 memmove (pb3
, x
, sizeof (__typeof (*pb3
)));
296 /* These are probably broken, but obfuscated, no warning. */
297 memmove ((void *) &b
, x
, sizeof (&b
));
298 memmove ((char *) &b
, x
, sizeof (&b
));
299 memmove (&b
, x
, sizeof (&b
) + 0);
300 memmove (&b
, x
, 0 + sizeof (&b
));
302 /* These are correct, no warning. */
303 memmove (x
, &b
, sizeof b
);
304 memmove (x
, &b
, sizeof (b
));
305 memmove (x
, &b
, sizeof (struct B
));
306 memmove (x
, &b
, sizeof (const struct B
));
307 memmove (x
, &b
, sizeof (volatile struct B
));
308 memmove (x
, &b
, sizeof (volatile const struct B
));
309 memmove (x
, &b
, sizeof (TB
));
310 memmove (x
, &b
, sizeof (__typeof (*&b
)));
311 memmove (x
, pb1
, sizeof (*pb1
));
312 memmove (x
, pb2
, sizeof (*pb3
));
313 memmove (x
, pb3
, sizeof (__typeof (*pb3
)));
314 /* These are probably broken, but obfuscated, no warning. */
315 memmove (x
, (void *) &b
, sizeof (&b
));
316 memmove (x
, (char *) &b
, sizeof (&b
));
317 memmove (x
, &b
, sizeof (&b
) + 0);
318 memmove (x
, &b
, 0 + sizeof (&b
));
322 f3 (void *x
, char *y
, int z
, X w
)
324 unsigned char *y1
= (unsigned char *) __builtin_alloca (z
+ 16);
326 signed char buf2
[z
+ 32];
329 signed char *y2
= buf2
;
332 memset (y
, 0, sizeof (y
)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
333 memset (y1
, 0, sizeof (y1
)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
334 memset (y2
, 0, sizeof (y2
)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
335 memset (&c
, 0, sizeof (&c
)); /* { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" } */
336 memset (w
, 0, sizeof w
); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
338 memcpy (y
, x
, sizeof (y
)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
339 memcpy (y1
, x
, sizeof (y1
)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
340 memcpy (y2
, x
, sizeof (y2
)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
341 memcpy (&c
, x
, sizeof (&c
)); /* { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" } */
342 memcpy (w
, x
, sizeof w
); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
344 memcpy (x
, y
, sizeof (y
)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
345 memcpy (x
, y1
, sizeof (y1
)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
346 memcpy (x
, y2
, sizeof (y2
)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
347 memcpy (x
, &c
, sizeof (&c
)); /* { dg-warning "call is the same expression as the source; did you mean to remove the addressof" } */
348 memcpy (x
, w
, sizeof w
); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
350 memmove (y
, x
, sizeof (y
)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
351 memmove (y1
, x
, sizeof (y1
)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
352 memmove (y2
, x
, sizeof (y2
)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
353 memmove (&c
, x
, sizeof (&c
)); /* { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" } */
354 memmove (w
, x
, sizeof w
); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
356 memmove (x
, y
, sizeof (y
)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
357 memmove (x
, y1
, sizeof (y1
)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
358 memmove (x
, y2
, sizeof (y2
)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
359 memmove (x
, &c
, sizeof (&c
)); /* { dg-warning "call is the same expression as the source; did you mean to remove the addressof" } */
360 memmove (x
, w
, sizeof w
); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
362 /* These are correct, no warning. */
363 memset (y
, 0, sizeof (*y
));
364 memset (y1
, 0, sizeof (*y2
));
365 memset (buf1
, 0, sizeof buf1
);
366 memset (buf3
, 0, sizeof (buf3
));
367 memset (&buf3
[0], 0, sizeof (buf3
));
368 memset (&buf4
[0], 0, sizeof (buf4
));
369 memset (w
, 0, sizeof (X
));
370 /* These are probably broken, but obfuscated, no warning. */
371 memset ((void *) y
, 0, sizeof (y
));
372 memset ((char *) y1
, 0, sizeof (y2
));
373 memset (y
, 0, sizeof (y
) + 0);
374 memset (y1
, 0, 0 + sizeof (y2
));
375 memset ((void *) &c
, 0, sizeof (&c
));
376 memset ((signed char *) &c
, 0, sizeof (&c
));
377 memset (&c
, 0, sizeof (&c
) + 0);
378 memset (&c
, 0, 0 + sizeof (&c
));
380 /* These are correct, no warning. */
381 memcpy (y
, x
, sizeof (*y
));
382 memcpy (y1
, x
, sizeof (*y2
));
383 memcpy (buf1
, x
, sizeof buf1
);
384 memcpy (buf3
, x
, sizeof (buf3
));
385 memcpy (&buf3
[0], x
, sizeof (buf3
));
386 memcpy (&buf4
[0], x
, sizeof (buf4
));
387 memcpy (&y3
, y
, sizeof (y3
));
388 memcpy ((char *) &y3
, y
, sizeof (y3
));
389 memcpy (w
, x
, sizeof (X
));
390 /* These are probably broken, but obfuscated, no warning. */
391 memcpy ((void *) y
, x
, sizeof (y
));
392 memcpy ((char *) y1
, x
, sizeof (y2
));
393 memcpy (y
, x
, sizeof (y
) + 0);
394 memcpy (y1
, x
, 0 + sizeof (y2
));
395 memcpy ((void *) &c
, x
, sizeof (&c
));
396 memcpy ((signed char *) &c
, x
, sizeof (&c
));
397 memcpy (&c
, x
, sizeof (&c
) + 0);
398 memcpy (&c
, x
, 0 + sizeof (&c
));
400 /* These are correct, no warning. */
401 memcpy (x
, y
, sizeof (*y
));
402 memcpy (x
, y1
, sizeof (*y2
));
403 memcpy (x
, buf1
, sizeof buf1
);
404 memcpy (x
, buf3
, sizeof (buf3
));
405 memcpy (x
, &buf3
[0], sizeof (buf3
));
406 memcpy (x
, &buf4
[0], sizeof (buf4
));
407 memcpy (y
, &y3
, sizeof (y3
));
408 memcpy (y
, (char *) &y3
, sizeof (y3
));
409 memcpy (x
, w
, sizeof (X
));
410 /* These are probably broken, but obfuscated, no warning. */
411 memcpy (x
, (void *) y
, sizeof (y
));
412 memcpy (x
, (char *) y1
, sizeof (y2
));
413 memcpy (x
, y
, sizeof (y
) + 0);
414 memcpy (x
, y1
, 0 + sizeof (y2
));
415 memcpy (x
, (void *) &c
, sizeof (&c
));
416 memcpy (x
, (signed char *) &c
, sizeof (&c
));
417 memcpy (x
, &c
, sizeof (&c
) + 0);
418 memcpy (x
, &c
, 0 + sizeof (&c
));
420 /* These are correct, no warning. */
421 memmove (y
, x
, sizeof (*y
));
422 memmove (y1
, x
, sizeof (*y2
));
423 memmove (buf1
, x
, sizeof buf1
);
424 memmove (buf3
, x
, sizeof (buf3
));
425 memmove (&buf3
[0], x
, sizeof (buf3
));
426 memmove (&buf4
[0], x
, sizeof (buf4
));
427 memmove (&y3
, y
, sizeof (y3
));
428 memmove ((char *) &y3
, y
, sizeof (y3
));
429 memmove (w
, x
, sizeof (X
));
430 /* These are probably broken, but obfuscated, no warning. */
431 memmove ((void *) y
, x
, sizeof (y
));
432 memmove ((char *) y1
, x
, sizeof (y2
));
433 memmove (y
, x
, sizeof (y
) + 0);
434 memmove (y1
, x
, 0 + sizeof (y2
));
435 memmove ((void *) &c
, x
, sizeof (&c
));
436 memmove ((signed char *) &c
, x
, sizeof (&c
));
437 memmove (&c
, x
, sizeof (&c
) + 0);
438 memmove (&c
, x
, 0 + sizeof (&c
));
440 /* These are correct, no warning. */
441 memmove (x
, y
, sizeof (*y
));
442 memmove (x
, y1
, sizeof (*y2
));
443 memmove (x
, buf1
, sizeof buf1
);
444 memmove (x
, buf3
, sizeof (buf3
));
445 memmove (x
, &buf3
[0], sizeof (buf3
));
446 memmove (x
, &buf4
[0], sizeof (buf4
));
447 memmove (y
, &y3
, sizeof (y3
));
448 memmove (y
, (char *) &y3
, sizeof (y3
));
449 memmove (x
, w
, sizeof (X
));
450 /* These are probably broken, but obfuscated, no warning. */
451 memmove (x
, (void *) y
, sizeof (y
));
452 memmove (x
, (char *) y1
, sizeof (y2
));
453 memmove (x
, y
, sizeof (y
) + 0);
454 memmove (x
, y1
, 0 + sizeof (y2
));
455 memmove (x
, (void *) &c
, sizeof (&c
));
456 memmove (x
, (signed char *) &c
, sizeof (&c
));
457 memmove (x
, &c
, sizeof (&c
) + 0);
458 memmove (x
, &c
, 0 + sizeof (&c
));
462 f4 (char *x
, char **y
, int z
, char w
[64])
464 const char *s1
= "foobarbaz";
465 const char *s2
= "abcde12345678";
466 strncpy (x
, s1
, sizeof (s1
)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
467 strncat (x
, s2
, sizeof (s2
)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
468 stpncpy (x
, s1
, sizeof (s1
)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
470 strncpy (w
, s1
, sizeof (w
)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
471 strncat (w
, s2
, sizeof (w
)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
472 stpncpy (w
, s1
, sizeof (w
)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
474 /* These are correct, no warning. */
475 const char s3
[] = "foobarbaz";
476 const char s4
[] = "abcde12345678";
477 strncpy (x
, s3
, sizeof (s3
));
478 strncat (x
, s4
, sizeof (s4
));
479 stpncpy (x
, s3
, sizeof (s3
));
482 /* { dg-prune-output "\[\n\r\]*will always overflow\[\n\r\]*" } */