1 /* { dg-do compile } */
2 /* { dg-options "-O2 -Warray-bounds" } */
3
4 int a[10];
5
n(void)6 static inline int n(void) {
7 __SIZE_TYPE__ strlen(const char *s);
8 return strlen("12345");
9 }
10
11 void g(int *p);
12 void h(int p);
13
14 void bar (void *);
15
f(void)16 int* f(void) {
17 int b[10];
18 int i;
19 struct {
20 int c[10];
21 } c;
22
23 a[-1] = 0; /* { dg-warning "6:array subscript" } */
24 a[ 0] = 0;
25 a[ 1] = 0;
26
27
28 a[ 9] = 0;
29 a[10] = 0; /* { dg-warning "6:array subscript" } */
30 a[11] = 0; /* { dg-warning "6:array subscript" } */
31 bar (a);
32 a[2 * n() - 11] = 1; /* { dg-warning "6:array subscript" } */
33 a[2 * n() - 10] = 1;
34 a[2 * n() - 1] = 1;
35 a[2 * n() - 0] = 1; /* { dg-warning "6:array subscript" } */
36 bar (a);
37
38 b[-1] = 0; /* { dg-warning "6:array subscript" } */
39 b[ 0] = 0;
40 b[ 1] = 0;
41 b[ 9] = 0;
42 b[10] = 0; /* { dg-warning "6:array subscript" } */
43 b[11] = 0; /* { dg-warning "6:array subscript" } */
44 bar (b);
45 b[2 * n() - 11] = 1; /* { dg-warning "6:array subscript" } */
46 b[2 * n() - 10] = 1;
47 b[2 * n() - 1] = 1;
48 b[2 * n() - 0] = 1; /* { dg-warning "array subscript" } */
49
50 c.c[-1] = 0; /* { dg-warning "8:array subscript" } */
51 c.c[ 0] = 0;
52 c.c[ 1] = 0;
53 c.c[ 9] = 0;
54 c.c[10] = 0; /* { dg-warning "8:array subscript" } */
55 c.c[11] = 0; /* { dg-warning "8:array subscript" } */
56 bar (&c);
57 c.c[2 * n() - 11] = 1; /* { dg-warning "8:array subscript" } */
58 c.c[2 * n() - 10] = 1;
59 c.c[2 * n() - 1] = 1;
60 c.c[2 * n() - 0] = 1; /* { dg-warning "8:array subscript" } */
61
62 g(&a[8]);
63 g(&a[9]);
64 g(&a[10]);
65 g(&a[11]); /* { dg-warning "array subscript" } */
66 g(&a[-30]+10); /* { dg-warning "array subscript" } */
67 g(&a[-30]+30);
68
69 g(&b[10]);
70 g(&c.c[10]);
71 g(&b[11]); /* { dg-warning "array subscript" } */
72 g(&c.c[11]); /* { dg-warning "array subscript" } */
73
74 g(&a[0]);
75 g(&b[0]);
76 g(&c.c[0]);
77
78 g(&a[-1]); /* { dg-warning "array subscript" } */
79 g(&b[-1]); /* { dg-warning "array subscript" } */
80 h(sizeof a[-1]);
81 h(sizeof a[10]);
82 h(sizeof b[-1]);
83 h(sizeof b[10]);
84 h(sizeof c.c[-1]);
85 h(sizeof c.c[10]);
86
87 if (10 < 10)
88 a[10] = 0;
89 if (10 < 10)
90 b[10] = 0;
91 if (-1 >= 0)
92 c.c[-1] = 0;
93
94 for (i = 20; i < 30; ++i)
95 a[i] = 1; /* { dg-warning "15:array subscript" } */
96
97 bar (b);
98 bar (&c);
99 return a;
100 }
101
102