]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/Warray-bounds-80.c
1 /* PR tree-optimization/101397 - spurious warning writing to the result
4 { dg-options "-O2 -Wall" } */
6 char* stpcpy (char*, const char*);
10 extern char ax
[], a3
[3], a5
[5], *s
;
14 void test_stpcpy (int i
)
17 char *p
= stpcpy (ax
, s
);
18 x
= p
[-9]; // { dg-bogus "\\\[-Warray-bounds" }
19 x
= p
[-1]; // { dg-bogus "\\\[-Warray-bounds" }
25 char *p
= stpcpy (a3
, s
);
26 x
= p
[-2]; // { dg-bogus "\\\[-Warray-bounds" }
27 x
= p
[-1]; // { dg-bogus "\\\[-Warray-bounds" }
31 char *p
= stpcpy (a3
, s
);
32 x
= p
[-3]; // { dg-warning "\\\[-Warray-bounds" }
33 sink (p
[-2], p
[-1], p
[0], p
[1], p
[2]);
34 x
= p
[ 3]; // { dg-warning "\\\[-Warray-bounds" }
38 /* Stpcpy always returns a pointer to the copied nul (which must
39 exist) and never a past-the-end pointer. As a result, P below
40 is in [a5, a5 + 4]. */
41 char *p
= stpcpy (a5
, s
);
42 x
= p
[-5]; // { dg-warning "\\\[-Warray-bounds" }
43 sink (p
[-4], p
[-3], p
[-2], p
[-1], p
[0]);
44 sink (p
[1], p
[2], p
[3], p
[4]);
45 x
= p
[ 5]; // { dg-warning "\\\[-Warray-bounds" }
49 char *p
= stpcpy (a5
+ 1, s
);
50 x
= p
[-5]; // { dg-warning "\\\[-Warray-bounds" }
51 sink (p
[-4], p
[-3], p
[-2], p
[-1], p
[0]);
52 sink (p
[1], p
[2], p
[3]);
53 x
= p
[ 4]; // { dg-warning "\\\[-Warray-bounds" }
57 char *p
= stpcpy (a5
+ 2, s
);
58 x
= p
[-5]; // { dg-warning "\\\[-Warray-bounds" }
59 sink (p
[-4], p
[-3], p
[-2], p
[-1], p
[0]);
61 x
= p
[ 3]; // { dg-warning "\\\[-Warray-bounds" }
65 char *p
= stpcpy (a5
+ 3, s
);
66 x
= p
[-5]; // { dg-warning "\\\[-Warray-bounds" }
67 sink (p
[-4], p
[-3], p
[-2], p
[-1], p
[0]);
69 x
= p
[ 2]; // { dg-warning "\\\[-Warray-bounds" }
73 /* Because strlen (a3) is at most 2, the stpcpy call must return
74 a pointer in the range [ax, ax + 2], and so -3 is necessarily
76 char *p
= stpcpy (ax
, a3
);
77 p
[-3] = 1; // { dg-warning "\\\[-Warray-bounds" }
84 char *p
= stpcpy (a3
, s
);
85 x
= p
[i
]; // { dg-bogus "\\\[-Warray-bounds" }
92 char *p
= stpcpy (a3
, s
);
93 p
[i
] = 1; // { dg-warning "\\\[-Warray-bounds" }