| 1 |
/* Test to verify that the temporary doesn't trigger a bogus -Warray-bounds |
| 2 |
warning. Distilled from libat_exchange_large_inplace in libatomic/gexch.c. |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-O2 -Wall" } */ |
| 5 |
|
| 6 |
typedef typeof (sizeof 0) size_t; |
| 7 |
|
| 8 |
extern void *memcpy (void*, const void*, size_t); |
| 9 |
|
| 10 |
void libat_exchange_large_inplace (size_t n, void *mptr, void *vptr) |
| 11 |
{ |
| 12 |
char temp[1024]; |
| 13 |
|
| 14 |
size_t i = 0; |
| 15 |
|
| 16 |
for (i = 0; n >= 1024; i += 1024, n -= 1024) |
| 17 |
{ |
| 18 |
memcpy (temp, mptr + i, 1024); |
| 19 |
|
| 20 |
/* The memcpy call below results in the following: |
| 21 |
unsigned long ivtmp.7; |
| 22 |
|
| 23 |
ivtmp.7_4 = (unsigned long) mptr_9(D); |
| 24 |
... |
| 25 |
<bb 4> |
| 26 |
# ivtmp.7_22 = PHI <ivtmp.7_4(3), ivtmp.7_5(4)> |
| 27 |
... |
| 28 |
_1 = (void *) ivtmp.7_22; |
| 29 |
... |
| 30 |
memcpy (_1, _2, 1024); |
| 31 |
|
| 32 |
Treating _1 as a pointer results in the bogus: |
| 33 |
warning: 'memcpy' offset 0 is out of the bounds [0, 8] of object 'ivtmp.7' with type 'long unsigned int' [-Warray-bounds] |
| 34 |
memcpy (mptr + i, vptr + i, 1024); |
| 35 |
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 36 |
*/ |
| 37 |
memcpy (mptr + i, vptr + i, 1024); |
| 38 |
|
| 39 |
memcpy (vptr + i, temp, 1024); |
| 40 |
} |
| 41 |
} |