| 1 |
/* PR middle-end/93829 - bogus -Wstringop-overflow on memcpy of a struct |
| 2 |
with a pointer member from another with a long string |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-O2 -Wall" } */ |
| 5 |
|
| 6 |
extern void* memcpy (void*, const void*, __SIZE_TYPE__); |
| 7 |
|
| 8 |
#define S40 "0123456789012345678901234567890123456789" |
| 9 |
|
| 10 |
const char s40[] = S40; |
| 11 |
|
| 12 |
struct S |
| 13 |
{ |
| 14 |
const void *p, *q, *r; |
| 15 |
} s, sa[2]; |
| 16 |
|
| 17 |
|
| 18 |
void test_lit_decl (void) |
| 19 |
{ |
| 20 |
struct S t = { 0, S40, 0 }; |
| 21 |
|
| 22 |
memcpy (&s, &t, sizeof t); // { dg-bogus "-Wstringop-overflow" } |
| 23 |
} |
| 24 |
|
| 25 |
void test_str_decl (void) |
| 26 |
{ |
| 27 |
struct S t = { 0, s40, 0 }; |
| 28 |
|
| 29 |
memcpy (&s, &t, sizeof t); // { dg-bogus "-Wstringop-overflow" } |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
void test_lit_ssa (int i) |
| 34 |
{ |
| 35 |
if (i < 1) |
| 36 |
i = 1; |
| 37 |
struct S *p = &sa[i]; |
| 38 |
struct S t = { 0, S40, 0 }; |
| 39 |
|
| 40 |
memcpy (p, &t, sizeof t); // { dg-bogus "-Wstringop-overflow" } |
| 41 |
} |
| 42 |
|
| 43 |
void test_str_ssa (int i) |
| 44 |
{ |
| 45 |
if (i < 1) |
| 46 |
i = 1; |
| 47 |
struct S *p = &sa[i]; |
| 48 |
struct S t = { 0, s40, 0 }; |
| 49 |
|
| 50 |
memcpy (p, &t, sizeof t); // { dg-bogus "-Wstringop-overflow" } |
| 51 |
} |