From 4ec15997d0ad8c0a0387de7b54b91bf846603f6d Mon Sep 17 00:00:00 2001 From: Jessica Paquette Date: Fri, 27 Jul 2018 18:21:57 +0000 Subject: [PATCH] [MachineOutliner] Exit getOutliningCandidateInfo when we erase all candidates 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 | 2 ++ lib/CodeGen/MachineOutliner.cpp | 8 +++++++- lib/Target/AArch64/AArch64InstrInfo.cpp | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/llvm/CodeGen/MachineOutliner.h b/include/llvm/CodeGen/MachineOutliner.h index 5aa0382ce7b..4249a99a891 100644 --- a/include/llvm/CodeGen/MachineOutliner.h +++ b/include/llvm/CodeGen/MachineOutliner.h @@ -217,6 +217,8 @@ public: for (std::shared_ptr &C : Candidates) C->Benefit = B; } + + OutlinedFunction() {} }; } // namespace outliner } // namespace llvm diff --git a/lib/CodeGen/MachineOutliner.cpp b/lib/CodeGen/MachineOutliner.cpp index 1babe4239e5..28e4e2c6c87 100644 --- a/lib/CodeGen/MachineOutliner.cpp +++ b/lib/CodeGen/MachineOutliner.cpp @@ -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 Seq; for (unsigned i = Leaf->SuffixIdx; i < Leaf->SuffixIdx + StringLen; i++) Seq.push_back(ST.Str[i]); diff --git a/lib/Target/AArch64/AArch64InstrInfo.cpp b/lib/Target/AArch64/AArch64InstrInfo.cpp index dc3fa4f8c1d..230480cf1ce 100644 --- a/lib/Target/AArch64/AArch64InstrInfo.cpp +++ b/lib/Target/AArch64/AArch64InstrInfo.cpp @@ -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. -- 2.50.1