1 /* { dg-do compile } */
2 /* { dg-options "-O3 -Warray-bounds=2" } */
4 typedef __SIZE_TYPE__
size_t;
5 extern void* malloc(size_t x
);
9 struct f
{ int f
[3]; };
11 extern void bar(int v
[]);
60 (*a
)[4] = 1; /* { dg-warning "subscript is above array bound" } */
63 a
[1][4] = 1; /* { dg-warning "subscript is above array bound" } */
67 c
[4] = 1; /* { dg-warning "subscript is above array bound" } */
69 e
[4] = 1; /* { dg-warning "subscript is above array bound" } */
72 f
.f
[4] = 1; /* { dg-warning "subscript is above array bound" } */
74 struct h
* h
= malloc(sizeof(struct h
) + 3 * sizeof(int));
75 struct h0
* h0
= malloc(sizeof(struct h0
) + 3 * sizeof(int));
76 struct h1
* h1
= malloc(sizeof(struct h1
) + 3 * sizeof(int));
77 struct h3
* h3
= malloc(sizeof(struct h3
));
79 h
->j
[4] = 1; // flexible array member
80 h0
->j
[4] = 1; // zero-sized array extension
81 h1
->j
[4] = 1; /* { dg-warning "subscript is above array bound" } */
82 h3
->j
[4] = 1; /* { dg-warning "subscript is above array bound" } */
84 struct h0b
* h0b
= malloc(sizeof(struct h
) + 3 * sizeof(int));
85 struct h1b
* h1b
= malloc(sizeof(struct h1b
) + 3 * sizeof(int));
86 struct h3b
* h3b
= malloc(sizeof(struct h3b
));
88 h1b
->j
[4] = 1;; /* { dg-warning "subscript is above array bound" } */
89 h3b
->j
[4] = 1;; /* { dg-warning "subscript is above array bound" } */
91 // make sure nothing gets optimized away