@@ -1818,6 +1818,15 @@ ConstantFolder::processWorkList() {
18181818 }
18191819
18201820 // 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+
18211830 for (auto Result : I->getResults ()) {
18221831 for (auto *Use : Result->getUses ()) {
18231832 SILInstruction *User = Use->getUser ();
@@ -1841,7 +1850,7 @@ ConstantFolder::processWorkList() {
18411850 // this as part of the constant folding logic, because there is no value
18421851 // they can produce (other than empty tuple, which is wasteful).
18431852 if (isa<CondFailInst>(User))
1844- deleter .trackIfDead (User);
1853+ tempDeleter .trackIfDead (User);
18451854
18461855 // See if we have an instruction that is read none and has a stateless
18471856 // inverse. If we do, add it to the worklist so we can check its users
@@ -1947,15 +1956,15 @@ ConstantFolder::processWorkList() {
19471956 // it, we exit the worklist as expected.
19481957 SILValue r = User->getResult (Index);
19491958 if (r->use_empty ()) {
1950- deleter .trackIfDead (User);
1959+ tempDeleter .trackIfDead (User);
19511960 continue ;
19521961 }
19531962
19541963 // Otherwise, do the RAUW.
19551964 User->getResult (Index)->replaceAllUsesWith (C);
19561965 // Record the user if it is dead to perform the necessary cleanups
19571966 // later.
1958- deleter .trackIfDead (User);
1967+ tempDeleter .trackIfDead (User);
19591968
19601969 // The new constant could be further folded now, add it to the
19611970 // worklist.
@@ -1967,7 +1976,7 @@ ConstantFolder::processWorkList() {
19671976
19681977 // Eagerly DCE. We do this after visiting all users to ensure we don't
19691978 // invalidate the uses iterator.
1970- deleter .cleanupDeadInstructions ();
1979+ tempDeleter .cleanupDeadInstructions ();
19711980 }
19721981
19731982 // TODO: refactor this code outside of the method. Passes should not merge
0 commit comments