Commit a82719f
committed
Fix temp var destruction in static initializers
For static vars:
static x as ClassUdt = ClassUdt( 123 )
we produce code like this:
static inited as integer
if inited = FALSE then
inited = TRUE
x.constructor( 123 )
end if
i.e. the initialization code is wrapped in an If block so the variable is
only initialized once.
This did not take temp vars in the initializer expression into account;
they were destroyed by the astBuildBranch() in hWrapInStaticFlag(),
resulting in code like this:
static inited as integer
dim temp as ...
condition = (inited = FALSE)
temp.destructor()
if condition then
inited = TRUE
temp.constructor(...)
x.constructor( temp )
end if
This is obviously broken since the temp var is destroyed too early, before
even being initialized.
To fix this, I adjusted the astBuildBranch() call to no longer call the
dtors, and instead, astDtorListFlush() is now done manually on the
initialization code path. Furthermore, cVarDecl() needs to use LINKs
and a single astAdd() instead of multiple astAdd()s for adding the DECL
node and the initialization code.
Besides initializer expressions, there can also be array bounds expressions
with temp vars in a static var decl (in case of static dynamic arrays),
this also works properly now. (hWrapInStaticFlag() is also used for the
Redim calls used to initialize the static dynamic arrays)
(cherry picked from commit a673e44)1 parent ae0624e commit a82719f
File tree
3 files changed
+120
-15
lines changed- src/compiler
- tests/structs
3 files changed
+120
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
920 | 920 | | |
921 | 921 | | |
922 | 922 | | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
923 | 944 | | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
924 | 948 | | |
925 | 949 | | |
926 | 950 | | |
927 | 951 | | |
928 | | - | |
| 952 | + | |
929 | 953 | | |
930 | 954 | | |
931 | 955 | | |
932 | 956 | | |
933 | 957 | | |
934 | 958 | | |
935 | 959 | | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
936 | 964 | | |
937 | 965 | | |
938 | 966 | | |
| |||
1579 | 1607 | | |
1580 | 1608 | | |
1581 | 1609 | | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
1582 | 1615 | | |
1583 | 1616 | | |
1584 | 1617 | | |
1585 | | - | |
1586 | 1618 | | |
1587 | 1619 | | |
1588 | 1620 | | |
1589 | | - | |
1590 | | - | |
| 1621 | + | |
1591 | 1622 | | |
1592 | 1623 | | |
1593 | 1624 | | |
1594 | 1625 | | |
1595 | 1626 | | |
1596 | 1627 | | |
1597 | | - | |
| 1628 | + | |
1598 | 1629 | | |
1599 | 1630 | | |
1600 | 1631 | | |
| |||
1606 | 1637 | | |
1607 | 1638 | | |
1608 | 1639 | | |
1609 | | - | |
| 1640 | + | |
1610 | 1641 | | |
1611 | 1642 | | |
1612 | 1643 | | |
| |||
1615 | 1646 | | |
1616 | 1647 | | |
1617 | 1648 | | |
1618 | | - | |
| 1649 | + | |
1619 | 1650 | | |
1620 | 1651 | | |
1621 | 1652 | | |
| |||
1626 | 1657 | | |
1627 | 1658 | | |
1628 | 1659 | | |
1629 | | - | |
| 1660 | + | |
1630 | 1661 | | |
1631 | 1662 | | |
1632 | 1663 | | |
1633 | | - | |
| 1664 | + | |
| 1665 | + | |
1634 | 1666 | | |
1635 | 1667 | | |
1636 | 1668 | | |
1637 | | - | |
1638 | | - | |
1639 | 1669 | | |
1640 | 1670 | | |
1641 | | - | |
| 1671 | + | |
1642 | 1672 | | |
1643 | 1673 | | |
1644 | 1674 | | |
1645 | | - | |
| 1675 | + | |
1646 | 1676 | | |
1647 | 1677 | | |
1648 | 1678 | | |
| |||
1664 | 1694 | | |
1665 | 1695 | | |
1666 | 1696 | | |
1667 | | - | |
1668 | | - | |
| 1697 | + | |
1669 | 1698 | | |
| 1699 | + | |
| 1700 | + | |
1670 | 1701 | | |
1671 | 1702 | | |
1672 | 1703 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3222 | 3222 | | |
3223 | 3223 | | |
3224 | 3224 | | |
| 3225 | + | |
| 3226 | + | |
| 3227 | + | |
| 3228 | + | |
| 3229 | + | |
| 3230 | + | |
| 3231 | + | |
| 3232 | + | |
| 3233 | + | |
| 3234 | + | |
| 3235 | + | |
| 3236 | + | |
| 3237 | + | |
| 3238 | + | |
| 3239 | + | |
| 3240 | + | |
| 3241 | + | |
| 3242 | + | |
| 3243 | + | |
| 3244 | + | |
| 3245 | + | |
| 3246 | + | |
| 3247 | + | |
3225 | 3248 | | |
3226 | 3249 | | |
3227 | 3250 | | |
| |||
3284 | 3307 | | |
3285 | 3308 | | |
3286 | 3309 | | |
| 3310 | + | |
| 3311 | + | |
| 3312 | + | |
| 3313 | + | |
| 3314 | + | |
| 3315 | + | |
| 3316 | + | |
| 3317 | + | |
| 3318 | + | |
| 3319 | + | |
3287 | 3320 | | |
3288 | 3321 | | |
3289 | 3322 | | |
| |||
3310 | 3343 | | |
3311 | 3344 | | |
3312 | 3345 | | |
| 3346 | + | |
| 3347 | + | |
| 3348 | + | |
| 3349 | + | |
| 3350 | + | |
| 3351 | + | |
| 3352 | + | |
| 3353 | + | |
| 3354 | + | |
| 3355 | + | |
| 3356 | + | |
| 3357 | + | |
| 3358 | + | |
| 3359 | + | |
| 3360 | + | |
| 3361 | + | |
| 3362 | + | |
| 3363 | + | |
| 3364 | + | |
| 3365 | + | |
| 3366 | + | |
| 3367 | + | |
| 3368 | + | |
| 3369 | + | |
| 3370 | + | |
| 3371 | + | |
| 3372 | + | |
| 3373 | + | |
| 3374 | + | |
| 3375 | + | |
3313 | 3376 | | |
3314 | 3377 | | |
3315 | 3378 | | |
| |||
3362 | 3425 | | |
3363 | 3426 | | |
3364 | 3427 | | |
| 3428 | + | |
| 3429 | + | |
| 3430 | + | |
| 3431 | + | |
| 3432 | + | |
| 3433 | + | |
| 3434 | + | |
| 3435 | + | |
| 3436 | + | |
| 3437 | + | |
3365 | 3438 | | |
3366 | 3439 | | |
3367 | 3440 | | |
| |||
0 commit comments