1 /* PR middle-end/103215 - bogus -Warray-bounds with two pointers with
2 different offsets each
3 Test for accesses by a user-defined function into the same array
4 through pointers with different offsets each. See Warray-bounds-91.c
5 for the corresponding test exercising -Warray-bounds for direct accesses.
6 { dg-do compile }
7 { dg-options "-O2 -Wall -ftrack-macro-expansion=0" } */
8
9 #define NOIPA __attribute__ ((noipa))
10
11 void sink (int[1]);
12 #define A(p, off) sink (p + off)
13
14 extern int a4[4];
15
16
17 NOIPA void p0_p1 (int i)
18 {
19 int *p0 = a4 + 0;
20 int *p1 = a4 + 1;
21 int *q = i ? p0 : p1;
22 A (q, -2); // { dg-warning "-Wstringop-overflow" }
23 A (q, -1); A (q, 0); A (q, 1); A (q, 2);
24 /* Since q points to a4 and -1 is a valid subscript, +3 must be invalid.
25 But the warning for each subscript is independent of prior subscripts
26 into the same object. That should be improved. */
27 A (q, 3); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
28 A (q, 4); // { dg-warning "-Wstringop-overflow" }
29 }
30
31 NOIPA void p1_p0 (int i)
32 {
33 int *p1 = a4 + 1;
34 int *p0 = a4 + 0;
35 int *q = i ? p0 : p1;
36 A (q, -2); // { dg-warning "-Wstringop-overflow" }
37 A (q, -1); A (q, 0); A (q, 1); A (q, 2);
38 A (q, 3); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
39 A (q, 4); // { dg-warning "-Wstringop-overflow" }
40 }
41
42
43 NOIPA void p1_p2 (int i)
44 {
45 int *p1 = a4 + 1;
46 int *p2 = a4 + 2;
47 int *q = i ? p1 : p2;
48 A (q, -3); // { dg-warning "-Wstringop-overflow" }
49 A (q, -2); A (q, -1); A (q, 0); A (q, 1);
50 A (q, 2); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
51 A (q, 3); // { dg-warning "-Wstringop-overflow" }
52 }
53
54 NOIPA void p2_p1 (int i)
55 {
56 int *p2 = a4 + 2;
57 int *p1 = a4 + 1;
58 int *q = i ? p1 : p2;
59 A (q, -3); // { dg-warning "-Wstringop-overflow" }
60 A (q, -2); A (q, -1); A (q, 0); A (q, 1);
61 A (q, 2); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
62 A (q, 3); // { dg-warning "-Wstringop-overflow" }
63 }
64
65
66 NOIPA void p1_p3 (int i)
67 {
68 int *p1 = a4 + 1;
69 int *p3 = a4 + 3;
70 int *q = i ? p1 : p3;
71 A (q, -4); // { dg-warning "-Wstringop-overflow" }
72 A (q, -3); A (q, -2); A (q, -1); A (q, 0);
73 A (q, 1); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
74 A (q, 2); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
75 A (q, 3); // { dg-warning "-Wstringop-overflow" }
76 }
77
78 NOIPA void p3_p1 (int i)
79 {
80 int *p3 = a4 + 3;
81 int *p1 = a4 + 1;
82 int *q = i ? p1 : p3;
83 A (q, -4); // { dg-warning "-Wstringop-overflow" }
84 A (q, -3); A (q, -2); A (q, -1); A (q, 0);
85 A (q, 1); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
86 A (q, 2); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
87 A (q, 3); // { dg-warning "-Wstringop-overflow" }
88 }
89
90
91 NOIPA void p1_p4 (int i)
92 {
93 int *p1 = a4 + 1;
94 int *p4 = a4 + 4;
95 int *q = i ? p1 : p4;
96 A (q, -5); // { dg-warning "-Wstringop-overflow" }
97 A (q, -4); A (q, -3); A (q, -2); A (q, -1);
98 A (q, 0); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
99 A (q, 1); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
100 A (q, 2); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
101 A (q, 3); // { dg-warning "-Wstringop-overflow" }
102 }
103
104 NOIPA void p4_p1 (int i)
105 {
106 int *p4 = a4 + 4;
107 int *p1 = a4 + 1;
108 int *q = i ? p1 : p4;
109 A (q, -5); // { dg-warning "-Wstringop-overflow" }
110 A (q, -4); A (q, -3); A (q, -2); A (q, -1);
111 A (q, 0); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
112 A (q, 1); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
113 A (q, 2); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
114 A (q, 3); // { dg-warning "-Wstringop-overflow" }
115 }
116
117
118 NOIPA void p0_p1_p2 (int i)
119 {
120 int *p0 = a4 + 0;
121 int *p1 = a4 + 1;
122 int *p2 = a4 + 2;
123 int *q = i < 0 ? p1 : 0 < i ? p2 : p0;
124 A (q, -3); // { dg-warning "-Wstringop-overflow" }
125 A (q, -2); A (q, -1); A (q, 0); A (q, 1);
126 A (q, 2); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
127 A (q, 3); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
128 A (q, 4); // { dg-warning "-Wstringop-overflow" }
129 }
130
131
132 NOIPA void p0_p1_p2_p3_p4 (int i)
133 {
134 int *p0 = a4 + 0;
135 int *p1 = a4 + 1;
136 int *p2 = a4 + 2;
137 int *p3 = a4 + 3;
138 int *p4 = a4 + 4;
139 int *q = i < -1 ? p1 : i < 0 ? p2 : 1 < i ? p4 : 0 < i ? p3 : p0;
140 A (q, -5); // { dg-warning "-Wstringop-overflow" }
141 A (q, -4); A (q, -3); A (q, -2); A (q, -1);
142 A (q, 0); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
143 A (q, 1); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
144 A (q, 2); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
145 A (q, 3); // { dg-warning "-Wstringop-overflow" "pr??????" { xfail *-*-* } }
146 A (q, 4); // { dg-warning "-Wstringop-overflow" }
147 }