Skip to content

Commit cb0ecc5

Browse files
committed
[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.
1 parent 5877d6f commit cb0ecc5

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

llvm/lib/Transforms/Utils/CallGraphUpdater.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ void CallGraphUpdater::removeFunction(Function &DeadFn) {
106106
}
107107

108108
void CallGraphUpdater::replaceFunctionWith(Function &OldFn, Function &NewFn) {
109+
OldFn.removeDeadConstantUsers();
109110
ReplacedFunctions.insert(&OldFn);
110111
if (CG) {
111112
// Update the call graph for the newly promoted function.

llvm/unittests/Analysis/CGSCCPassManagerTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,10 @@ TEST_F(CGSCCPassManagerTest, TestUpdateCGAndAnalysisManagerForPasses8) {
16081608
FnF->getEntryBlock().front().moveBefore(RI);
16091609
ASSERT_NE(FnF, nullptr);
16101610

1611+
// Create an unsused constant that is referencing the old (=replaced)
1612+
// function.
1613+
ConstantExpr::getBitCast(FnF, Type::getInt8PtrTy(FnF->getContext()));
1614+
16111615
// Use the CallGraphUpdater to update the call graph.
16121616
CallGraphUpdater CGU;
16131617
CGU.initialize(CG, C, AM, UR);

0 commit comments

Comments
 (0)