diff options
Diffstat (limited to 'llvm/lib/ProfileData/CoverageMapping.cpp')
-rw-r--r-- | llvm/lib/ProfileData/CoverageMapping.cpp | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/llvm/lib/ProfileData/CoverageMapping.cpp b/llvm/lib/ProfileData/CoverageMapping.cpp index e130565500f..334de3c3b06 100644 --- a/llvm/lib/ProfileData/CoverageMapping.cpp +++ b/llvm/lib/ProfileData/CoverageMapping.cpp @@ -375,21 +375,7 @@ static SmallBitVector gatherFileIDs(StringRef SourceFile, return FilenameEquivalence; } -static Optional<unsigned> findMainViewFileID(StringRef SourceFile, - const FunctionRecord &Function) { - SmallBitVector IsNotExpandedFile(Function.Filenames.size(), true); - SmallBitVector FilenameEquivalence = gatherFileIDs(SourceFile, Function); - for (const auto &CR : Function.CountedRegions) - if (CR.Kind == CounterMappingRegion::ExpansionRegion && - FilenameEquivalence[CR.FileID]) - IsNotExpandedFile[CR.ExpandedFileID] = false; - IsNotExpandedFile &= FilenameEquivalence; - int I = IsNotExpandedFile.find_first(); - if (I == -1) - return None; - return I; -} - +/// Return the ID of the file where the definition of the function is located. static Optional<unsigned> findMainViewFileID(const FunctionRecord &Function) { SmallBitVector IsNotExpandedFile(Function.Filenames.size(), true); for (const auto &CR : Function.CountedRegions) @@ -401,6 +387,16 @@ static Optional<unsigned> findMainViewFileID(const FunctionRecord &Function) { return I; } +/// Check if SourceFile is the file that contains the definition of +/// the Function. Return the ID of the file in that case or None otherwise. +static Optional<unsigned> findMainViewFileID(StringRef SourceFile, + const FunctionRecord &Function) { + Optional<unsigned> I = findMainViewFileID(Function); + if (I && SourceFile == Function.Filenames[*I]) + return I; + return None; +} + /// Sort a nested sequence of regions from a single file. template <class It> static void sortNestedRegions(It First, It Last) { std::sort(First, Last, @@ -422,13 +418,11 @@ CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) { for (const auto &Function : Functions) { auto MainFileID = findMainViewFileID(Filename, Function); - if (!MainFileID) - continue; auto FileIDs = gatherFileIDs(Filename, Function); for (const auto &CR : Function.CountedRegions) if (FileIDs.test(CR.FileID)) { Regions.push_back(CR); - if (isExpansion(CR, *MainFileID)) + if (MainFileID && isExpansion(CR, *MainFileID)) FileCoverage.Expansions.emplace_back(CR, Function); } } |