[AlwaysInliner] Invalidate analyses when we delete functions

Fixes PR52292.

Reviewed By: asbirlea

Differential Revision: https://reviews.llvm.org/D112473
This commit is contained in:
Arthur Eubanks 2021-10-25 10:52:30 -07:00
parent 882df21a1b
commit 4a9db7367d
2 changed files with 14 additions and 2 deletions
llvm
lib/Transforms/IPO
test/Transforms/Inline

View File

@ -108,8 +108,10 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
// Delete the non-comdat ones from the module and also from our vector.
auto NonComdatBegin = partition(
InlinedFunctions, [&](Function *F) { return F->hasComdat(); });
for (Function *F : make_range(NonComdatBegin, InlinedFunctions.end()))
for (Function *F : make_range(NonComdatBegin, InlinedFunctions.end())) {
M.getFunctionList().erase(F);
Changed = true;
}
InlinedFunctions.erase(NonComdatBegin, InlinedFunctions.end());
if (!InlinedFunctions.empty()) {
@ -117,8 +119,10 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
// are not actually dead.
filterDeadComdatFunctions(M, InlinedFunctions);
// The remaining functions are actually dead.
for (Function *F : InlinedFunctions)
for (Function *F : InlinedFunctions) {
M.getFunctionList().erase(F);
Changed = true;
}
}
return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();

View File

@ -0,0 +1,8 @@
; RUN: opt -passes='require<no-op-module>,always-inline' -disable-output < %s 2>&1 -debug-pass-manager | FileCheck %s
; CHECK: Invalidating {{.*}} NoOpModuleAnalysis
; CHECK-NOT: @f
define internal void @f() alwaysinline {
unreachable
}