From: Wenlei He Date: Wed, 1 Sep 2021 21:37:18 +0000 (-0700) Subject: [llvm-profdata] Fix assertion from invalid iterator X-Git-Tag: upstream/15.0.7~32485 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4ef88031f52f7c21356295e609ecea3c10d29d9f;p=platform%2Fupstream%2Fllvm.git [llvm-profdata] Fix assertion from invalid iterator Differential Revision: https://reviews.llvm.org/D109096 --- diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp index 488dc8f..6692c54 100644 --- a/llvm/tools/llvm-profdata/llvm-profdata.cpp +++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -1633,6 +1633,7 @@ void SampleOverlapAggregator::computeSampleProfileOverlap(raw_fd_ostream &OS) { "except inlinees"); FuncOverlap.TestSample = TestStats[FuncOverlap.TestName].SampleSum; + bool Matched = false; const auto Match = BaseFuncProf.find(FuncOverlap.TestName); if (Match == BaseFuncProf.end()) { const FuncSampleStats &FuncStats = TestStats[FuncOverlap.TestName]; @@ -1677,6 +1678,7 @@ void SampleOverlapAggregator::computeSampleProfileOverlap(raw_fd_ostream &OS) { // Remove matched base functions for later reporting functions not found // in test profile. BaseFuncProf.erase(Match); + Matched = true; } // Print function-level similarity information if specified by options. @@ -1684,9 +1686,8 @@ void SampleOverlapAggregator::computeSampleProfileOverlap(raw_fd_ostream &OS) { "TestStats should have records for all functions in test profile " "except inlinees"); if (TestStats[FuncOverlap.TestName].MaxSample >= FuncFilter.ValueCutoff || - (Match != BaseFuncProf.end() && - FuncOverlap.Similarity < LowSimilarityThreshold) || - (Match != BaseFuncProf.end() && !FuncFilter.NameFilter.empty() && + (Matched && FuncOverlap.Similarity < LowSimilarityThreshold) || + (Matched && !FuncFilter.NameFilter.empty() && FuncOverlap.BaseName.toString().find(FuncFilter.NameFilter) != std::string::npos)) { assert(ProfOverlap.BaseSample > 0 &&