comparison gcc/testsuite/gcc.dg/Warray-bounds-27.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents
children
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 /* { dg-do compile }
2 { dg-options "-O2 -Wall -Wextra -Warray-bounds -Wrestrict" } */
3
4 typedef __SIZE_TYPE__ size_t;
5
6 extern void* memcpy (void* restrict, const void* restrict, size_t);
7
8 extern void sink (void*, ...);
9
10 struct Data {
11 size_t n;
12 void *p;
13 };
14
15 void test_copy (void)
16 {
17 struct Data d;
18 sink (&d);
19
20 char dp1[sizeof d + 1];
21 char d2x[2 * sizeof d];
22 char d2xp1[2 * sizeof d + 1];
23
24 /* During development the following would incorrectly trigger:
25 warning: 'memcpy' forming offset [17, 25] is out of the bounds [0, 16]
26 of object ā€˜dā€™ with type 'struct Data' [-Warray-bounds]
27 that wasn't caught by the test suite. Make sure it is. */
28 memcpy (&dp1, d.p, sizeof dp1); /* { dg-bogus "\\\[-Warray-bounds" } */
29
30 /* Likewise. */
31 memcpy (&d2x, d.p, sizeof d2x); /* { dg-bogus "\\\[-Warray-bounds" } */
32 memcpy (&d2xp1, d.p, sizeof d2xp1); /* { dg-bogus "\\\[-Warray-bounds" } */
33
34 sink (&d, &dp1, &d2x, &d2xp1);
35 }