gcc/java/
[official-gcc.git] / gcc / testsuite / gcc.dg / Warray-bounds.c
blob44120392c73b79b4eb28409cf853874ca27c5113
1 /* { dg-do compile } */
2 /* { dg-options "-O2 -Warray-bounds" } */
4 int a[10];
6 static inline int n(void) {
7 __SIZE_TYPE__ strlen(const char *s);
8 return strlen("12345");
11 void g(int *p);
12 void h(int p);
14 int* f(void) {
15 int b[10];
16 int i;
17 struct {
18 int c[10];
19 } c;
21 a[-1] = 0; /* { dg-warning "6:array subscript" } */
22 a[ 0] = 0;
23 a[ 1] = 0;
26 a[ 9] = 0;
27 a[10] = 0; /* { dg-warning "6:array subscript" } */
28 a[11] = 0; /* { dg-warning "6:array subscript" } */
29 a[2 * n() - 11] = 1; /* { dg-warning "6:array subscript" } */
30 a[2 * n() - 10] = 1;
31 a[2 * n() - 1] = 1;
32 a[2 * n() - 0] = 1; /* { dg-warning "6:array subscript" } */
34 b[-1] = 0; /* { dg-warning "6:array subscript" } */
35 b[ 0] = 0;
36 b[ 1] = 0;
37 b[ 9] = 0;
38 b[10] = 0; /* { dg-warning "6:array subscript" } */
39 b[11] = 0; /* { dg-warning "6:array subscript" } */
40 b[2 * n() - 11] = 1; /* { dg-warning "6:array subscript" } */
41 b[2 * n() - 10] = 1;
42 b[2 * n() - 1] = 1;
43 b[2 * n() - 0] = 1; /* { dg-warning "array subscript" } */
45 c.c[-1] = 0; /* { dg-warning "8:array subscript" } */
46 c.c[ 0] = 0;
47 c.c[ 1] = 0;
48 c.c[ 9] = 0;
49 c.c[10] = 0; /* { dg-warning "8:array subscript" } */
50 c.c[11] = 0; /* { dg-warning "8:array subscript" } */
51 c.c[2 * n() - 11] = 1; /* { dg-warning "8:array subscript" } */
52 c.c[2 * n() - 10] = 1;
53 c.c[2 * n() - 1] = 1;
54 c.c[2 * n() - 0] = 1; /* { dg-warning "8:array subscript" } */
56 g(&a[8]);
57 g(&a[9]);
58 g(&a[10]);
59 g(&a[11]); /* { dg-warning "array subscript" "" { xfail *-*-* } } */
60 g(&a[-30]+10); /* { dg-warning "array subscript" } */
61 g(&a[-30]+30);
63 g(&b[10]);
64 g(&c.c[10]);
65 g(&b[11]); /* { dg-warning "array subscript" "" { xfail *-*-* } } */
66 g(&c.c[11]); /* { dg-warning "array subscript" } */
68 g(&a[0]);
69 g(&b[0]);
70 g(&c.c[0]);
72 g(&a[-1]); /* { dg-warning "array subscript" } */
73 g(&b[-1]); /* { dg-warning "array subscript" } */
74 h(sizeof a[-1]);
75 h(sizeof a[10]);
76 h(sizeof b[-1]);
77 h(sizeof b[10]);
78 h(sizeof c.c[-1]);
79 h(sizeof c.c[10]);
81 if (10 < 10)
82 a[10] = 0;
83 if (10 < 10)
84 b[10] = 0;
85 if (-1 >= 0)
86 c.c[-1] = 0;
88 for (i = 20; i < 30; ++i)
89 a[i] = 1; /* { dg-warning "15:array subscript" } */
91 return a;