Debian Codegraph @

gcc/testsuite/gcc.dg/Warray-bounds-49.c

raw
1 /* PR middle-end/91647 - missing -Warray-bounds accessing a zero-length array
2 of a declared object
3 { dg-do "compile" }
4 { dg-options "-O2 -Wall" } */
5
6 struct __attribute__ ((aligned (16))) A16
7 {
8 __INT64_TYPE__ i8;
9 __INT16_TYPE__ i2;
10 __INT16_TYPE__ a2[];
11 };
12
13 struct A16 a0 = { };
14
15 void test_a0 (void)
16 {
17 // The first three elements fit in the tail padding.
18 a0.a2[0] = 0; a0.a2[1] = 1; a0.a2[2] = 2;
19
20 a0.a2[3] = 3; // { dg-warning "array subscript 3 is above array bounds of 'short int\\\[]'" "" { target { ! short_eq_int } } }
21 // { dg-warning "array subscript 3 is above array bounds of 'int\\\[]'" "" { target { short_eq_int } } .-1 }
22 }
23
24
25 struct A16 a1 = { .a2 = { 1 } };
26
27 void test_a1 (void)
28 {
29 a1.a2[0] = 0; a1.a2[1] = 1; a1.a2[2] = 2;
30
31 a1.a2[3] = 3; // { dg-warning "array subscript 3 is above array bounds of 'short int\\\[]'" "" { target { ! short_eq_int } } }
32 // { dg-warning "array subscript 3 is above array bounds of 'int\\\[]'" "" { target { short_eq_int } } .-1 }
33 }
34
35
36 struct A16 a2 = { .a2 = { 1, 2 } };
37
38 void test_a2 (void)
39 {
40 a2.a2[0] = 0; a2.a2[1] = 1; a2.a2[2] = 2;
41
42 a2.a2[3] = 3; // { dg-warning "array subscript 3 is above array bounds of 'short int\\\[]'" "" { target { ! short_eq_int } } }
43 // { dg-warning "array subscript 3 is above array bounds of 'int\\\[]'" "" { target { short_eq_int } } .-1 }
44 }
45
46
47 struct A16 a3 = { .a2 = { 1, 2, 3 } };
48
49 void test_a3 (void)
50 {
51 a3.a2[0] = 0; a3.a2[1] = 1; a3.a2[2] = 2;
52
53 a3.a2[3] = 3; // { dg-warning "array subscript 3 is above array bounds of 'short int\\\[]'" "" { target { ! short_eq_int } } }
54 // { dg-warning "array subscript 3 is above array bounds of 'int\\\[]'" "" { target { short_eq_int } } .-1 }
55 }
56
57
58 struct A16 a4 = { .a2 = { 1, 2, 3, 4 } };
59
60 void test_a4 (void)
61 {
62 a4.a2[0] = 0; a4.a2[1] = 1; a4.a2[2] = 2; a4.a2[3] = 3;
63
64 a4.a2[4] = 4; // { dg-warning "array subscript 4 is above array bounds of 'short int\\\[]'" "" { target { ! short_eq_int } } }
65 // { dg-warning "array subscript 4 is above array bounds of 'int\\\[]'" "" { target { short_eq_int } } .-1 }
66 }
67
68
69 struct A16 a5 = { .a2 = { 1, 2, 3, 4, 5 } };
70
71 void test_a5 (void)
72 {
73 a5.a2[0] = 0; a5.a2[1] = 1; a5.a2[2] = 2; a5.a2[3] = 3; a5.a2[4] = 4;
74
75 a5.a2[5] = 5; // { dg-warning "array subscript 5 is above array bounds of 'short int\\\[]'" "" { target { ! short_eq_int } } }
76 // { dg-warning "array subscript 5 is above array bounds of 'int\\\[]'" "" { target { short_eq_int } } .-1 }
77 }
78
79
80 struct A16 a6 = { .a2 = { 1, 2, 3, 4, 5, 6 } };
81
82 void test_a6 (void)
83 {
84 a6.a2[0] = 0; a6.a2[1] = 1; a6.a2[2] = 2; a6.a2[3] = 3; a6.a2[4] = 4;
85 a6.a2[5] = 5;
86
87 a6.a2[6] = 6; // { dg-warning "array subscript 6 is above array bounds of 'short int\\\[]'" "" { target { ! short_eq_int } } }
88 // { dg-warning "array subscript 6 is above array bounds of 'int\\\[]'" "" { target { short_eq_int } } .-1 }
89 }
90
91
92 struct A16 a7 = { .a2 = { 1, 2, 3, 4, 5, 6, 7 } };
93
94 void test_a7 (void)
95 {
96 a7.a2[0] = 0; a7.a2[1] = 1; a7.a2[2] = 2; a7.a2[3] = 3; a7.a2[4] = 4;
97 a7.a2[5] = 5; a7.a2[5] = 5; a7.a2[6] = 6;
98
99 a7.a2[7] = 7; // { dg-warning "array subscript 7 is above array bounds of 'short int\\\[]'" "" { target { ! short_eq_int } } }
100 // { dg-warning "array subscript 7 is above array bounds of 'int\\\[]'" "" { target { short_eq_int } } .-1 }
101 }
102
103
104 struct A16 a8 = { .a2 = { 1, 2, 3, 4, 5, 6, 7, 8 } };
105
106 void test_a8 (void)
107 {
108 a8.a2[0] = 0; a8.a2[1] = 1; a8.a2[2] = 2; a8.a2[3] = 3; a8.a2[4] = 4;
109 a8.a2[5] = 5; a8.a2[5] = 5; a8.a2[6] = 6; a8.a2[7] = 7;
110
111 a8.a2[8] = 8; // { dg-warning "array subscript 8 is above array bounds of 'short int\\\[]'" "" { target { ! short_eq_int } } }
112 // { dg-warning "array subscript 8 is above array bounds of 'int\\\[]'" "" { target { short_eq_int } } .-1 }
113 }
114
115
116 struct A16 a9 = { .a2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9 } };
117
118 void test_a9 (void)
119 {
120 a8.a2[0] = 8; a8.a2[1] = 7; a8.a2[2] = 6; a8.a2[3] = 5; a8.a2[4] = 4;
121 a8.a2[5] = 3; a8.a2[5] = 2; a8.a2[6] = 1; a8.a2[7] = 0;
122
123 a8.a2[9] = 8; // { dg-warning "array subscript 9 is above array bounds of 'short int\\\[]'" "" { target { ! short_eq_int } } }
124 // { dg-warning "array subscript 9 is above array bounds of 'int\\\[]'" "" { target { short_eq_int } } .-1 }
125 }