annotate gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess2.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Test -Wsizeof-pointer-memaccess warnings. */
kono
parents:
diff changeset
2 /* { dg-do compile } */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3 /* { dg-options "-Wall -O2 -Wno-array-bounds -Wno-sizeof-array-argument -Wno-stringop-truncation -ftrack-macro-expansion=0" } */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
4 /* { dg-options "-Wall -O2 -Wno-array-bounds -Wno-sizeof-array-argument -Wno-stringop-truncation -Wno-c++-compat -ftrack-macro-expansion=0" {target c} } */
111
kono
parents:
diff changeset
5 /* { dg-require-effective-target alloca } */
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 #define bos(ptr) __builtin_object_size (ptr, 1)
kono
parents:
diff changeset
8 #define bos0(ptr) __builtin_object_size (ptr, 0)
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 #define memset(dst, val, sz) __builtin___memset_chk (dst, val, sz, bos (dst))
kono
parents:
diff changeset
11 #define memcpy(dst, src, sz) __builtin___memcpy_chk (dst, src, sz, bos (dst))
kono
parents:
diff changeset
12 #define memmove(dst, src, sz) __builtin___memmove_chk (dst, src, sz, bos (dst))
kono
parents:
diff changeset
13 #define strncpy(dst, src, sz) __builtin___strncpy_chk (dst, src, sz, bos (dst))
kono
parents:
diff changeset
14 #define strncat(dst, src, sz) __builtin___strncat_chk (dst, src, sz, bos (dst))
kono
parents:
diff changeset
15 #define stpncpy(dst, src, sz) __builtin___stpncpy_chk (dst, src, sz, bos (dst))
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 struct A { short a, b; int c, d; long e, f; };
kono
parents:
diff changeset
18 typedef struct A TA;
kono
parents:
diff changeset
19 typedef struct A *PA;
kono
parents:
diff changeset
20 typedef TA *PTA;
kono
parents:
diff changeset
21 struct B {};
kono
parents:
diff changeset
22 typedef struct B TB;
kono
parents:
diff changeset
23 typedef struct B *PB;
kono
parents:
diff changeset
24 typedef TB *PTB;
kono
parents:
diff changeset
25 typedef int X[3][3][3];
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 void
kono
parents:
diff changeset
28 f1 (void *x)
kono
parents:
diff changeset
29 {
kono
parents:
diff changeset
30 struct A a, *pa1 = &a;
kono
parents:
diff changeset
31 TA *pa2 = &a;
kono
parents:
diff changeset
32 PA pa3 = &a;
kono
parents:
diff changeset
33 PTA pa4 = &a;
kono
parents:
diff changeset
34 memset (&a, 0, sizeof (&a)); /* { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" } */
kono
parents:
diff changeset
35 memset (pa1, 0, sizeof (pa1)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
36 memset (pa2, 0, sizeof pa2); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
37 memset (pa3, 0, sizeof (pa3)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
38 memset (pa4, 0, sizeof pa4); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
39 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" } */
kono
parents:
diff changeset
40 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" } */
kono
parents:
diff changeset
41 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" } */
kono
parents:
diff changeset
42 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" } */
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 memcpy (&a, x, sizeof (&a)); /* { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" } */
kono
parents:
diff changeset
45 memcpy (pa1, x, sizeof (pa1)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
46 memcpy (pa2, x, sizeof pa2); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
47 memcpy (pa3, x, sizeof (pa3)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
48 memcpy (pa4, x, sizeof pa4); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
49 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" } */
kono
parents:
diff changeset
50 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" } */
kono
parents:
diff changeset
51 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" } */
kono
parents:
diff changeset
52 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" } */
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 memcpy (x, &a, sizeof (&a)); /* { dg-warning "call is the same expression as the source; did you mean to remove the addressof" } */
kono
parents:
diff changeset
55 memcpy (x, pa1, sizeof (pa1)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
kono
parents:
diff changeset
56 memcpy (x, pa2, sizeof pa2); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
kono
parents:
diff changeset
57 memcpy (x, pa3, sizeof (pa3)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
kono
parents:
diff changeset
58 memcpy (x, pa4, sizeof pa4); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
kono
parents:
diff changeset
59 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" } */
kono
parents:
diff changeset
60 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" } */
kono
parents:
diff changeset
61 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" } */
kono
parents:
diff changeset
62 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" } */
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 memmove (&a, x, sizeof (&a)); /* { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" } */
kono
parents:
diff changeset
65 memmove (pa1, x, sizeof (pa1)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
66 memmove (pa2, x, sizeof pa2); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
67 memmove (pa3, x, sizeof (pa3)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
68 memmove (pa4, x, sizeof pa4); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
69 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" } */
kono
parents:
diff changeset
70 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" } */
kono
parents:
diff changeset
71 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" } */
kono
parents:
diff changeset
72 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" } */
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 memmove (x, &a, sizeof (&a)); /* { dg-warning "call is the same expression as the source; did you mean to remove the addressof" } */
kono
parents:
diff changeset
75 memmove (x, pa1, sizeof (pa1)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
kono
parents:
diff changeset
76 memmove (x, pa2, sizeof pa2); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
kono
parents:
diff changeset
77 memmove (x, pa3, sizeof (pa3)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
kono
parents:
diff changeset
78 memmove (x, pa4, sizeof pa4); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
kono
parents:
diff changeset
79 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" } */
kono
parents:
diff changeset
80 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" } */
kono
parents:
diff changeset
81 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" } */
kono
parents:
diff changeset
82 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" } */
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 /* These are correct, no warning. */
kono
parents:
diff changeset
85 memset (&a, 0, sizeof a);
kono
parents:
diff changeset
86 memset (&a, 0, sizeof (a));
kono
parents:
diff changeset
87 memset (&a, 0, sizeof (struct A));
kono
parents:
diff changeset
88 memset (&a, 0, sizeof (const struct A));
kono
parents:
diff changeset
89 memset (&a, 0, sizeof (volatile struct A));
kono
parents:
diff changeset
90 memset (&a, 0, sizeof (volatile const struct A));
kono
parents:
diff changeset
91 memset (&a, 0, sizeof (TA));
kono
parents:
diff changeset
92 memset (&a, 0, sizeof (__typeof (*&a)));
kono
parents:
diff changeset
93 memset (pa1, 0, sizeof (*pa1));
kono
parents:
diff changeset
94 memset (pa2, 0, sizeof (*pa3));
kono
parents:
diff changeset
95 memset (pa3, 0, sizeof (__typeof (*pa3)));
kono
parents:
diff changeset
96 /* These are probably broken, but obfuscated, no warning. */
kono
parents:
diff changeset
97 memset ((void *) &a, 0, sizeof (&a));
kono
parents:
diff changeset
98 memset ((char *) &a, 0, sizeof (&a));
kono
parents:
diff changeset
99 memset (&a, 0, sizeof (&a) + 0);
kono
parents:
diff changeset
100 memset (&a, 0, 0 + sizeof (&a));
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 /* These are correct, no warning. */
kono
parents:
diff changeset
103 memcpy (&a, x, sizeof a);
kono
parents:
diff changeset
104 memcpy (&a, x, sizeof (a));
kono
parents:
diff changeset
105 memcpy (&a, x, sizeof (struct A));
kono
parents:
diff changeset
106 memcpy (&a, x, sizeof (const struct A));
kono
parents:
diff changeset
107 memcpy (&a, x, sizeof (volatile struct A));
kono
parents:
diff changeset
108 memcpy (&a, x, sizeof (volatile const struct A));
kono
parents:
diff changeset
109 memcpy (&a, x, sizeof (TA));
kono
parents:
diff changeset
110 memcpy (&a, x, sizeof (__typeof (*&a)));
kono
parents:
diff changeset
111 memcpy (pa1, x, sizeof (*pa1));
kono
parents:
diff changeset
112 memcpy (pa2, x, sizeof (*pa3));
kono
parents:
diff changeset
113 memcpy (pa3, x, sizeof (__typeof (*pa3)));
kono
parents:
diff changeset
114 /* These are probably broken, but obfuscated, no warning. */
kono
parents:
diff changeset
115 memcpy ((void *) &a, x, sizeof (&a));
kono
parents:
diff changeset
116 memcpy ((char *) &a, x, sizeof (&a));
kono
parents:
diff changeset
117 memcpy (&a, x, sizeof (&a) + 0);
kono
parents:
diff changeset
118 memcpy (&a, x, 0 + sizeof (&a));
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 /* These are correct, no warning. */
kono
parents:
diff changeset
121 memcpy (x, &a, sizeof a);
kono
parents:
diff changeset
122 memcpy (x, &a, sizeof (a));
kono
parents:
diff changeset
123 memcpy (x, &a, sizeof (struct A));
kono
parents:
diff changeset
124 memcpy (x, &a, sizeof (const struct A));
kono
parents:
diff changeset
125 memcpy (x, &a, sizeof (volatile struct A));
kono
parents:
diff changeset
126 memcpy (x, &a, sizeof (volatile const struct A));
kono
parents:
diff changeset
127 memcpy (x, &a, sizeof (TA));
kono
parents:
diff changeset
128 memcpy (x, &a, sizeof (__typeof (*&a)));
kono
parents:
diff changeset
129 memcpy (x, pa1, sizeof (*pa1));
kono
parents:
diff changeset
130 memcpy (x, pa2, sizeof (*pa3));
kono
parents:
diff changeset
131 memcpy (x, pa3, sizeof (__typeof (*pa3)));
kono
parents:
diff changeset
132 /* These are probably broken, but obfuscated, no warning. */
kono
parents:
diff changeset
133 memcpy (x, (void *) &a, sizeof (&a));
kono
parents:
diff changeset
134 memcpy (x, (char *) &a, sizeof (&a));
kono
parents:
diff changeset
135 memcpy (x, &a, sizeof (&a) + 0);
kono
parents:
diff changeset
136 memcpy (x, &a, 0 + sizeof (&a));
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 /* These are correct, no warning. */
kono
parents:
diff changeset
139 memmove (&a, x, sizeof a);
kono
parents:
diff changeset
140 memmove (&a, x, sizeof (a));
kono
parents:
diff changeset
141 memmove (&a, x, sizeof (struct A));
kono
parents:
diff changeset
142 memmove (&a, x, sizeof (const struct A));
kono
parents:
diff changeset
143 memmove (&a, x, sizeof (volatile struct A));
kono
parents:
diff changeset
144 memmove (&a, x, sizeof (volatile const struct A));
kono
parents:
diff changeset
145 memmove (&a, x, sizeof (TA));
kono
parents:
diff changeset
146 memmove (&a, x, sizeof (__typeof (*&a)));
kono
parents:
diff changeset
147 memmove (pa1, x, sizeof (*pa1));
kono
parents:
diff changeset
148 memmove (pa2, x, sizeof (*pa3));
kono
parents:
diff changeset
149 memmove (pa3, x, sizeof (__typeof (*pa3)));
kono
parents:
diff changeset
150 /* These are probably broken, but obfuscated, no warning. */
kono
parents:
diff changeset
151 memmove ((void *) &a, x, sizeof (&a));
kono
parents:
diff changeset
152 memmove ((char *) &a, x, sizeof (&a));
kono
parents:
diff changeset
153 memmove (&a, x, sizeof (&a) + 0);
kono
parents:
diff changeset
154 memmove (&a, x, 0 + sizeof (&a));
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 /* These are correct, no warning. */
kono
parents:
diff changeset
157 memmove (x, &a, sizeof a);
kono
parents:
diff changeset
158 memmove (x, &a, sizeof (a));
kono
parents:
diff changeset
159 memmove (x, &a, sizeof (struct A));
kono
parents:
diff changeset
160 memmove (x, &a, sizeof (const struct A));
kono
parents:
diff changeset
161 memmove (x, &a, sizeof (volatile struct A));
kono
parents:
diff changeset
162 memmove (x, &a, sizeof (volatile const struct A));
kono
parents:
diff changeset
163 memmove (x, &a, sizeof (TA));
kono
parents:
diff changeset
164 memmove (x, &a, sizeof (__typeof (*&a)));
kono
parents:
diff changeset
165 memmove (x, pa1, sizeof (*pa1));
kono
parents:
diff changeset
166 memmove (x, pa2, sizeof (*pa3));
kono
parents:
diff changeset
167 memmove (x, pa3, sizeof (__typeof (*pa3)));
kono
parents:
diff changeset
168 /* These are probably broken, but obfuscated, no warning. */
kono
parents:
diff changeset
169 memmove (x, (void *) &a, sizeof (&a));
kono
parents:
diff changeset
170 memmove (x, (char *) &a, sizeof (&a));
kono
parents:
diff changeset
171 memmove (x, &a, sizeof (&a) + 0);
kono
parents:
diff changeset
172 memmove (x, &a, 0 + sizeof (&a));
kono
parents:
diff changeset
173 }
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 void
kono
parents:
diff changeset
176 f2 (void *x)
kono
parents:
diff changeset
177 {
kono
parents:
diff changeset
178 struct B b, *pb1 = &b;
kono
parents:
diff changeset
179 TB *pb2 = &b;
kono
parents:
diff changeset
180 PB pb3 = &b;
kono
parents:
diff changeset
181 PTB pb4 = &b;
kono
parents:
diff changeset
182 memset (&b, 0, sizeof (&b)); /* { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" } */
kono
parents:
diff changeset
183 memset (pb1, 0, sizeof (pb1)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
184 memset (pb2, 0, sizeof pb2); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
185 memset (pb3, 0, sizeof (pb3)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
186 memset (pb4, 0, sizeof pb4); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
187 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" } */
kono
parents:
diff changeset
188 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" } */
kono
parents:
diff changeset
189 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" } */
kono
parents:
diff changeset
190 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" } */
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 memcpy (&b, x, sizeof (&b)); /* { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" } */
kono
parents:
diff changeset
193 memcpy (pb1, x, sizeof (pb1)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
194 memcpy (pb2, x, sizeof pb2); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
195 memcpy (pb3, x, sizeof (pb3)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
196 memcpy (pb4, x, sizeof pb4); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
197 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" } */
kono
parents:
diff changeset
198 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" } */
kono
parents:
diff changeset
199 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" } */
kono
parents:
diff changeset
200 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" } */
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 memcpy (x, &b, sizeof (&b)); /* { dg-warning "call is the same expression as the source; did you mean to remove the addressof" } */
kono
parents:
diff changeset
203 memcpy (x, pb1, sizeof (pb1)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
kono
parents:
diff changeset
204 memcpy (x, pb2, sizeof pb2); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
kono
parents:
diff changeset
205 memcpy (x, pb3, sizeof (pb3)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
kono
parents:
diff changeset
206 memcpy (x, pb4, sizeof pb4); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
kono
parents:
diff changeset
207 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" } */
kono
parents:
diff changeset
208 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" } */
kono
parents:
diff changeset
209 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" } */
kono
parents:
diff changeset
210 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" } */
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 memmove (&b, x, sizeof (&b)); /* { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" } */
kono
parents:
diff changeset
213 memmove (pb1, x, sizeof (pb1)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
214 memmove (pb2, x, sizeof pb2); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
215 memmove (pb3, x, sizeof (pb3)); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
216 memmove (pb4, x, sizeof pb4); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
217 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" } */
kono
parents:
diff changeset
218 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" } */
kono
parents:
diff changeset
219 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" } */
kono
parents:
diff changeset
220 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" } */
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 memmove (x, &b, sizeof (&b)); /* { dg-warning "call is the same expression as the source; did you mean to remove the addressof" } */
kono
parents:
diff changeset
223 memmove (x, pb1, sizeof (pb1)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
kono
parents:
diff changeset
224 memmove (x, pb2, sizeof pb2); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
kono
parents:
diff changeset
225 memmove (x, pb3, sizeof (pb3)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
kono
parents:
diff changeset
226 memmove (x, pb4, sizeof pb4); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
kono
parents:
diff changeset
227 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" } */
kono
parents:
diff changeset
228 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" } */
kono
parents:
diff changeset
229 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" } */
kono
parents:
diff changeset
230 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" } */
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 /* These are correct, no warning. */
kono
parents:
diff changeset
233 memset (&b, 0, sizeof b);
kono
parents:
diff changeset
234 memset (&b, 0, sizeof (b));
kono
parents:
diff changeset
235 memset (&b, 0, sizeof (struct B));
kono
parents:
diff changeset
236 memset (&b, 0, sizeof (const struct B));
kono
parents:
diff changeset
237 memset (&b, 0, sizeof (volatile struct B));
kono
parents:
diff changeset
238 memset (&b, 0, sizeof (volatile const struct B));
kono
parents:
diff changeset
239 memset (&b, 0, sizeof (TB));
kono
parents:
diff changeset
240 memset (&b, 0, sizeof (__typeof (*&b)));
kono
parents:
diff changeset
241 memset (pb1, 0, sizeof (*pb1));
kono
parents:
diff changeset
242 memset (pb2, 0, sizeof (*pb3));
kono
parents:
diff changeset
243 memset (pb3, 0, sizeof (__typeof (*pb3)));
kono
parents:
diff changeset
244 /* These are probably broken, but obfuscated, no warning. */
kono
parents:
diff changeset
245 memset ((void *) &b, 0, sizeof (&b));
kono
parents:
diff changeset
246 memset ((char *) &b, 0, sizeof (&b));
kono
parents:
diff changeset
247 memset (&b, 0, sizeof (&b) + 0);
kono
parents:
diff changeset
248 memset (&b, 0, 0 + sizeof (&b));
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 /* These are correct, no warning. */
kono
parents:
diff changeset
251 memcpy (&b, x, sizeof b);
kono
parents:
diff changeset
252 memcpy (&b, x, sizeof (b));
kono
parents:
diff changeset
253 memcpy (&b, x, sizeof (struct B));
kono
parents:
diff changeset
254 memcpy (&b, x, sizeof (const struct B));
kono
parents:
diff changeset
255 memcpy (&b, x, sizeof (volatile struct B));
kono
parents:
diff changeset
256 memcpy (&b, x, sizeof (volatile const struct B));
kono
parents:
diff changeset
257 memcpy (&b, x, sizeof (TB));
kono
parents:
diff changeset
258 memcpy (&b, x, sizeof (__typeof (*&b)));
kono
parents:
diff changeset
259 memcpy (pb1, x, sizeof (*pb1));
kono
parents:
diff changeset
260 memcpy (pb2, x, sizeof (*pb3));
kono
parents:
diff changeset
261 memcpy (pb3, x, sizeof (__typeof (*pb3)));
kono
parents:
diff changeset
262 /* These are probably broken, but obfuscated, no warning. */
kono
parents:
diff changeset
263 memcpy ((void *) &b, x, sizeof (&b));
kono
parents:
diff changeset
264 memcpy ((char *) &b, x, sizeof (&b));
kono
parents:
diff changeset
265 memcpy (&b, x, sizeof (&b) + 0);
kono
parents:
diff changeset
266 memcpy (&b, x, 0 + sizeof (&b));
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 /* These are correct, no warning. */
kono
parents:
diff changeset
269 memcpy (x, &b, sizeof b);
kono
parents:
diff changeset
270 memcpy (x, &b, sizeof (b));
kono
parents:
diff changeset
271 memcpy (x, &b, sizeof (struct B));
kono
parents:
diff changeset
272 memcpy (x, &b, sizeof (const struct B));
kono
parents:
diff changeset
273 memcpy (x, &b, sizeof (volatile struct B));
kono
parents:
diff changeset
274 memcpy (x, &b, sizeof (volatile const struct B));
kono
parents:
diff changeset
275 memcpy (x, &b, sizeof (TB));
kono
parents:
diff changeset
276 memcpy (x, &b, sizeof (__typeof (*&b)));
kono
parents:
diff changeset
277 memcpy (x, pb1, sizeof (*pb1));
kono
parents:
diff changeset
278 memcpy (x, pb2, sizeof (*pb3));
kono
parents:
diff changeset
279 memcpy (x, pb3, sizeof (__typeof (*pb3)));
kono
parents:
diff changeset
280 /* These are probably broken, but obfuscated, no warning. */
kono
parents:
diff changeset
281 memcpy (x, (void *) &b, sizeof (&b));
kono
parents:
diff changeset
282 memcpy (x, (char *) &b, sizeof (&b));
kono
parents:
diff changeset
283 memcpy (x, &b, sizeof (&b) + 0);
kono
parents:
diff changeset
284 memcpy (x, &b, 0 + sizeof (&b));
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 /* These are correct, no warning. */
kono
parents:
diff changeset
287 memmove (&b, x, sizeof b);
kono
parents:
diff changeset
288 memmove (&b, x, sizeof (b));
kono
parents:
diff changeset
289 memmove (&b, x, sizeof (struct B));
kono
parents:
diff changeset
290 memmove (&b, x, sizeof (const struct B));
kono
parents:
diff changeset
291 memmove (&b, x, sizeof (volatile struct B));
kono
parents:
diff changeset
292 memmove (&b, x, sizeof (volatile const struct B));
kono
parents:
diff changeset
293 memmove (&b, x, sizeof (TB));
kono
parents:
diff changeset
294 memmove (&b, x, sizeof (__typeof (*&b)));
kono
parents:
diff changeset
295 memmove (pb1, x, sizeof (*pb1));
kono
parents:
diff changeset
296 memmove (pb2, x, sizeof (*pb3));
kono
parents:
diff changeset
297 memmove (pb3, x, sizeof (__typeof (*pb3)));
kono
parents:
diff changeset
298 /* These are probably broken, but obfuscated, no warning. */
kono
parents:
diff changeset
299 memmove ((void *) &b, x, sizeof (&b));
kono
parents:
diff changeset
300 memmove ((char *) &b, x, sizeof (&b));
kono
parents:
diff changeset
301 memmove (&b, x, sizeof (&b) + 0);
kono
parents:
diff changeset
302 memmove (&b, x, 0 + sizeof (&b));
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 /* These are correct, no warning. */
kono
parents:
diff changeset
305 memmove (x, &b, sizeof b);
kono
parents:
diff changeset
306 memmove (x, &b, sizeof (b));
kono
parents:
diff changeset
307 memmove (x, &b, sizeof (struct B));
kono
parents:
diff changeset
308 memmove (x, &b, sizeof (const struct B));
kono
parents:
diff changeset
309 memmove (x, &b, sizeof (volatile struct B));
kono
parents:
diff changeset
310 memmove (x, &b, sizeof (volatile const struct B));
kono
parents:
diff changeset
311 memmove (x, &b, sizeof (TB));
kono
parents:
diff changeset
312 memmove (x, &b, sizeof (__typeof (*&b)));
kono
parents:
diff changeset
313 memmove (x, pb1, sizeof (*pb1));
kono
parents:
diff changeset
314 memmove (x, pb2, sizeof (*pb3));
kono
parents:
diff changeset
315 memmove (x, pb3, sizeof (__typeof (*pb3)));
kono
parents:
diff changeset
316 /* These are probably broken, but obfuscated, no warning. */
kono
parents:
diff changeset
317 memmove (x, (void *) &b, sizeof (&b));
kono
parents:
diff changeset
318 memmove (x, (char *) &b, sizeof (&b));
kono
parents:
diff changeset
319 memmove (x, &b, sizeof (&b) + 0);
kono
parents:
diff changeset
320 memmove (x, &b, 0 + sizeof (&b));
kono
parents:
diff changeset
321 }
kono
parents:
diff changeset
322
kono
parents:
diff changeset
323 void
kono
parents:
diff changeset
324 f3 (void *x, char *y, int z, X w)
kono
parents:
diff changeset
325 {
kono
parents:
diff changeset
326 unsigned char *y1 = (unsigned char *) __builtin_alloca (z + 16);
kono
parents:
diff changeset
327 char buf1[7];
kono
parents:
diff changeset
328 signed char buf2[z + 32];
kono
parents:
diff changeset
329 long buf3[17];
kono
parents:
diff changeset
330 int *buf4[9];
kono
parents:
diff changeset
331 signed char *y2 = buf2;
kono
parents:
diff changeset
332 char c;
kono
parents:
diff changeset
333 char *y3;
kono
parents:
diff changeset
334 memset (y, 0, sizeof (y)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
335 memset (y1, 0, sizeof (y1)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
336 memset (y2, 0, sizeof (y2)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
337 memset (&c, 0, sizeof (&c)); /* { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" } */
kono
parents:
diff changeset
338 memset (w, 0, sizeof w); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
339
kono
parents:
diff changeset
340 memcpy (y, x, sizeof (y)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
341 memcpy (y1, x, sizeof (y1)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
342 memcpy (y2, x, sizeof (y2)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
343 memcpy (&c, x, sizeof (&c)); /* { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" } */
kono
parents:
diff changeset
344 memcpy (w, x, sizeof w); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
345
kono
parents:
diff changeset
346 memcpy (x, y, sizeof (y)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
347 memcpy (x, y1, sizeof (y1)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
348 memcpy (x, y2, sizeof (y2)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
349 memcpy (x, &c, sizeof (&c)); /* { dg-warning "call is the same expression as the source; did you mean to remove the addressof" } */
kono
parents:
diff changeset
350 memcpy (x, w, sizeof w); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
kono
parents:
diff changeset
351
kono
parents:
diff changeset
352 memmove (y, x, sizeof (y)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
353 memmove (y1, x, sizeof (y1)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
354 memmove (y2, x, sizeof (y2)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
355 memmove (&c, x, sizeof (&c)); /* { dg-warning "call is the same expression as the destination; did you mean to remove the addressof" } */
kono
parents:
diff changeset
356 memmove (w, x, sizeof w); /* { dg-warning "call is the same expression as the destination; did you mean to dereference it" } */
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 memmove (x, y, sizeof (y)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
359 memmove (x, y1, sizeof (y1)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
360 memmove (x, y2, sizeof (y2)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
361 memmove (x, &c, sizeof (&c)); /* { dg-warning "call is the same expression as the source; did you mean to remove the addressof" } */
kono
parents:
diff changeset
362 memmove (x, w, sizeof w); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 /* These are correct, no warning. */
kono
parents:
diff changeset
365 memset (y, 0, sizeof (*y));
kono
parents:
diff changeset
366 memset (y1, 0, sizeof (*y2));
kono
parents:
diff changeset
367 memset (buf1, 0, sizeof buf1);
kono
parents:
diff changeset
368 memset (buf3, 0, sizeof (buf3));
kono
parents:
diff changeset
369 memset (&buf3[0], 0, sizeof (buf3));
kono
parents:
diff changeset
370 memset (&buf4[0], 0, sizeof (buf4));
kono
parents:
diff changeset
371 memset (w, 0, sizeof (X));
kono
parents:
diff changeset
372 /* These are probably broken, but obfuscated, no warning. */
kono
parents:
diff changeset
373 memset ((void *) y, 0, sizeof (y));
kono
parents:
diff changeset
374 memset ((char *) y1, 0, sizeof (y2));
kono
parents:
diff changeset
375 memset (y, 0, sizeof (y) + 0);
kono
parents:
diff changeset
376 memset (y1, 0, 0 + sizeof (y2));
kono
parents:
diff changeset
377 memset ((void *) &c, 0, sizeof (&c));
kono
parents:
diff changeset
378 memset ((signed char *) &c, 0, sizeof (&c));
kono
parents:
diff changeset
379 memset (&c, 0, sizeof (&c) + 0);
kono
parents:
diff changeset
380 memset (&c, 0, 0 + sizeof (&c));
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382 /* These are correct, no warning. */
kono
parents:
diff changeset
383 memcpy (y, x, sizeof (*y));
kono
parents:
diff changeset
384 memcpy (y1, x, sizeof (*y2));
kono
parents:
diff changeset
385 memcpy (buf1, x, sizeof buf1);
kono
parents:
diff changeset
386 memcpy (buf3, x, sizeof (buf3));
kono
parents:
diff changeset
387 memcpy (&buf3[0], x, sizeof (buf3));
kono
parents:
diff changeset
388 memcpy (&buf4[0], x, sizeof (buf4));
kono
parents:
diff changeset
389 memcpy (&y3, y, sizeof (y3));
kono
parents:
diff changeset
390 memcpy ((char *) &y3, y, sizeof (y3));
kono
parents:
diff changeset
391 memcpy (w, x, sizeof (X));
kono
parents:
diff changeset
392 /* These are probably broken, but obfuscated, no warning. */
kono
parents:
diff changeset
393 memcpy ((void *) y, x, sizeof (y));
kono
parents:
diff changeset
394 memcpy ((char *) y1, x, sizeof (y2));
kono
parents:
diff changeset
395 memcpy (y, x, sizeof (y) + 0);
kono
parents:
diff changeset
396 memcpy (y1, x, 0 + sizeof (y2));
kono
parents:
diff changeset
397 memcpy ((void *) &c, x, sizeof (&c));
kono
parents:
diff changeset
398 memcpy ((signed char *) &c, x, sizeof (&c));
kono
parents:
diff changeset
399 memcpy (&c, x, sizeof (&c) + 0);
kono
parents:
diff changeset
400 memcpy (&c, x, 0 + sizeof (&c));
kono
parents:
diff changeset
401
kono
parents:
diff changeset
402 /* These are correct, no warning. */
kono
parents:
diff changeset
403 memcpy (x, y, sizeof (*y));
kono
parents:
diff changeset
404 memcpy (x, y1, sizeof (*y2));
kono
parents:
diff changeset
405 memcpy (x, buf1, sizeof buf1);
kono
parents:
diff changeset
406 memcpy (x, buf3, sizeof (buf3));
kono
parents:
diff changeset
407 memcpy (x, &buf3[0], sizeof (buf3));
kono
parents:
diff changeset
408 memcpy (x, &buf4[0], sizeof (buf4));
kono
parents:
diff changeset
409 memcpy (y, &y3, sizeof (y3));
kono
parents:
diff changeset
410 memcpy (y, (char *) &y3, sizeof (y3));
kono
parents:
diff changeset
411 memcpy (x, w, sizeof (X));
kono
parents:
diff changeset
412 /* These are probably broken, but obfuscated, no warning. */
kono
parents:
diff changeset
413 memcpy (x, (void *) y, sizeof (y));
kono
parents:
diff changeset
414 memcpy (x, (char *) y1, sizeof (y2));
kono
parents:
diff changeset
415 memcpy (x, y, sizeof (y) + 0);
kono
parents:
diff changeset
416 memcpy (x, y1, 0 + sizeof (y2));
kono
parents:
diff changeset
417 memcpy (x, (void *) &c, sizeof (&c));
kono
parents:
diff changeset
418 memcpy (x, (signed char *) &c, sizeof (&c));
kono
parents:
diff changeset
419 memcpy (x, &c, sizeof (&c) + 0);
kono
parents:
diff changeset
420 memcpy (x, &c, 0 + sizeof (&c));
kono
parents:
diff changeset
421
kono
parents:
diff changeset
422 /* These are correct, no warning. */
kono
parents:
diff changeset
423 memmove (y, x, sizeof (*y));
kono
parents:
diff changeset
424 memmove (y1, x, sizeof (*y2));
kono
parents:
diff changeset
425 memmove (buf1, x, sizeof buf1);
kono
parents:
diff changeset
426 memmove (buf3, x, sizeof (buf3));
kono
parents:
diff changeset
427 memmove (&buf3[0], x, sizeof (buf3));
kono
parents:
diff changeset
428 memmove (&buf4[0], x, sizeof (buf4));
kono
parents:
diff changeset
429 memmove (&y3, y, sizeof (y3));
kono
parents:
diff changeset
430 memmove ((char *) &y3, y, sizeof (y3));
kono
parents:
diff changeset
431 memmove (w, x, sizeof (X));
kono
parents:
diff changeset
432 /* These are probably broken, but obfuscated, no warning. */
kono
parents:
diff changeset
433 memmove ((void *) y, x, sizeof (y));
kono
parents:
diff changeset
434 memmove ((char *) y1, x, sizeof (y2));
kono
parents:
diff changeset
435 memmove (y, x, sizeof (y) + 0);
kono
parents:
diff changeset
436 memmove (y1, x, 0 + sizeof (y2));
kono
parents:
diff changeset
437 memmove ((void *) &c, x, sizeof (&c));
kono
parents:
diff changeset
438 memmove ((signed char *) &c, x, sizeof (&c));
kono
parents:
diff changeset
439 memmove (&c, x, sizeof (&c) + 0);
kono
parents:
diff changeset
440 memmove (&c, x, 0 + sizeof (&c));
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442 /* These are correct, no warning. */
kono
parents:
diff changeset
443 memmove (x, y, sizeof (*y));
kono
parents:
diff changeset
444 memmove (x, y1, sizeof (*y2));
kono
parents:
diff changeset
445 memmove (x, buf1, sizeof buf1);
kono
parents:
diff changeset
446 memmove (x, buf3, sizeof (buf3));
kono
parents:
diff changeset
447 memmove (x, &buf3[0], sizeof (buf3));
kono
parents:
diff changeset
448 memmove (x, &buf4[0], sizeof (buf4));
kono
parents:
diff changeset
449 memmove (y, &y3, sizeof (y3));
kono
parents:
diff changeset
450 memmove (y, (char *) &y3, sizeof (y3));
kono
parents:
diff changeset
451 memmove (x, w, sizeof (X));
kono
parents:
diff changeset
452 /* These are probably broken, but obfuscated, no warning. */
kono
parents:
diff changeset
453 memmove (x, (void *) y, sizeof (y));
kono
parents:
diff changeset
454 memmove (x, (char *) y1, sizeof (y2));
kono
parents:
diff changeset
455 memmove (x, y, sizeof (y) + 0);
kono
parents:
diff changeset
456 memmove (x, y1, 0 + sizeof (y2));
kono
parents:
diff changeset
457 memmove (x, (void *) &c, sizeof (&c));
kono
parents:
diff changeset
458 memmove (x, (signed char *) &c, sizeof (&c));
kono
parents:
diff changeset
459 memmove (x, &c, sizeof (&c) + 0);
kono
parents:
diff changeset
460 memmove (x, &c, 0 + sizeof (&c));
kono
parents:
diff changeset
461 }
kono
parents:
diff changeset
462
kono
parents:
diff changeset
463 void
kono
parents:
diff changeset
464 f4 (char *x, char **y, int z, char w[64])
kono
parents:
diff changeset
465 {
kono
parents:
diff changeset
466 const char *s1 = "foobarbaz";
kono
parents:
diff changeset
467 const char *s2 = "abcde12345678";
kono
parents:
diff changeset
468 strncpy (x, s1, sizeof (s1)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
469 strncat (x, s2, sizeof (s2)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
470 stpncpy (x, s1, sizeof (s1)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
471
kono
parents:
diff changeset
472 strncpy (w, s1, sizeof (w)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
473 strncat (w, s2, sizeof (w)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
474 stpncpy (w, s1, sizeof (w)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
kono
parents:
diff changeset
475
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
476 /* These are pointless when the destination is large enough, and
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
477 cause overflow otherwise. If the copies are guaranteed to be
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
478 safe the calls might as well be replaced by strcat(), strcpy(),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
479 or memcpy(). */
111
kono
parents:
diff changeset
480 const char s3[] = "foobarbaz";
kono
parents:
diff changeset
481 const char s4[] = "abcde12345678";
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
482 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?" } */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
483 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?" } */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
484 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?" } */
111
kono
parents:
diff changeset
485 }
kono
parents:
diff changeset
486
kono
parents:
diff changeset
487 /* { dg-prune-output "\[\n\r\]*writing\[\n\r\]*" } */
kono
parents:
diff changeset
488 /* { dg-prune-output "\[\n\r\]*reading\[\n\r\]*" } */