1 /* PR tree-optimization/82588 - missing -Warray-bounds on an excessively
4 { dg-require-effective-target alloca }
5 { dg-options "-O2 -Warray-bounds -ftrack-macro-expansion=0" } */
7 #define SIZE_MAX __SIZE_MAX__
8 #define DIFF_MAX __PTRDIFF_MAX__
9 #define DIFF_MIN (-DIFF_MAX - 1)
11 typedef __PTRDIFF_TYPE__
ptrdiff_t;
12 typedef __SIZE_TYPE__
size_t;
14 static ptrdiff_t signed_value (void)
16 extern volatile ptrdiff_t signed_value_source
;
17 return signed_value_source
;
20 static ptrdiff_t signed_range (ptrdiff_t min
, ptrdiff_t max
)
22 ptrdiff_t val
= signed_value ();
23 return val
< min
|| max
< val
? min
: val
;
26 typedef struct AX
{ int n
; char ax
[]; } AX
;
28 typedef struct A1
{ int i
; char a1
[1]; } A1
;
29 typedef struct B
{ int i
; struct A1 a1x
[]; } B
;
33 #define T(expr) sink (0, (expr))
35 void test_vla (unsigned m
, unsigned n
)
39 T (vla1
[DIFF_MIN
]); /* { dg-warning "array subscript -\[0-9\]+ is below array bounds" "vla" } */
40 T (vla1
[-1]); /* { dg-warning "array subscript -1 is below array bounds" "vla" } */
44 /* It would be nice to diagnose this. */
45 T (vla1
[m
]); /* { dg-warning "array subscript \[0-9\]+ is above array bounds" "bug 82608" { xfail *-*-*} } */
46 T (vla1
[DIFF_MAX
- 1]);
47 T (vla1
[DIFF_MAX
]); /* { dg-warning "array subscript \[0-9\]+ is above array bounds" "vla" } */
49 ptrdiff_t i
= signed_range (DIFF_MAX
- 1, DIFF_MAX
);
54 T (vla2
[0][DIFF_MIN
]); /* { dg-warning "array subscript -\[0-9\]+ is below array bounds" "vla" } */
55 T (vla2
[0][-1]); /* { dg-warning "array subscript -1 is below array bounds" "vla" } */
58 T (vla2
[m
- 1][n
- 1]);
59 /* It would be nice to diagnose this. */
60 T (vla2
[m
][0]); /* { dg-warning "array subscript \[0-9\]+ is above array bounds" "bug 82608" { xfail *-*-*} } */
61 T (vla2
[m
+ 1][0]); /* { dg-warning "array subscript \[0-9\]+ is above array bounds" "bug 82608" { xfail *-*-*} } */
62 T (vla2
[0][n
]); /* { dg-warning "array subscript \[0-9\]+ is above array bounds" "bug 82608" { xfail *-*-*} } */
63 T (vla2
[0][n
+ 1]); /* { dg-warning "array subscript \[0-9\]+ is above array bounds" "bug 82608" { xfail *-*-*} } */
64 T (vla2
[m
][n
]); /* { dg-warning "array subscript \[0-9\]+ is above array bounds" "bug 82608" { xfail *-*-*} } */
65 T (vla2
[m
+ 1][n
+ 1]); /* { dg-warning "array subscript \[0-9\]+ is above array bounds" "bug 82608" { xfail *-*-*} } */
67 T (vla2
[0][DIFF_MAX
]); /* { dg-warning "array subscript \[0-9\]+ is above array bounds" "vla" } */
68 T (vla2
[DIFF_MAX
][0]); /* { dg-warning "array subscript \[0-9\]+ is above array bounds" "vla" { xfail *-*-* } } */
69 T (vla2
[DIFF_MAX
][DIFF_MAX
]); /* { dg-warning "array subscript \[0-9\]+ is above array bounds" "vla" } */
71 struct S256
{ char a
[256]; } vla3
[m
];
73 T (vla3
[DIFF_MIN
].a
[0]); /* { dg-warning "array subscript -\[0-9\]+ is below array bounds" "vla" } */
74 T (vla3
[-1].a
[0]); /* { dg-warning "array subscript -1 is below array bounds" "vla" } */
78 T (vla3
[DIFF_MAX
/ 256 - 1].a
[0]);
79 T (vla3
[DIFF_MAX
/ 256].a
[0]); /* { dg-warning "array subscript \[0-9\]+ is above array bounds" "vla" } */
81 i
= signed_range (DIFF_MAX
/ 256 - 1, DIFF_MAX
);
84 i
= signed_range (DIFF_MAX
/ 256, DIFF_MAX
);
85 T (vla3
[i
].a
[0]); /* { dg-warning "array subscript \[0-9\]+ is above array bounds" "vla" } */
87 struct VLA
{ char vla
[n
]; } x
;
89 T (x
.vla
[DIFF_MIN
]); /* { dg-warning "array subscript -\[0-9\]+ is below array bounds" "vla" } */
90 T (x
.vla
[-1]); /* { dg-warning "array subscript -1 is below array bounds" "vla" } */
94 T (x
.vla
[DIFF_MAX
- 1]);
95 T (x
.vla
[DIFF_MAX
]); /* { dg-warning "array subscript \[0-9\]+ is above array bounds" "vla" } */