OSDN Git Service

[MachineOutliner] Exit getOutliningCandidateInfo when we erase all candidates
authorJessica Paquette <jpaquette@apple.com>
Fri, 27 Jul 2018 18:21:57 +0000 (18:21 +0000)
committerJessica Paquette <jpaquette@apple.com>
Fri, 27 Jul 2018 18:21:57 +0000 (18:21 +0000)
There was a missing check for if a candidate list was entirely deleted. This
adds that check.

This fixes an asan failure caused by running test/CodeGen/AArch64/addsub_ext.ll
with the MachineOutliner enabled.

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

include/llvm/CodeGen/MachineOutliner.h
lib/CodeGen/MachineOutliner.cpp
lib/Target/AArch64/AArch64InstrInfo.cpp

index 5aa0382..4249a99 100644 (file)
@@ -217,6 +217,8 @@ public:
     for (std::shared_ptr<Candidate> &C : Candidates)
       C->Benefit = B;
   }
+
+  OutlinedFunction() {}
 };
 } // namespace outliner
 } // namespace llvm
index 1babe42..28e4e2c 100644 (file)
@@ -979,7 +979,13 @@ unsigned MachineOutliner::findCandidates(
     // We've found something we might want to outline.
     // Create an OutlinedFunction to store it and check if it'd be beneficial
     // to outline.
-    OutlinedFunction OF = TII.getOutliningCandidateInfo(CandidatesForRepeatedSeq);
+    OutlinedFunction OF =
+        TII.getOutliningCandidateInfo(CandidatesForRepeatedSeq);
+
+    // If we deleted every candidate, then there's nothing to outline.
+    if (OF.Candidates.empty())
+      continue;
+
     std::vector<unsigned> Seq;
     for (unsigned i = Leaf->SuffixIdx; i < Leaf->SuffixIdx + StringLen; i++)
       Seq.push_back(ST.Str[i]);
index dc3fa4f..230480c 100644 (file)
@@ -4967,6 +4967,10 @@ AArch64InstrInfo::getOutliningCandidateInfo(
                                             CantGuaranteeValueAcrossCall),
                              RepeatedSequenceLocs.end());
 
+  // If the sequence is empty, we're done.
+  if (RepeatedSequenceLocs.empty())
+    return outliner::OutlinedFunction();
+
   // At this point, we have only "safe" candidates to outline. Figure out
   // frame + call instruction information.