]> granicus.if.org Git - llvm/commitdiff
[PM/Inliner] Fix a bug in r297374 where we would leave stale calls in
authorChandler Carruth <chandlerc@gmail.com>
Thu, 16 Mar 2017 10:45:42 +0000 (10:45 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Thu, 16 Mar 2017 10:45:42 +0000 (10:45 +0000)
the work queue and crash when trying to visit them after deleting the
function containing those calls.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297940 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/Inliner.cpp
test/Transforms/Inline/internal-scc-members.ll [new file with mode: 0644]

index 5ea26a86eb8624b7779e7fd80eb836c2ad690242..31589ac99eea13c67cfc83b9126ce7867a8a2db7 100644 (file)
@@ -903,6 +903,12 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
         // made dead by this operation on other functions).
         Callee.removeDeadConstantUsers();
         if (Callee.use_empty()) {
+          Calls.erase(
+              std::remove_if(Calls.begin() + i + 1, Calls.end(),
+                             [&Callee](const std::pair<CallSite, int> &Call) {
+                               return Call.first.getCaller() == &Callee;
+                             }),
+              Calls.end());
           // Clear the body and queue the function itself for deletion when we
           // finish inlining and call graph updates.
           // Note that after this point, it is an error to do anything other
diff --git a/test/Transforms/Inline/internal-scc-members.ll b/test/Transforms/Inline/internal-scc-members.ll
new file mode 100644 (file)
index 0000000..258ce00
--- /dev/null
@@ -0,0 +1,31 @@
+; Test that the inliner can handle deleting functions within an SCC while still
+; processing the calls in that SCC.
+;
+; RUN: opt < %s -S -inline | FileCheck %s
+; RUN: opt < %s -S -passes=inline | FileCheck %s
+
+; CHECK-LABEL: define internal void @test1_scc0()
+; CHECK-NOT: call
+; CHECK: call void @test1_scc0()
+; CHECK-NOT: call
+; CHECK: ret
+define internal void @test1_scc0() {
+entry:
+  call void @test1_scc1()
+  ret void
+}
+
+; CHECK-NOT: @test1_scc1
+define internal void @test1_scc1() {
+entry:
+  call void @test1_scc0()
+  ret void
+}
+
+; CHECK-LABEL: define void @test1()
+; CHECK: call void @test1_scc0()
+define void @test1() {
+entry:
+  call void @test1_scc0() noinline
+  ret void
+}