1// Test -Wsizeof-pointer-memaccess warnings.
2// { dg-do compile }
3// { dg-options "-Wall -Wno-sizeof-array-argument" }
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
8extern "C" {
9
10typedef __SIZE_TYPE__ size_t;
11extern void *memset (void *, int, size_t);
12extern void *memcpy (void *__restrict, const void *__restrict, size_t);
13extern void *memmove (void *__restrict, const void *__restrict, size_t);
14extern int memcmp (const void *, const void *, size_t);
15extern char *strncpy (char *__restrict, const char *__restrict, size_t);
16extern char *strncat (char *__restrict, const char *__restrict, size_t);
17extern char *stpncpy (char *__restrict, const char *__restrict, size_t);
18extern char *strndup (const char *, size_t);
19extern int strncmp (const char *, const char *, size_t);
20extern int strncasecmp (const char *, const char *, size_t);
21
22#ifdef __OPTIMIZE__
23# define bos(ptr) __builtin_object_size (ptr, 1)
24# define bos0(ptr) __builtin_object_size (ptr, 0)
25
26__attribute__((__always_inline__, __gnu_inline__, __artificial__))
27extern inline void *
28memset (void *dest, int c, size_t len)
29{
30  return __builtin___memset_chk (dest, c, len, bos0 (dest));
31}
32
33__attribute__((__always_inline__, __gnu_inline__, __artificial__))
34extern inline void *
35memcpy (void *__restrict dest, const void *__restrict src, size_t len)
36{
37  return __builtin___memcpy_chk (dest, src, len, bos0 (dest));
38}
39
40__attribute__((__always_inline__, __gnu_inline__, __artificial__))
41extern inline void *
42memmove (void *dest, const void *src, size_t len)
43{
44  return __builtin___memmove_chk (dest, src, len, bos0 (dest));
45}
46
47__attribute__((__always_inline__, __gnu_inline__, __artificial__))
48extern inline char *
49strncpy (char *__restrict dest, const char *__restrict src, size_t len)
50{
51  return __builtin___strncpy_chk (dest, src, len, bos (dest));
52}
53
54__attribute__((__always_inline__, __gnu_inline__, __artificial__))
55extern inline char *
56strncat (char *dest, const char *src, size_t len)
57{
58  return __builtin___strncat_chk (dest, src, len, bos (dest));
59}
60
61__attribute__((__always_inline__, __gnu_inline__, __artificial__))
62extern inline char *
63stpncpy (char *__restrict dest, const char *__restrict src, size_t len)
64{
65  return __builtin___stpncpy_chk (dest, src, len, bos (dest));
66}
67#endif
68
69}
70
71struct A { short a, b; int c, d; long e, f; };
72typedef struct A TA;
73typedef struct A *PA;
74typedef TA *PTA;
75struct B {};
76typedef struct B TB;
77typedef struct B *PB;
78typedef TB *PTB;
79typedef int X[3][3][3];
80
81template <int N>
82int
83f1 (void *x, int z)
84{
85  struct A a, *pa1 = &a;
86  TA *pa2 = &a;
87  PA pa3 = &a;
88  PTA pa4 = &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" }
98
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" }
108
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" }
118
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" }
128
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" }
138
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" }
147
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" }
156
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));
174
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));
192
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));
210
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));
228
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));
246
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));
264
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));
282
283  return z;
284}
285
286template <int N>
287int
288f2 (void *x, int z)
289{
290  struct B b, *pb1 = &b;
291  TB *pb2 = &b;
292  PB pb3 = &b;
293  PTB pb4 = &b;
294  memset (&b, 0, sizeof (&b));		    // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
295  memset (pb1, 0, sizeof (pb1));	    // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
296  memset (pb2, 0, sizeof pb2);		    // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
297  memset (pb3, 0, sizeof (pb3));	    // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
298  memset (pb4, 0, sizeof pb4);		    // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
299  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" }
300  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" }
301  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" }
302  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
304  memcpy (&b, x, sizeof (&b));		    // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
305  memcpy (pb1, x, sizeof (pb1));	    // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
306  memcpy (pb2, x, sizeof pb2);		    // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
307  memcpy (pb3, x, sizeof (pb3));	    // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
308  memcpy (pb4, x, sizeof pb4);		    // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
309  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" }
310  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" }
311  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" }
312  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
314  memcpy (x, &b, sizeof (&b));		    // { dg-warning "call is the same expression as the source; did you mean to remove the addressof" }
315  memcpy (x, pb1, sizeof (pb1));	    // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
316  memcpy (x, pb2, sizeof pb2);		    // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
317  memcpy (x, pb3, sizeof (pb3));	    // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
318  memcpy (x, pb4, sizeof pb4);		    // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
319  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" }
320  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" }
321  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" }
322  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
324  memmove (&b, x, sizeof (&b));		    // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
325  memmove (pb1, x, sizeof (pb1));	    // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
326  memmove (pb2, x, sizeof pb2);		    // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
327  memmove (pb3, x, sizeof (pb3));	    // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
328  memmove (pb4, x, sizeof pb4);		    // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
329  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" }
330  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" }
331  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" }
332  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
334  memmove (x, &b, sizeof (&b));		    // { dg-warning "call is the same expression as the source; did you mean to remove the addressof" }
335  memmove (x, pb1, sizeof (pb1));	    // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
336  memmove (x, pb2, sizeof pb2);		    // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
337  memmove (x, pb3, sizeof (pb3));	    // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
338  memmove (x, pb4, sizeof pb4);		    // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
339  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" }
340  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" }
341  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" }
342  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
344  z += memcmp (&b, x, sizeof (&b));	    // { dg-warning "call is the same expression as the first source; did you mean to remove the addressof" }
345  z += memcmp (pb1, x, sizeof (pb1));	    // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
346  z += memcmp (pb2, x, sizeof pb2);	    // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
347  z += memcmp (pb3, x, sizeof (pb3));	    // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
348  z += memcmp (pb4, x, sizeof pb4);	    // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
349  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" }
350  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" }
351  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
353  z += memcmp (x, &b, sizeof (&b));	    // { dg-warning "call is the same expression as the second source; did you mean to remove the addressof" }
354  z += memcmp (x, pb1, sizeof (pb1));	    // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
355  z += memcmp (x, pb2, sizeof pb2);	    // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
356  z += memcmp (x, pb3, sizeof (pb3));	    // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
357  z += memcmp (x, pb4, sizeof pb4);	    // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
358  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" }
359  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" }
360  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
362  // These are correct, no warning.
363  memset (&b, 0, sizeof b);
364  memset (&b, 0, sizeof (b));
365  memset (&b, 0, sizeof (struct B));
366  memset (&b, 0, sizeof (const struct B));
367  memset (&b, 0, sizeof (volatile struct B));
368  memset (&b, 0, sizeof (volatile const struct B));
369  memset (&b, 0, sizeof (TB));
370  memset (&b, 0, sizeof (__typeof (*&b)));
371  memset (pb1, 0, sizeof (*pb1));
372  memset (pb2, 0, sizeof (*pb3));
373  memset (pb3, 0, sizeof (__typeof (*pb3)));
374  // These are probably broken, but obfuscated, no warning.
375  memset ((void *) &b, 0, sizeof (&b));
376  memset ((char *) &b, 0, sizeof (&b));
377  memset (&b, 0, sizeof (&b) + 0);
378  memset (&b, 0, 0 + sizeof (&b));
379
380  // These are correct, no warning.
381  memcpy (&b, x, sizeof b);
382  memcpy (&b, x, sizeof (b));
383  memcpy (&b, x, sizeof (struct B));
384  memcpy (&b, x, sizeof (const struct B));
385  memcpy (&b, x, sizeof (volatile struct B));
386  memcpy (&b, x, sizeof (volatile const struct B));
387  memcpy (&b, x, sizeof (TB));
388  memcpy (&b, x, sizeof (__typeof (*&b)));
389  memcpy (pb1, x, sizeof (*pb1));
390  memcpy (pb2, x, sizeof (*pb3));
391  memcpy (pb3, x, sizeof (__typeof (*pb3)));
392  // These are probably broken, but obfuscated, no warning.
393  memcpy ((void *) &b, x, sizeof (&b));
394  memcpy ((char *) &b, x, sizeof (&b));
395  memcpy (&b, x, sizeof (&b) + 0);
396  memcpy (&b, x, 0 + sizeof (&b));
397
398  // These are correct, no warning.
399  memcpy (x, &b, sizeof b);
400  memcpy (x, &b, sizeof (b));
401  memcpy (x, &b, sizeof (struct B));
402  memcpy (x, &b, sizeof (const struct B));
403  memcpy (x, &b, sizeof (volatile struct B));
404  memcpy (x, &b, sizeof (volatile const struct B));
405  memcpy (x, &b, sizeof (TB));
406  memcpy (x, &b, sizeof (__typeof (*&b)));
407  memcpy (x, pb1, sizeof (*pb1));
408  memcpy (x, pb2, sizeof (*pb3));
409  memcpy (x, pb3, sizeof (__typeof (*pb3)));
410  // These are probably broken, but obfuscated, no warning.
411  memcpy (x, (void *) &b, sizeof (&b));
412  memcpy (x, (char *) &b, sizeof (&b));
413  memcpy (x, &b, sizeof (&b) + 0);
414  memcpy (x, &b, 0 + sizeof (&b));
415
416  // These are correct, no warning.
417  memmove (&b, x, sizeof b);
418  memmove (&b, x, sizeof (b));
419  memmove (&b, x, sizeof (struct B));
420  memmove (&b, x, sizeof (const struct B));
421  memmove (&b, x, sizeof (volatile struct B));
422  memmove (&b, x, sizeof (volatile const struct B));
423  memmove (&b, x, sizeof (TB));
424  memmove (&b, x, sizeof (__typeof (*&b)));
425  memmove (pb1, x, sizeof (*pb1));
426  memmove (pb2, x, sizeof (*pb3));
427  memmove (pb3, x, sizeof (__typeof (*pb3)));
428  // These are probably broken, but obfuscated, no warning.
429  memmove ((void *) &b, x, sizeof (&b));
430  memmove ((char *) &b, x, sizeof (&b));
431  memmove (&b, x, sizeof (&b) + 0);
432  memmove (&b, x, 0 + sizeof (&b));
433
434  // These are correct, no warning.
435  memmove (x, &b, sizeof b);
436  memmove (x, &b, sizeof (b));
437  memmove (x, &b, sizeof (struct B));
438  memmove (x, &b, sizeof (const struct B));
439  memmove (x, &b, sizeof (volatile struct B));
440  memmove (x, &b, sizeof (volatile const struct B));
441  memmove (x, &b, sizeof (TB));
442  memmove (x, &b, sizeof (__typeof (*&b)));
443  memmove (x, pb1, sizeof (*pb1));
444  memmove (x, pb2, sizeof (*pb3));
445  memmove (x, pb3, sizeof (__typeof (*pb3)));
446  // These are probably broken, but obfuscated, no warning.
447  memmove (x, (void *) &b, sizeof (&b));
448  memmove (x, (char *) &b, sizeof (&b));
449  memmove (x, &b, sizeof (&b) + 0);
450  memmove (x, &b, 0 + sizeof (&b));
451
452  // These are correct, no warning.
453  z += memcmp (&b, x, sizeof b);
454  z += memcmp (&b, x, sizeof (b));
455  z += memcmp (&b, x, sizeof (struct B));
456  z += memcmp (&b, x, sizeof (const struct B));
457  z += memcmp (&b, x, sizeof (volatile struct B));
458  z += memcmp (&b, x, sizeof (volatile const struct B));
459  z += memcmp (&b, x, sizeof (TB));
460  z += memcmp (&b, x, sizeof (__typeof (*&b)));
461  z += memcmp (pb1, x, sizeof (*pb1));
462  z += memcmp (pb2, x, sizeof (*pb3));
463  z += memcmp (pb3, x, sizeof (__typeof (*pb3)));
464  // These are probably broken, but obfuscated, no warning.
465  z += memcmp ((void *) &b, x, sizeof (&b));
466  z += memcmp ((char *) &b, x, sizeof (&b));
467  z += memcmp (&b, x, sizeof (&b) + 0);
468  z += memcmp (&b, x, 0 + sizeof (&b));
469
470  // These are correct, no warning.
471  z += memcmp (x, &b, sizeof b);
472  z += memcmp (x, &b, sizeof (b));
473  z += memcmp (x, &b, sizeof (struct B));
474  z += memcmp (x, &b, sizeof (const struct B));
475  z += memcmp (x, &b, sizeof (volatile struct B));
476  z += memcmp (x, &b, sizeof (volatile const struct B));
477  z += memcmp (x, &b, sizeof (TB));
478  z += memcmp (x, &b, sizeof (__typeof (*&b)));
479  z += memcmp (x, pb1, sizeof (*pb1));
480  z += memcmp (x, pb2, sizeof (*pb3));
481  z += memcmp (x, pb3, sizeof (__typeof (*pb3)));
482  // These are probably broken, but obfuscated, no warning.
483  z += memcmp (x, (void *) &b, sizeof (&b));
484  z += memcmp (x, (char *) &b, sizeof (&b));
485  z += memcmp (x, &b, sizeof (&b) + 0);
486  z += memcmp (x, &b, 0 + sizeof (&b));
487
488  return z;
489}
490
491template <int N>
492int
493f3 (void *x, char *y, int z, X w)
494{
495  unsigned char *y1 = (unsigned char *) __builtin_alloca (z + 16);
496  char buf1[7];
497  signed char buf2[z + 32];
498  long buf3[17];
499  int *buf4[9];
500  signed char *y2 = buf2;
501  char c;
502  char *y3;
503  memset (y, 0, sizeof (y));		    // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
504  memset (y1, 0, sizeof (y1));		    // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
505  memset (y2, 0, sizeof (y2));		    // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
506  memset (&c, 0, sizeof (&c));		    // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
507  memset (w, 0, sizeof w);		    // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
508
509  memcpy (y, x, sizeof (y));		    // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
510  memcpy (y1, x, sizeof (y1));		    // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
511  memcpy (y2, x, sizeof (y2));		    // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
512  memcpy (&c, x, sizeof (&c));		    // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
513  memcpy (w, x, sizeof w);		    // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
514
515  memcpy (x, y, sizeof (y));		    // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
516  memcpy (x, y1, sizeof (y1));		    // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
517  memcpy (x, y2, sizeof (y2));		    // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
518  memcpy (x, &c, sizeof (&c));		    // { dg-warning "call is the same expression as the source; did you mean to remove the addressof" }
519  memcpy (x, w, sizeof w);		    // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
520
521  memmove (y, x, sizeof (y));		    // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
522  memmove (y1, x, sizeof (y1));		    // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
523  memmove (y2, x, sizeof (y2));		    // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
524  memmove (&c, x, sizeof (&c));		    // { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" }
525  memmove (w, x, sizeof w);		    // { dg-warning "call is the same expression as the destination; did you mean to dereference it" }
526
527  memmove (x, y, sizeof (y));		    // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
528  memmove (x, y1, sizeof (y1));		    // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
529  memmove (x, y2, sizeof (y2));		    // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
530  memmove (x, &c, sizeof (&c));		    // { dg-warning "call is the same expression as the source; did you mean to remove the addressof" }
531  memmove (x, w, sizeof w);		    // { dg-warning "call is the same expression as the source; did you mean to dereference it" }
532
533  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" }
534  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" }
535  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" }
536  z += memcmp (&c, x, sizeof (&c));	    // { dg-warning "call is the same expression as the first source; did you mean to remove the addressof" }
537  z += memcmp (w, x, sizeof w);		    // { dg-warning "call is the same expression as the first source; did you mean to dereference it" }
538
539  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" }
540  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" }
541  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" }
542  z += memcmp (x, &c, sizeof (&c));	    // { dg-warning "call is the same expression as the second source; did you mean to remove the addressof" }
543  z += memcmp (x, w, sizeof w);		    // { dg-warning "call is the same expression as the second source; did you mean to dereference it" }
544
545  // These are correct, no warning.
546  memset (y, 0, sizeof (*y));
547  memset (y1, 0, sizeof (*y2));
548  memset (buf1, 0, sizeof buf1);
549  memset (buf3, 0, sizeof (buf3));
550  memset (&buf3[0], 0, sizeof (buf3));
551  memset (&buf4[0], 0, sizeof (buf4));
552  memset (w, 0, sizeof (X));
553  // These are probably broken, but obfuscated, no warning.
554  memset ((void *) y, 0, sizeof (y));
555  memset ((char *) y1, 0, sizeof (y2));
556  memset (y, 0, sizeof (y) + 0);
557  memset (y1, 0, 0 + sizeof (y2));
558  memset ((void *) &c, 0, sizeof (&c));
559  memset ((signed char *) &c, 0, sizeof (&c));
560  memset (&c, 0, sizeof (&c) + 0);
561  memset (&c, 0, 0 + sizeof (&c));
562
563  // These are correct, no warning.
564  memcpy (y, x, sizeof (*y));
565  memcpy (y1, x, sizeof (*y2));
566  memcpy (buf1, x, sizeof buf1);
567  memcpy (buf3, x, sizeof (buf3));
568  memcpy (&buf3[0], x, sizeof (buf3));
569  memcpy (&buf4[0], x, sizeof (buf4));
570  memcpy (&y3, y, sizeof (y3));
571  memcpy ((char *) &y3, y, sizeof (y3));
572  memcpy (w, x, sizeof (X));
573  // These are probably broken, but obfuscated, no warning.
574  memcpy ((void *) y, x, sizeof (y));
575  memcpy ((char *) y1, x, sizeof (y2));
576  memcpy (y, x, sizeof (y) + 0);
577  memcpy (y1, x, 0 + sizeof (y2));
578  memcpy ((void *) &c, x, sizeof (&c));
579  memcpy ((signed char *) &c, x, sizeof (&c));
580  memcpy (&c, x, sizeof (&c) + 0);
581  memcpy (&c, x, 0 + sizeof (&c));
582
583  // These are correct, no warning.
584  memcpy (x, y, sizeof (*y));
585  memcpy (x, y1, sizeof (*y2));
586  memcpy (x, buf1, sizeof buf1);
587  memcpy (x, buf3, sizeof (buf3));
588  memcpy (x, &buf3[0], sizeof (buf3));
589  memcpy (x, &buf4[0], sizeof (buf4));
590  memcpy (y, &y3, sizeof (y3));
591  memcpy (y, (char *) &y3, sizeof (y3));
592  memcpy (x, w, sizeof (X));
593  // These are probably broken, but obfuscated, no warning.
594  memcpy (x, (void *) y, sizeof (y));
595  memcpy (x, (char *) y1, sizeof (y2));
596  memcpy (x, y, sizeof (y) + 0);
597  memcpy (x, y1, 0 + sizeof (y2));
598  memcpy (x, (void *) &c, sizeof (&c));
599  memcpy (x, (signed char *) &c, sizeof (&c));
600  memcpy (x, &c, sizeof (&c) + 0);
601  memcpy (x, &c, 0 + sizeof (&c));
602
603  // These are correct, no warning.
604  memmove (y, x, sizeof (*y));
605  memmove (y1, x, sizeof (*y2));
606  memmove (buf1, x, sizeof buf1);
607  memmove (buf3, x, sizeof (buf3));
608  memmove (&buf3[0], x, sizeof (buf3));
609  memmove (&buf4[0], x, sizeof (buf4));
610  memmove (&y3, y, sizeof (y3));
611  memmove ((char *) &y3, y, sizeof (y3));
612  memmove (w, x, sizeof (X));
613  // These are probably broken, but obfuscated, no warning.
614  memmove ((void *) y, x, sizeof (y));
615  memmove ((char *) y1, x, sizeof (y2));
616  memmove (y, x, sizeof (y) + 0);
617  memmove (y1, x, 0 + sizeof (y2));
618  memmove ((void *) &c, x, sizeof (&c));
619  memmove ((signed char *) &c, x, sizeof (&c));
620  memmove (&c, x, sizeof (&c) + 0);
621  memmove (&c, x, 0 + sizeof (&c));
622
623  // These are correct, no warning.
624  memmove (x, y, sizeof (*y));
625  memmove (x, y1, sizeof (*y2));
626  memmove (x, buf1, sizeof buf1);
627  memmove (x, buf3, sizeof (buf3));
628  memmove (x, &buf3[0], sizeof (buf3));
629  memmove (x, &buf4[0], sizeof (buf4));
630  memmove (y, &y3, sizeof (y3));
631  memmove (y, (char *) &y3, sizeof (y3));
632  memmove (x, w, sizeof (X));
633  // These are probably broken, but obfuscated, no warning.
634  memmove (x, (void *) y, sizeof (y));
635  memmove (x, (char *) y1, sizeof (y2));
636  memmove (x, y, sizeof (y) + 0);
637  memmove (x, y1, 0 + sizeof (y2));
638  memmove (x, (void *) &c, sizeof (&c));
639  memmove (x, (signed char *) &c, sizeof (&c));
640  memmove (x, &c, sizeof (&c) + 0);
641  memmove (x, &c, 0 + sizeof (&c));
642
643  // These are correct, no warning.
644  z += memcmp (y, x, sizeof (*y));
645  z += memcmp (y1, x, sizeof (*y2));
646  z += memcmp (buf1, x, sizeof buf1);
647  z += memcmp (buf3, x, sizeof (buf3));
648  z += memcmp (&buf3[0], x, sizeof (buf3));
649  z += memcmp (&buf4[0], x, sizeof (buf4));
650  z += memcmp (&y3, y, sizeof (y3));
651  z += memcmp ((char *) &y3, y, sizeof (y3));
652  z += memcmp (w, x, sizeof (X));
653  // These are probably broken, but obfuscated, no warning.
654  z += memcmp ((void *) y, x, sizeof (y));
655  z += memcmp ((char *) y1, x, sizeof (y2));
656  z += memcmp (y, x, sizeof (y) + 0);
657  z += memcmp (y1, x, 0 + sizeof (y2));
658  z += memcmp ((void *) &c, x, sizeof (&c));
659  z += memcmp ((signed char *) &c, x, sizeof (&c));
660  z += memcmp (&c, x, sizeof (&c) + 0);
661  z += memcmp (&c, x, 0 + sizeof (&c));
662
663  // These are correct, no warning.
664  z += memcmp (x, y, sizeof (*y));
665  z += memcmp (x, y1, sizeof (*y2));
666  z += memcmp (x, buf1, sizeof buf1);
667  z += memcmp (x, buf3, sizeof (buf3));
668  z += memcmp (x, &buf3[0], sizeof (buf3));
669  z += memcmp (x, &buf4[0], sizeof (buf4));
670  z += memcmp (y, &y3, sizeof (y3));
671  z += memcmp (y, (char *) &y3, sizeof (y3));
672  z += memcmp (x, w, sizeof (X));
673  // These are probably broken, but obfuscated, no warning.
674  z += memcmp (x, (void *) y, sizeof (y));
675  z += memcmp (x, (char *) y1, sizeof (y2));
676  z += memcmp (x, y, sizeof (y) + 0);
677  z += memcmp (x, y1, 0 + sizeof (y2));
678  z += memcmp (x, (void *) &c, sizeof (&c));
679  z += memcmp (x, (signed char *) &c, sizeof (&c));
680  z += memcmp (x, &c, sizeof (&c) + 0);
681  z += memcmp (x, &c, 0 + sizeof (&c));
682
683  return z;
684}
685
686template <int N>
687int
688f4 (char *x, char **y, int z, char w[64])
689{
690  const char *s1 = "foobarbaz";
691  const char *s2 = "abcde12345678";
692  strncpy (x, s1, sizeof (s1));		    // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
693  strncat (x, s2, sizeof (s2));		    // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
694  stpncpy (x, s1, sizeof (s1));		    // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
695  y[0] = strndup (s1, sizeof (s1));	    // { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" }
696  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" }
697  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" }
698  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" }
699  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" }
700
701  strncpy (w, s1, sizeof (w));		    // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
702  strncat (w, s2, sizeof (w));		    // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
703  stpncpy (w, s1, sizeof (w));		    // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" }
704
705  // These are correct, no warning.
706  const char s3[] = "foobarbaz";
707  const char s4[] = "abcde12345678";
708  strncpy (x, s3, sizeof (s3));
709  strncat (x, s4, sizeof (s4));
710  stpncpy (x, s3, sizeof (s3));
711  y[1] = strndup (s3, sizeof (s3));
712  z += strncmp (s3, s4, sizeof (s3));
713  z += strncmp (s3, s4, sizeof (s4));
714  z += strncasecmp (s3, s4, sizeof (s3));
715  z += strncasecmp (s3, s4, sizeof (s4));
716
717  return z;
718}
719
720int
721f (void *x, char *y, int z, X w, char **u, char v[64])
722{
723  z += f1<0> (x, z);
724  z += f2<0> (x, z);
725  z += f3<0> (x, y, z, w);
726  z += f4<0> (y, u, z, v);
727  return z;
728}
729
730// { dg-prune-output "\[\n\r\]*will always overflow\[\n\r\]*" }
731