[CallGraphUpdater] Remove dead constants before replacing a function

Dead constants might be left when a function is replaced, we can
gracefully handle this case and avoid complexity for the users who would
see an assertion otherwise.
This commit is contained in:
Johannes Doerfert 2020-03-23 01:09:49 -05:00
parent 5877d6f5f4
commit cb0ecc5c33
2 changed files with 5 additions and 0 deletions

View File

@ -106,6 +106,7 @@ void CallGraphUpdater::removeFunction(Function &DeadFn) {
}
void CallGraphUpdater::replaceFunctionWith(Function &OldFn, Function &NewFn) {
OldFn.removeDeadConstantUsers();
ReplacedFunctions.insert(&OldFn);
if (CG) {
// Update the call graph for the newly promoted function.

View File

@ -1608,6 +1608,10 @@ TEST_F(CGSCCPassManagerTest, TestUpdateCGAndAnalysisManagerForPasses8) {
FnF->getEntryBlock().front().moveBefore(RI);
ASSERT_NE(FnF, nullptr);
// Create an unsused constant that is referencing the old (=replaced)
// function.
ConstantExpr::getBitCast(FnF, Type::getInt8PtrTy(FnF->getContext()));
// Use the CallGraphUpdater to update the call graph.
CallGraphUpdater CGU;
CGU.initialize(CG, C, AM, UR);