| 1 |
/* PR tree-optimization/101397 - spurious warning writing to the result |
| 2 |
of stpcpy minus 1 |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-O2 -Wall" } */ |
| 5 |
|
| 6 |
char* strcpy (char*, const char*); |
| 7 |
|
| 8 |
void sink (int, ...); |
| 9 |
|
| 10 |
extern char ax[], a3[3], a5[5], *s; |
| 11 |
|
| 12 |
volatile int x; |
| 13 |
|
| 14 |
void test_strcpy (int i) |
| 15 |
{ |
| 16 |
{ |
| 17 |
char *p = strcpy (ax, s); |
| 18 |
x = p[-1]; // { dg-warning "\\\[-Warray-bounds" } |
| 19 |
x = p[ 0]; |
| 20 |
x = p[+9]; |
| 21 |
} |
| 22 |
|
| 23 |
{ |
| 24 |
char *p = strcpy (a3, s); |
| 25 |
x = p[-1]; // { dg-warning "\\\[-Warray-bounds" } |
| 26 |
x = p[0]; |
| 27 |
x = p[1]; |
| 28 |
x = p[2]; |
| 29 |
x = p[3]; // { dg-warning "\\\[-Warray-bounds" } |
| 30 |
} |
| 31 |
|
| 32 |
{ |
| 33 |
char *p = strcpy (a5, s); |
| 34 |
x = p[-1]; // { dg-warning "\\\[-Warray-bounds" } |
| 35 |
sink (p[0], p[1], p[2], p[3], p[4]); |
| 36 |
x = p[ 5]; // { dg-warning "\\\[-Warray-bounds" } |
| 37 |
} |
| 38 |
|
| 39 |
{ |
| 40 |
char *p = strcpy (a5 + 1, s); |
| 41 |
x = p[-2]; // { dg-warning "\\\[-Warray-bounds" } |
| 42 |
sink (p[-1], p[0], p[1], p[2], p[3]); |
| 43 |
x = p[4]; // { dg-warning "\\\[-Warray-bounds" } |
| 44 |
} |
| 45 |
|
| 46 |
{ |
| 47 |
char *p = strcpy (a5 + 2, s); |
| 48 |
x = p[-3]; // { dg-warning "\\\[-Warray-bounds" } |
| 49 |
sink (p[-2], p[-1], p[0], p[1], p[2]); |
| 50 |
x = p[3]; // { dg-warning "\\\[-Warray-bounds" } |
| 51 |
} |
| 52 |
|
| 53 |
{ |
| 54 |
char *p = strcpy (a5 + 3, s); |
| 55 |
x = p[-4]; // { dg-warning "\\\[-Warray-bounds" } |
| 56 |
sink (p[-3], p[-2], p[-1], p[0], p[1]); |
| 57 |
x = p[2]; // { dg-warning "\\\[-Warray-bounds" } |
| 58 |
} |
| 59 |
|
| 60 |
{ |
| 61 |
char *p = strcpy (ax, a3); |
| 62 |
p[-1] = 1; // { dg-warning "\\\[-Warray-bounds" } |
| 63 |
sink (p[0], p[1], p[2], p[9], p[99]); |
| 64 |
} |
| 65 |
} |