c++: Implement for namespace statics CWG 2867 - Order of initialization for structure...
[official-gcc.git] / gcc / testsuite / gcc.dg / Warray-bounds-53.c
blob591cca28d27efc890ba044a140dc28f710c80679
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" } */
6 #include "range.h"
8 #define INT_MAX __INT_MAX__
9 #define INT_MIN (-__INT_MAX__ - 1)
11 void sink (int, ...);
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]'" }
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]'" }
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 *-*-* } }
47 #undef T
48 #define T(idx, ...) do { \
49 int *p = (__VA_ARGS__); \
50 sink (p[idx]); \
51 } while (0)
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]'" }
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]'" }
69 void ptr_idx_var (int i)
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 });
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]'" }
84 i = SR (0, 1);
86 T (i, (int[]){ }); // { dg-warning "array subscript 0 is outside array bounds of 'int\\\[0]'" }
87 T (i, (int[]){ 1 });
89 i = SR (1, 2);
90 T (i, (int[]){ 1 }); // { dg-warning "array subscript 1 is outside array bounds of 'int\\\[1]'" }
92 i = SR (2, 3);
93 T (i, (int[]){ 1, 2, 3 });
95 i = SR (3, 4);
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" } */