1 /* PR middle-end/92341 - missing -Warray-bounds indexing past the end
4 { dg-options "-O2 -Wall -ftrack-macro-expansion=0" } */
8 #define INT_MAX __INT_MAX__
9 #define INT_MIN (-__INT_MAX__ - 1)
14 #define T(...) sink (__LINE__, (__VA_ARGS__))
17 void direct_idx_cst (void)
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]'" }
23 T ((int[]){ 1 }[-1]); // { dg-warning "array subscript -1 is below array bounds of 'int\\\[1]'" }
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]'" }
32 void direct_idx_var (int i
)
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]'" }
39 void direct_idx_range (void)
41 ptrdiff_t i
= SR (-2, -1);
43 T ((int[]){ 1 }[i
]); // { dg-warning "array subscript \[ \n\r]+ is outside array bounds of 'int\\\[0]'" "pr?????" { xfail *-*-* } }
48 #define T(idx, ...) do { \
49 int *p = (__VA_ARGS__); \
53 void ptr_idx_cst (void)
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]'" }
59 T (-1, (int[]){ 1 }); // { dg-warning "array subscript -1 is outside array bounds of '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]'" }
69 void ptr_idx_var (int i
)
71 T (i
, (int[]){ }); // { dg-warning "array subscript \[^\n\r\]+ is outside array bounds of 'int\\\[0]'" }
73 T (i
, (int[]){ i
, 1 });
76 void ptr_idx_range (void)
78 ptrdiff_t i
= SR (-2, -1);
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]'" }
86 T (i
, (int[]){ }); // { dg-warning "array subscript 0 is outside array bounds of 'int\\\[0]'" }
90 T (i
, (int[]){ 1 }); // { dg-warning "array subscript 1 is outside array bounds of 'int\\\[1]'" }
93 T (i
, (int[]){ 1, 2, 3 });
96 T (i
, (int[]){ 2, 3, 4 }); // { dg-warning "array subscript 3 is outside array bounds of 'int\\\[3]'" }
99 /* Some of the invalid accesses above also trigger -Wuninitialized.
100 { dg-prune-output "\\\[-Wuninitialized" } */