1 /* PR tree-optimization/83776: missing -Warray-bounds indexing past the end
3 Test to exercise indices into wide string literals.
5 { dg-options "-O2 -Warray-bounds -ftrack-macro-expansion=0" } */
12 typedef __WCHAR_TYPE__
wchar_t;
18 #define W8 L"12345678"
19 #define W9 L"123456789"
23 #define T(expr) sink (expr)
26 void wide_direct_cst (void)
28 T (W9
[MIN
]); /* { dg-warning "array subscript -\[0-9\]+ is below array bounds of .\[a-z \]+\\\[10]" "bug 86611" { xfail ilp32 } } */
29 T (W9
[-1]); /* { dg-warning "array subscript -1 is below array bounds of .\[a-z \]+\\\[10]" } */
30 T (W9
[11]); /* { dg-warning "array subscript 11 is above array bounds of .\[a-z \]+\\\[10]" } */
31 T (W9
[MAX
]); /* { dg-warning "array subscript \[0-9\]+ is above array bounds of .\[a-z \]+\\\[10]" } */
34 void wide_ptr_deref_cst (void)
36 const wchar_t *p
= W8
+ 9;
37 T (*p
); /* { dg-warning "array subscript 9 is outside array bounds of .\[a-z \]+\\\[9]." } */
38 T (p
[1]); /* { dg-warning "array subscript 10 is outside array bounds of .\[a-z \]+\\\[9]." } */
39 T (p
[99]); /* { dg-warning "array subscript 108 is outside array bounds of .\[a-z \]+\\\[9]." } */
42 void wide_ptr_index_cst (void)
44 const wchar_t *p
= W7
;
47 T (p
[8]); /* { dg-warning "array subscript 8 is outside array bounds of .\[a-z \]+\\\[8]." } */
48 T (p
[99]); /* { dg-warning "array subscript 99 is outside array bounds of .\[a-z \]+\\\[8]." } */
49 T (p
[MAX
]); /* { dg-warning "array subscript -?\[0-9\]+ is outside array bounds of .\[a-z \]+\\\[8]." } */
53 void wide_direct_range (ptrdiff_t i
, size_t j
)
58 T (W9
[SR (MIN
, -9)]); /* { dg-warning "array subscript -9 is below array bounds of .\[a-z \]+\\\[10]" } */
59 T (W9
[SR (MIN
, -1)]); /* { dg-warning "array subscript -1 is below array bounds of .\[a-z \]+\\\[10]" } */
61 T (W9
[SR (-2, -1)]); /* { dg-warning "array subscript -1 is below array bounds of .\[a-z \]+\\\[10]" } */
66 T (W9
[SR (10, 999)]); /* { dg-warning "array subscript 10 is above array bounds of .\[a-z \]+\\\[10]" } */
67 T (W9
[SR (99, MAX
)]); /* { dg-warning "array subscript 99 is above array bounds of .\[a-z \]+\\\[10]" } */
70 void wide_ptr_deref_range (ptrdiff_t i
, size_t j
)
81 T (*p
); /* { dg-warning "array subscript \\\[-9, -1] is outside array bounds of .\[a-z \]+\\\[9]." } */
90 T (*p
); /* { dg-warning "array subscript 9 is outside array bounds of .\[a-z \]+\\\[9]." } */
93 void wide_ptr_index_range (void)
98 T (p
[SR (-9, -1)]); /* { dg-warning "array subscript \\\[-9, -1] is outside array bounds of .\[a-z \]+\\\[8]." } */
102 T (p
[SR (8, 9)]); /* { dg-warning "array subscript 8 is outside array bounds of .\[a-z \]+\\\[8]." } */
105 T (p
[5]); /* { dg-warning "array subscript \\\[9, 11] is outside array bounds of .\[a-z \]+\\\[8]." } */
108 void wide_ptr_index_range_1 (void)
112 const wchar_t *p1
= W2
+ i
;
118 const wchar_t *p1
= W2
+ i
;
124 const wchar_t *p1
= W2
+ i
;
126 T (p1
[2]); /* { dg-warning "array subscript 3 is outside array bounds of .\[a-z \]+\\\[3]." } */
130 void wide_ptr_index_range_chain (void)
134 const wchar_t *p1
= W2
+ i
;
135 const wchar_t *p2
= p1
+ i
;
136 const wchar_t *p3
= p2
+ i
;
138 T (p1
[-3]); /* { dg-warning "array subscript \\\[-2, -1] is outside array bounds of .\[a-z \]+\\\[3]." } */
143 T (p1
[2]); /* { dg-warning "array subscript 3 is outside array bounds of .\[a-z \]+\\\[3]." } */
145 T (p2
[-5]); /* { dg-warning "array subscript \\\[-3, -2] is outside array bounds of .\[a-z \]+\\\[3]." } */
146 T (p2
[-4]); /* { dg-warning "array subscript \\\[-2, -1] is outside array bounds of .\[a-z \]+\\\[3]." } */
149 T (p2
[1]); /* { dg-warning "array subscript 3 is outside array bounds of .\[a-z \]+\\\[3]." } */
151 T (p3
[0]); /* { dg-warning "array subscript 3 is outside array bounds of .\[a-z \]+\\\[3]." } */
152 T (p3
[1]); /* { dg-warning "array subscript 4 is outside array bounds of .\[a-z \]+\\\[3]." } */
153 T (p3
[9999]); /* { dg-warning "array subscript 10002 is outside array bounds of .\[a-z \]+\\\[3]." "" { target size20plus} } */
154 /* { dg-warning "array subscript \\\[-6382, -6379] is outside array bounds of .\[a-z \]+\\\[3]." "" { target { ! size20plus } } .-1 } */
155 /* Large offsets are indistinguishable from negative values. */
156 T (p3
[DIFF_MAX
]); /* { dg-warning "array subscript" "bug" { xfail *-*-* } } */
160 const wchar_t *p1
= W3
+ i
;
161 const wchar_t *p2
= p1
+ i
;
162 const wchar_t *p3
= p2
+ i
;
163 const wchar_t *p4
= p3
+ i
;
165 T (p1
[-3]); /* { dg-warning "array subscript \\\[-2, -1] is outside array bounds of .\[a-z \]+\\\[4]." } */
169 T (p1
[3]); /* { dg-warning "array subscript 4 is outside array bounds of .\[a-z \]+\\\[4]." } */
171 T (p3
[1]); /* { dg-warning "array subscript 4 is outside array bounds of .\[a-z \]+\\\[4]." } */
175 void wide_ptr_index_range_4 (void)
178 const wchar_t *p1
= W4
+ i
;
179 const wchar_t *p2
= p1
+ i
;
180 const wchar_t *p3
= p2
+ i
;
181 const wchar_t *p4
= p3
+ i
;
183 T (p4
[1]); /* { dg-warning "array subscript 5 is outside array bounds of .\[a-z \]+\\\[5]." } */