@@ -1818,6 +1818,15 @@ ConstantFolder::processWorkList() {
1818
1818
}
1819
1819
1820
1820
// Go through all users of the constant and try to fold them.
1821
+ //
1822
+ // FIXME: remove this temporary deleter. It is dangerous because any use of
1823
+ // the original deleter will invalidate its iterators. It is currently used
1824
+ // to work around bugs that are exposed in the -Onone stdlib build when the
1825
+ // same deleter is used for both the dead code elimination above and the
1826
+ // dead use elimination below.
1827
+ auto tempCallbacks = deleter.getCallbacks ();
1828
+ InstructionDeleter tempDeleter (std::move (tempCallbacks));
1829
+
1821
1830
for (auto Result : I->getResults ()) {
1822
1831
for (auto *Use : Result->getUses ()) {
1823
1832
SILInstruction *User = Use->getUser ();
@@ -1841,7 +1850,7 @@ ConstantFolder::processWorkList() {
1841
1850
// this as part of the constant folding logic, because there is no value
1842
1851
// they can produce (other than empty tuple, which is wasteful).
1843
1852
if (isa<CondFailInst>(User))
1844
- deleter .trackIfDead (User);
1853
+ tempDeleter .trackIfDead (User);
1845
1854
1846
1855
// See if we have an instruction that is read none and has a stateless
1847
1856
// inverse. If we do, add it to the worklist so we can check its users
@@ -1947,15 +1956,15 @@ ConstantFolder::processWorkList() {
1947
1956
// it, we exit the worklist as expected.
1948
1957
SILValue r = User->getResult (Index);
1949
1958
if (r->use_empty ()) {
1950
- deleter .trackIfDead (User);
1959
+ tempDeleter .trackIfDead (User);
1951
1960
continue ;
1952
1961
}
1953
1962
1954
1963
// Otherwise, do the RAUW.
1955
1964
User->getResult (Index)->replaceAllUsesWith (C);
1956
1965
// Record the user if it is dead to perform the necessary cleanups
1957
1966
// later.
1958
- deleter .trackIfDead (User);
1967
+ tempDeleter .trackIfDead (User);
1959
1968
1960
1969
// The new constant could be further folded now, add it to the
1961
1970
// worklist.
@@ -1967,7 +1976,7 @@ ConstantFolder::processWorkList() {
1967
1976
1968
1977
// Eagerly DCE. We do this after visiting all users to ensure we don't
1969
1978
// invalidate the uses iterator.
1970
- deleter .cleanupDeadInstructions ();
1979
+ tempDeleter .cleanupDeadInstructions ();
1971
1980
}
1972
1981
1973
1982
// TODO: refactor this code outside of the method. Passes should not merge
0 commit comments