Commit 57c7c3e
committed
Fix the behavior of local array initializer
After observing the implementation of cfront, it appears that the local
array initializer may not generate correct instructions to initialize
all elements.
For example, consider the following code:
int main()
{
int a[5] = {5, 10};
return a[0] + a[1] + a[2] + a[3] + a[4];
}
If the number of elements in the initializer-list is less than the size
of array, the generated instructions only initialize the first elements.
The remaining elements are left uninitialized, which may cause the
return value in the above example to differ from the expected 15.
When the initializer-list is empty, all elements remain uninitialized.
Therefore, this commit improves the cfront to generate more instructions
to initialize all elements of an array exactly.1 parent 018bce6 commit 57c7c3e
1 file changed
+45
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1257 | 1257 | | |
1258 | 1258 | | |
1259 | 1259 | | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
1260 | 1305 | | |
1261 | 1306 | | |
1262 | 1307 | | |
| |||
0 commit comments