1 /* PR middle-end/100137 - -Warray-bounds false positive on varying offset
2 plus negative
3 { dg-do compile }
4 { dg-options "-O2 -Wall" } */
5
6 extern char ax[], a1[1], a2[2], a3[3], a4[4], a5[5];
7
8 int* ptr;
9 #define X (*ptr++)
10
11
12 __attribute__ ((noipa)) void
13 array_plus_var_minus_cstint (int i, int j)
14 {
15 {
16 const char *p = ax;
17 p += i;
18 X = p[-1];
19 X = p[-123];
20 }
21
22 {
23 const char *p = a1;
24 p += i;
25 X = p[-1]; // { dg-bogus "\\\[-Warray-bounds" }
26 X = p[-2]; // { dg-warning "\\\[-Warray-bounds" }
27 X = p[-3]; // { dg-warning "\\\[-Warray-bounds" }
28 X = p[-4]; // { dg-warning "\\\[-Warray-bounds" }
29 }
30
31 {
32 const char *p = a2;
33 p += i;
34 X = p[-1]; // { dg-bogus "\\\[-Warray-bounds" }
35 X = p[-2]; // { dg-bogus "\\\[-Warray-bounds" }
36 X = p[-3]; // { dg-warning "\\\[-Warray-bounds" }
37 X = p[-4]; // { dg-warning "\\\[-Warray-bounds" }
38 }
39
40 {
41 const char *p = a3;
42 p += i;
43 X = p[-1]; // { dg-bogus "\\\[-Warray-bounds" }
44 X = p[-2]; // { dg-bogus "\\\[-Warray-bounds" }
45 X = p[-3]; // { dg-bogus "\\\[-Warray-bounds" }
46 X = p[-4]; // { dg-warning "\\\[-Warray-bounds" }
47 X = p[-5]; // { dg-warning "\\\[-Warray-bounds" }
48 }
49
50 {
51 const char *p = a4;
52 p += i;
53 X = p[-1]; // { dg-bogus "\\\[-Warray-bounds" }
54 X = p[-2]; // { dg-bogus "\\\[-Warray-bounds" }
55 X = p[-3]; // { dg-bogus "\\\[-Warray-bounds" }
56 X = p[-4]; // { dg-bogus "\\\[-Warray-bounds" }
57 X = p[-5]; // { dg-warning "\\\[-Warray-bounds" }
58 X = p[-6]; // { dg-warning "\\\[-Warray-bounds" }
59 }
60
61 {
62 const char *p = a5;
63 p += i;
64 p += j;
65 X = p[-1]; // { dg-bogus "\\\[-Warray-bounds" }
66 X = p[-2]; // { dg-bogus "\\\[-Warray-bounds" }
67 X = p[-3]; // { dg-bogus "\\\[-Warray-bounds" }
68 X = p[-4]; // { dg-bogus "\\\[-Warray-bounds" }
69 X = p[-5]; // { dg-bogus "\\\[-Warray-bounds" }
70 X = p[-6]; // { dg-warning "\\\[-Warray-bounds" }
71 }
72 }
73
74
75 __attribute__ ((noipa)) void
76 array_plus_var_minus_cstlong (long i, long j)
77 {
78 {
79 const char *p = ax;
80 p += i;
81 X = p[-1];
82 X = p[-123];
83 }
84
85 {
86 const char *p = a1;
87 p += i;
88 X = p[-1]; // { dg-bogus "\\\[-Warray-bounds" }
89 X = p[-2]; // { dg-warning "\\\[-Warray-bounds" }
90 X = p[-3]; // { dg-warning "\\\[-Warray-bounds" }
91 X = p[-4]; // { dg-warning "\\\[-Warray-bounds" }
92 }
93
94 {
95 const char *p = a2;
96 p += i;
97 X = p[-1]; // { dg-bogus "\\\[-Warray-bounds" }
98 X = p[-2]; // { dg-bogus "\\\[-Warray-bounds" }
99 X = p[-3]; // { dg-warning "\\\[-Warray-bounds" }
100 X = p[-4]; // { dg-warning "\\\[-Warray-bounds" }
101 }
102
103 {
104 const char *p = a3;
105 p += i;
106 X = p[-1]; // { dg-bogus "\\\[-Warray-bounds" }
107 X = p[-2]; // { dg-bogus "\\\[-Warray-bounds" }
108 X = p[-3]; // { dg-bogus "\\\[-Warray-bounds" }
109 X = p[-4]; // { dg-warning "\\\[-Warray-bounds" }
110 X = p[-5]; // { dg-warning "\\\[-Warray-bounds" }
111 }
112
113 {
114 const char *p = a4;
115 p += i;
116 X = p[-1]; // { dg-bogus "\\\[-Warray-bounds" }
117 X = p[-2]; // { dg-bogus "\\\[-Warray-bounds" }
118 X = p[-3]; // { dg-bogus "\\\[-Warray-bounds" }
119 X = p[-4]; // { dg-bogus "\\\[-Warray-bounds" }
120 X = p[-5]; // { dg-warning "\\\[-Warray-bounds" }
121 X = p[-6]; // { dg-warning "\\\[-Warray-bounds" }
122 }
123
124 {
125 const char *p = a5;
126 p += i;
127 p += j;
128 X = p[-1]; // { dg-bogus "\\\[-Warray-bounds" }
129 X = p[-2]; // { dg-bogus "\\\[-Warray-bounds" }
130 X = p[-3]; // { dg-bogus "\\\[-Warray-bounds" }
131 X = p[-4]; // { dg-bogus "\\\[-Warray-bounds" }
132 X = p[-5]; // { dg-bogus "\\\[-Warray-bounds" }
133 X = p[-6]; // { dg-warning "\\\[-Warray-bounds" }
134 }
135 }