1 /* PR middle-end/97188 - ICE passing a null VLA to a function expecting
2 at least one element
3 { dg-do compile }
4 { dg-options "-O -Wall -ftrack-macro-expansion=0" } */
5
6 #define INT_MAX __INT_MAX__
7 #define INT_MIN (-INT_MAX - 1)
8
9 /* Exercise passing nul to a one-dimensional VLA argument. */
10
11 void test_fca_n (int r_m1)
12 {
13 extern void fca_n (int n, char[n]); // { dg-message "in a call to function 'fca_n'" "note" }
14
15 #define T(n) fca_n (n, 0)
16
17 int min = INT_MIN;
18 int max = INT_MAX;
19 if (r_m1 >= 0)
20 r_m1 = -1;
21
22 // Verify negative bounds.
23 T (min); // { dg-warning "bound argument 1 value -\\d+ is negative for a variable length array argument 2 of type 'char\\\[n]'" }
24 T (r_m1); // { dg-warning "bound argument 1 value \\\[-\\d+, -1] is negative for a variable length array argument 2 of type 'char\\\[n]" }
25 T ( -1); // { dg-warning "bound argument 1 value -1 is negative for a variable length array argument 2 of type 'char\\\[n]" }
26
27 T ( 0);
28
29 // Verify positive bounds.
30 T ( 1); // { dg-warning "argument 2 of variable length array 'char\\\[n]' is null but the corresponding bound argument 1 value is 1" }
31 T ( 9); // { dg-warning "argument 2 of variable length array 'char\\\[n]' is null but the corresponding bound argument 1 value is 9" }
32 T (max); // { dg-warning "argument 2 of variable length array 'char\\\[n]' is null but the corresponding bound argument 1 value is \\d+" }
33 }
34
35
36 /* Exercise passing nul to an array with unspecified bound of VLAs. */
37
38 void test_fsa_x_n (int r_m1)
39 {
40 extern void fsa_x_n (int n, short[][n]); // { dg-message "in a call to function 'fsa_x_n'" "note" }
41
42 #undef T
43 #define T(n) fsa_x_n (n, 0)
44
45 int min = INT_MIN;
46 int max = INT_MAX;
47 if (r_m1 >= 0)
48 r_m1 = -1;
49
50 // Verify negative bounds.
51 T (min); // { dg-warning "bound argument 1 value -\\d+ is negative for a variable length array argument 2 of type 'short int\\\[]\\\[n]'" }
52 T (r_m1); // { dg-warning "bound argument 1 value \\\[-\\d+, -1] is negative for a variable length array argument 2 of type 'short int\\\[]\\\[n]" }
53 T ( -1); // { dg-warning "bound argument 1 value -1 is negative for a variable length array argument 2 of type 'short int\\\[]\\\[n]" }
54
55 T ( 0);
56
57 // Verify positive bounds.
58 T ( 1); // { dg-warning "argument 2 of variable length array 'short int\\\[]\\\[n]' is null but the corresponding bound argument 1 value is 1" }
59 T ( 9); // { dg-warning "argument 2 of variable length array 'short int\\\[]\\\[n]' is null but the corresponding bound argument 1 value is 9" }
60 T (max); // { dg-warning "argument 2 of variable length array 'short int\\\[]\\\[n]' is null but the corresponding bound argument 1 value is \\d+" }
61 }
62
63
64 /* Exercise passing nul to an array of a single VLA. */
65
66 void test_fia_1_n (int r_m1)
67 {
68 extern void fia_1_n (int n, int[1][n]); // { dg-message "in a call to function 'fia_1_n'" "note" }
69
70 #undef T
71 #define T(n) fia_1_n (n, 0)
72
73 int min = INT_MIN;
74 int max = INT_MAX;
75 if (r_m1 >= 0)
76 r_m1 = -1;
77
78 // Verify negative bounds.
79 T (min); // { dg-warning "bound argument 1 value -\\d+ is negative for a variable length array argument 2 of type 'int\\\[1]\\\[n]'" }
80 T (r_m1); // { dg-warning "bound argument 1 value \\\[-\\d+, -1] is negative for a variable length array argument 2 of type 'int\\\[1]\\\[n]" }
81 T ( -1); // { dg-warning "bound argument 1 value -1 is negative for a variable length array argument 2 of type 'int\\\[1]\\\[n]" }
82
83 T ( 0);
84
85 // Verify positive bounds.
86 T ( 1); // { dg-warning "argument 2 of variable length array 'int\\\[1]\\\[n]' is null but the corresponding bound argument 1 value is 1" }
87 T ( 9); // { dg-warning "argument 2 of variable length array 'int\\\[1]\\\[n]' is null but the corresponding bound argument 1 value is 9" }
88 T (max); // { dg-warning "argument 2 of variable length array 'int\\\[1]\\\[n]' is null but the corresponding bound argument 1 value is \\d+" }
89 }
90
91
92 /* Exercise passing nul to an array of three VLAs. */
93
94 void test_fla_3_n (int r_m1)
95 {
96 extern void fla_3_n (int n, long[3][n]); // { dg-message "in a call to function 'fla_3_n'" "note" }
97
98 #undef T
99 #define T(n) fla_3_n (n, 0)
100
101 int min = INT_MIN;
102 int max = INT_MAX;
103 if (r_m1 >= 0)
104 r_m1 = -1;
105
106 // Verify negative bounds.
107 T (min); // { dg-warning "bound argument 1 value -\\d+ is negative for a variable length array argument 2 of type 'long int\\\[3]\\\[n]'" }
108 T (r_m1); // { dg-warning "bound argument 1 value \\\[-\\d+, -1] is negative for a variable length array argument 2 of type 'long int\\\[3]\\\[n]" }
109 T ( -1); // { dg-warning "bound argument 1 value -1 is negative for a variable length array argument 2 of type 'long int\\\[3]\\\[n]" }
110
111 T ( 0);
112
113 // Verify positive bounds.
114 T ( 1); // { dg-warning "argument 2 of variable length array 'long int\\\[3]\\\[n]' is null but the corresponding bound argument 1 value is 1" }
115 T ( 9); // { dg-warning "argument 2 of variable length array 'long int\\\[3]\\\[n]' is null but the corresponding bound argument 1 value is 9" }
116 T (max); // { dg-warning "argument 2 of variable length array 'long int\\\[3]\\\[n]' is null but the corresponding bound argument 1 value is \\d+" }
117 }
118
119
120 /* Exercise passing nul to a VLA of five-element arrays. */
121
122 void test_fda_n_5 (int r_m1)
123 {
124 extern void fda_n_5 (int n, double[n][5]);// { dg-message "in a call to function 'fda_n_5'" "note" }
125
126 #undef T
127 #define T(n) fda_n_5 (n, 0)
128
129 int min = INT_MIN;
130 int max = INT_MAX;
131 if (r_m1 >= 0)
132 r_m1 = -1;
133
134 // Verify negative bounds.
135 T (min); // { dg-warning "bound argument 1 value -\\d+ is negative for a variable length array argument 2 of type 'double\\\[n]\\\[5]'" }
136 T (r_m1); // { dg-warning "bound argument 1 value \\\[-\\d+, -1] is negative for a variable length array argument 2 of type 'double\\\[n]\\\[5]" }
137 T ( -1); // { dg-warning "bound argument 1 value -1 is negative for a variable length array argument 2 of type 'double\\\[n]\\\[5]" }
138
139 T ( 0);
140
141 // Verify positive bounds.
142 T ( 1); // { dg-warning "argument 2 of variable length array 'double\\\[n]\\\[5]' is null but the corresponding bound argument 1 value is 1" }
143 T ( 9); // { dg-warning "argument 2 of variable length array 'double\\\[n]\\\[5]' is null but the corresponding bound argument 1 value is 9" }
144 T (max); // { dg-warning "argument 2 of variable length array 'double\\\[n]\\\[5]' is null but the corresponding bound argument 1 value is \\d+" }
145 }
146
147
148 /* Exercise passing nul to a two-dimensional VLA. */
149
150 void test_fca_n_n (int r_m1)
151 {
152 extern void fca_n_n (int n, char[n][n]); // { dg-message "in a call to function 'fca_n_n'" "note" }
153
154 #undef T
155 #define T(n) fca_n_n (n, 0)
156
157 int min = INT_MIN;
158 int max = INT_MAX;
159 if (r_m1 >= 0)
160 r_m1 = -1;
161
162 // Verify negative bounds.
163 T (min); // { dg-warning "bound argument 1 value -\\d+ is negative for a variable length array argument 2 of type 'char\\\[n]\\\[n]'" }
164 T (r_m1); // { dg-warning "bound argument 1 value \\\[-\\d+, -1] is negative for a variable length array argument 2 of type 'char\\\[n]\\\[n]" }
165 T ( -1); // { dg-warning "bound argument 1 value -1 is negative for a variable length array argument 2 of type 'char\\\[n]\\\[n]" }
166
167 T ( 0);
168
169 // Verify positive bounds.
170 T ( 1); // { dg-warning "argument 2 of variable length array 'char\\\[n]\\\[n]' is null but the corresponding bound argument 1 value is 1" }
171 T ( 9); // { dg-warning "argument 2 of variable length array 'char\\\[n]\\\[n]' is null but the corresponding bound argument 1 value is 9" }
172 T (max); // { dg-warning "argument 2 of variable length array 'char\\\[n]\\\[n]' is null but the corresponding bound argument 1 value is \\d+" }
173 }