Use this fact in some foldings of comparisons. See testcase.
Showing the changes to tests (1 of 2 files). Show all
Unified · Split
| @@ -1470,6 +1470,10 @@ typedef int arrtype2[3]; · 1469 unmodified lines | |||
| 1470 | arrtype2 sinit21 = {4}; | 1470 | arrtype2 sinit21 = {4}; |
| 1471 | arrtype2 sinit22 = {5,6,7}; | 1471 | arrtype2 sinit22 = {5,6,7}; |
| 1472 | 1472 | ||
| 1473 | /* Address comparisons of non-weak symbols with zero can be const-folded */ | ||
| 1474 | int sinit23[2] = { "astring" ? sizeof("astring") : -1, | ||
| 1475 | &sinit23 ? 42 : -1 }; | ||
| 1476 | |||
| 1473 | void init_test(void) | 1477 | void init_test(void) |
| 1474 | { | 1478 | { |
| 1475 | int linit1 = 2; | 1479 | int linit1 = 2; |
| @@ -1484,6 +1488,9 @@ void init_test(void) · 8 unmodified lines | |||
| 1484 | int linit15[10] = { linit1, linit1 + 1, [6] = linit1 + 2, }; | 1488 | int linit15[10] = { linit1, linit1 + 1, [6] = linit1 + 2, }; |
| 1485 | struct linit16 { int a1, a2, a3, a4; } linit16 = { 1, .a3 = 2 }; | 1489 | struct linit16 { int a1, a2, a3, a4; } linit16 = { 1, .a3 = 2 }; |
| 1486 | int linit17 = sizeof(linit17); | 1490 | int linit17 = sizeof(linit17); |
| 1491 | int zero = 0; | ||
| 1492 | /* Addresses on non-weak symbols are non-zero, but not the access itself */ | ||
| 1493 | int linit18[2] = {&zero ? 1 : -1, zero ? -1 : 1 }; | ||
| 1487 | 1494 | ||
| 1488 | printf("init_test:\n"); | 1495 | printf("init_test:\n"); |
| 1489 | 1496 | ||
| @@ -1577,6 +1584,9 @@ void init_test(void) · 87 unmodified lines | |||
| 1577 | printf("arrtype4: %d %d %d\n", sinit22[0], sinit22[1], sinit22[2]); | 1584 | printf("arrtype4: %d %d %d\n", sinit22[0], sinit22[1], sinit22[2]); |
| 1578 | printf("arrtype5: %d %d\n", sizeof(sinit21), sizeof(sinit22)); | 1585 | printf("arrtype5: %d %d\n", sizeof(sinit21), sizeof(sinit22)); |
| 1579 | printf("arrtype6: %d\n", sizeof(arrtype2)); | 1586 | printf("arrtype6: %d\n", sizeof(arrtype2)); |
| 1587 | |||
| 1588 | printf("sinit23= %d %d\n", sinit23[0], sinit23[1]); | ||
| 1589 | printf("linit18= %d %d\n", linit18[0], linit18[1]); | ||
| 1580 | } | 1590 | } |
| 1581 | 1591 | ||
| 1582 | 1592 | ||