]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/Warray-bounds-82.c
1 /* PR tree-optimization/101397 - spurious warning writing to the result
3 Verify warnings for indexing into a pointer returned from mempcpy.
4 The call mempcpy(S1, S2, N) returns &S1[N].
6 { dg-options "-O2 -Wall" } */
8 typedef __SIZE_TYPE__
size_t;
10 void* mempcpy (void*, const void*, size_t);
12 extern char ax
[], a3
[3], a5
[5], a7
[7], *s
;
16 /* Verify warnings for indexing into the result of mempcpy with a source
17 pointing to an array of unknown bound. */
19 void test_mempcpy_from_ptr (int i
)
22 char *p
= mempcpy (ax
, s
, 5);
23 x
= p
[-6]; // { dg-warning "\\\[-Warray-bounds" }
31 char *p
= mempcpy (a5
, s
, 3);
32 x
= p
[-4]; // { dg-warning "\\\[-Warray-bounds" }
38 x
= p
[ 2]; // { dg-warning "\\\[-Warray-bounds" }
42 char *p
= mempcpy (a5
, s
, 4);
43 x
= p
[-5]; // { dg-warning "\\\[-Warray-bounds" }
49 x
= p
[ 1]; // { dg-warning "\\\[-Warray-bounds" }
53 char *p
= mempcpy (a5
, s
, 4);
68 x
= p
[i
]; // { dg-warning "\\\[-Warray-bounds" }
72 /* Verify warnings for indexing into the result of mempcpy with a source
73 an array of size 5. */
75 void test_mempcpy_from_a5 (int i
, int n
, int n3_9
)
78 // The returned pointer is ax + 3 as specified by the bound.
79 char *p
= mempcpy (ax
, a5
, 3);
80 x
= p
[-4]; // { dg-warning "\\\[-Warray-bounds" }
89 // The returned pointer is ax + 5.
90 char *p
= mempcpy (ax
, a5
, 5);
91 x
= p
[-6]; // { dg-warning "\\\[-Warray-bounds" }
99 //The returned pointer is in [ax, ax + 5] even though n is not known.
100 char *p
= mempcpy (ax
, a5
, n
);
101 x
= p
[-6]; // { dg-warning "\\\[-Warray-bounds" }
110 // The returned pointer is a3 + 3.
111 char *p
= mempcpy (a3
, a5
, 3);
112 x
= p
[-4]; // { dg-warning "\\\[-Warray-bounds" }
115 x
= p
[ 0]; // { dg-warning "\\\[-Warray-bounds" }
116 x
= p
[ 1]; // { dg-warning "\\\[-Warray-bounds" }
120 // The returned pointer is in [a3, a3 + 3].
121 char *p
= mempcpy (a3
, a5
, n
);
122 x
= p
[-4]; // { dg-warning "\\\[-Warray-bounds" }
128 x
= p
[ 3]; // { dg-warning "\\\[-Warray-bounds" }
132 if (n3_9
< 3 || 9 < n3_9
)
135 // The returned pointer is a3.
136 char *p
= mempcpy (a3
, a5
, n3_9
);
137 x
= p
[-4]; // { dg-warning "\\\[-Warray-bounds" }
141 x
= p
[ 0]; // { dg-warning "\\\[-Warray-bounds" }
145 char *p
= mempcpy (a3
, a5
, 3);
157 x
= p
[i
]; // { dg-warning "\\\[-Warray-bounds" }
162 /* Verify warnings for indexing into the result of mempcpy with a source
163 an array of size 7. */
165 void test_mempcpy_from_a7 (int i
, int n
, int n3_9
)
168 // The returned pointer is ax + 5.
169 char *p
= mempcpy (ax
, a7
, 5);
170 x
= p
[-6]; // { dg-warning "\\\[-Warray-bounds" }
178 //The returned pointer is in [ax, ax + 7] even though n is not known.
179 char *p
= mempcpy (ax
, a7
, n
);
180 x
= p
[-8]; // { dg-warning "\\\[-Warray-bounds" }
189 // The returned pointer is a5 + 3 as specified by the bound.
190 char *p
= mempcpy (a5
, a7
, 3);
191 x
= p
[-4]; // { dg-warning "\\\[-Warray-bounds" }
196 x
= p
[ 2]; // { dg-warning "\\\[-Warray-bounds" }
200 // The returned pointer is a5 + 4.
201 char *p
= mempcpy (a5
, a7
, 4);
202 x
= p
[-5]; // { dg-warning "\\\[-Warray-bounds" }
208 x
= p
[ 1]; // { dg-warning "\\\[-Warray-bounds" }
212 // The returned pointer is in [a5, a5 + 5].
213 char *p
= mempcpy (a5
, a7
, n
);
214 x
= p
[-6]; // { dg-warning "\\\[-Warray-bounds" }
221 x
= p
[ 5]; // { dg-warning "\\\[-Warray-bounds" }
225 if (n3_9
< 3 || 9 < n3_9
)
228 // The returned pointer is in [a5 + 3, a5 + 5].
229 char *p
= mempcpy (a5
, a7
, n3_9
);
230 x
= p
[-6]; // { dg-warning "\\\[-Warray-bounds" }
237 x
= p
[ 2]; // { dg-warning "\\\[-Warray-bounds" }
241 char *p
= mempcpy (a5
, a7
, 4);
256 x
= p
[i
]; // { dg-warning "\\\[-Warray-bounds" }