PR tree-optimization/83369 - Missing diagnostics during inlining
[official-gcc.git] / gcc / testsuite / gcc.dg / Warray-bounds-11.c
blobc9fc461942f8230d666e4265392583044154fbde
1 /* { dg-do compile } */
2 /* { dg-options "-O3 -Warray-bounds=2" } */
4 typedef __SIZE_TYPE__ size_t;
5 extern void* malloc(size_t x);
7 int e[3];
9 struct f { int f[3]; };
11 extern void bar(int v[]);
13 struct h {
15 int i;
16 int j[];
19 struct h0 {
21 int i;
22 int j[0];
25 struct h0b {
27 int i;
28 int j[0];
29 int k;
32 struct h1 {
34 int i;
35 int j[1];
38 struct h1b {
40 int i;
41 int j[1];
42 int k;
45 struct h3 {
47 int i;
48 int j[3];
51 struct h3b {
53 int i;
54 int j[3];
55 int k;
58 void foo(int (*a)[3])
60 (*a)[4] = 1; /* { dg-warning "subscript 4 is above array bound" } */
61 a[0][0] = 1; // ok
62 a[1][0] = 1; // ok
63 a[1][4] = 1; /* { dg-warning "subscript 4 is above array bound" } */
65 int c[3] = { 0 };
67 c[4] = 1; /* { dg-warning "subscript 4 is above array bound" } */
69 e[4] = 1; /* { dg-warning "subscript 4 is above array bound" } */
71 struct f f;
72 f.f[4] = 1; /* { dg-warning "subscript 4 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 4 is above array bound" } */
82 h3->j[4] = 1; /* { dg-warning "subscript 4 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));
87 // h0b->j[4] = 1;
88 h1b->j[4] = 1;; /* { dg-warning "subscript 4 is above array bound" } */
89 h3b->j[4] = 1;; /* { dg-warning "subscript 4 is above array bound" } */
91 // make sure nothing gets optimized away
92 bar(*a);
93 bar(c);
94 bar(e);
95 bar(f.f);
96 bar(h1->j);
97 bar(h3->j);
98 bar(h3b->j);
99 bar(h1b->j);
100 bar(h->j);
101 bar(h0->j);