145
|
1 /* PR middle-end/92341 - missing -Warray-bounds indexing past the end
|
|
2 of a compound literal
|
|
3 { dg-do compile }
|
|
4 { dg-options "-O2 -Wall -ftrack-macro-expansion=0" } */
|
|
5
|
|
6 #include "range.h"
|
|
7
|
|
8 #define INT_MAX __INT_MAX__
|
|
9 #define INT_MIN (-__INT_MAX__ - 1)
|
|
10
|
|
11 void sink (int, ...);
|
|
12
|
|
13
|
|
14 #define T(...) sink (__LINE__, (__VA_ARGS__))
|
|
15
|
|
16
|
|
17 void direct_idx_cst (void)
|
|
18 {
|
|
19 T ((int[]){ }[-1]); // { dg-warning "array subscript -1 is outside array bounds of 'int\\\[0]'" }
|
|
20 T ((int[]){ }[0]); // { dg-warning "array subscript 0 is outside array bounds of 'int\\\[0]'" }
|
|
21 T ((int[]){ }[1]); // { dg-warning "array subscript 1 is outside array bounds of 'int\\\[0]'" }
|
|
22
|
|
23 T ((int[]){ 1 }[-1]); // { dg-warning "array subscript -1 is below array bounds of 'int\\\[1]'" }
|
|
24 T ((int[]){ 1 }[0]);
|
|
25 T ((int[]){ 1 }[1]); // { dg-warning "array subscript 1 is above array bounds of 'int\\\[1]'" }
|
|
26 T ((int[]){ 1 }[INT_MIN]); // { dg-warning "array subscript -\[0-9\]+ is below array bounds of 'int\\\[1]'" }
|
|
27 T ((int[]){ 1 }[INT_MAX]); // { dg-warning "array subscript \[0-9\]+ is above array bounds of 'int\\\[1]'" }
|
|
28 T ((int[]){ 1 }[SIZE_MAX]); // { dg-warning "array subscript \[0-9\]+ is above array bounds of 'int\\\[1]'" }
|
|
29 }
|
|
30
|
|
31
|
|
32 void direct_idx_var (int i)
|
|
33 {
|
|
34 T ((char[]){ }[i]); // { dg-warning "array subscript i is outside array bounds of 'char\\\[0]'" }
|
|
35 T ((int[]){ }[i]); // { dg-warning "array subscript i is outside array bounds of 'int\\\[0]'" }
|
|
36 }
|
|
37
|
|
38
|
|
39 void direct_idx_range (void)
|
|
40 {
|
|
41 ptrdiff_t i = SR (-2, -1);
|
|
42
|
|
43 T ((int[]){ 1 }[i]); // { dg-warning "array subscript \[ \n\r]+ is outside array bounds of 'int\\\[0]'" "pr?????" { xfail *-*-* } }
|
|
44 }
|
|
45
|
|
46
|
|
47 #undef T
|
|
48 #define T(idx, ...) do { \
|
|
49 int *p = (__VA_ARGS__); \
|
|
50 sink (p[idx]); \
|
|
51 } while (0)
|
|
52
|
|
53 void ptr_idx_cst (void)
|
|
54 {
|
|
55 T (-1, (int[]){ }); // { dg-warning "array subscript -1 is outside array bounds of 'int\\\[0]'" }
|
|
56 T ( 0, (int[]){ }); // { dg-warning "array subscript 0 is outside array bounds of 'int\\\[0]'" }
|
|
57 T (+1, (int[]){ }); // { dg-warning "array subscript 1 is outside array bounds of 'int\\\[0]'" }
|
|
58
|
|
59 T (-1, (int[]){ 1 }); // { dg-warning "array subscript -1 is outside array bounds of 'int\\\[1]'" }
|
|
60 T ( 0, (int[]){ 1 });
|
|
61 T (+1, (int[]){ 1 }); // { dg-warning "array subscript 1 is outside array bounds of 'int\\\[1]'" }
|
|
62 T (INT_MIN, (int[]){ 1 }); // { dg-warning "array subscript -\[0-9\]+ is outside array bounds of 'int\\\[1]'" "pr92381" { xfail ilp32 } }
|
|
63 T (INT_MAX, (int[]){ 1 }); // { dg-warning "array subscript \[0-9\]+ is outside array bounds of 'int\\\[1]'" "pr92381" { xfail ilp32 } }
|
|
64 // { dg-warning "array subscript -\[0-9\]+ is outside array bounds of 'int\\\[1]'" "" { target ilp32 } .-1 }
|
|
65 T (SIZE_MAX, (int[]){ 1 }); // { dg-warning "array subscript -?\[0-9\]+ is outside array bounds of 'int\\\[1]'" }
|
|
66 }
|
|
67
|
|
68
|
|
69 void ptr_idx_var (int i)
|
|
70 {
|
|
71 T (i, (int[]){ }); // { dg-warning "array subscript \[^\n\r\]+ is outside array bounds of 'int\\\[0]'" }
|
|
72 T (i, (int[]){ 1 });
|
|
73 T (i, (int[]){ i, 1 });
|
|
74 }
|
|
75
|
|
76 void ptr_idx_range (void)
|
|
77 {
|
|
78 ptrdiff_t i = SR (-2, -1);
|
|
79
|
|
80 T (i, (int[]){ }); // { dg-warning "array subscript \\\[-2, -1] is outside array bounds of 'int\\\[0]'" }
|
|
81 T (i, (int[]){ 1 }); // { dg-warning "array subscript \\\[-2, -1] is outside array bounds of 'int\\\[1]'" }
|
|
82 T (i, (int[]){ i }); // { dg-warning "array subscript \\\[-2, -1] is outside array bounds of 'int\\\[1]'" }
|
|
83
|
|
84 i = SR (0, 1);
|
|
85
|
|
86 T (i, (int[]){ }); // { dg-warning "array subscript \\\[0, 1] is outside array bounds of 'int\\\[0]'" }
|
|
87 T (i, (int[]){ 1 });
|
|
88
|
|
89 i = SR (1, 2);
|
|
90 T (i, (int[]){ 1 }); // { dg-warning "array subscript \\\[1, 2] is outside array bounds of 'int\\\[1]'" }
|
|
91
|
|
92 i = SR (2, 3);
|
|
93 T (i, (int[]){ 1, 2, 3 });
|
|
94
|
|
95 i = SR (3, 4);
|
|
96 T (i, (int[]){ 2, 3, 4 }); // { dg-warning "array subscript \\\[3, 4] is outside array bounds of 'int\\\[3]'" }
|
|
97 }
|