summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ProfileData/CoverageMapping.cpp
diff options
context:
space:
mode:
authorIgor Kudrin <ikudrin.dev@gmail.com>2016-04-15 14:56:50 +0000
committerIgor Kudrin <ikudrin.dev@gmail.com>2016-04-15 14:56:50 +0000
commit061d496c511b02a0c2bd394539c757c5ad4511e3 (patch)
tree2a74d228a4d1a319e950414d2b4b078507494716 /llvm/lib/ProfileData/CoverageMapping.cpp
parent81433e99b9a770ccbd086b80390031a4ea708dbd (diff)
downloadbcm5719-llvm-061d496c511b02a0c2bd394539c757c5ad4511e3.tar.gz
bcm5719-llvm-061d496c511b02a0c2bd394539c757c5ad4511e3.zip
[Coverage] Prevent detection of false instantiations in case of macro expansion.
The root of the problem was that findMainViewFileID(File, Function) could return some ID for any given file, even though that file was not the main file for that function. This patch ensures that the result of this function is conformed with the result of findMainViewFileID(Function). Differential Revision: http://reviews.llvm.org/D18787 llvm-svn: 266436
Diffstat (limited to 'llvm/lib/ProfileData/CoverageMapping.cpp')
-rw-r--r--llvm/lib/ProfileData/CoverageMapping.cpp30
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);
}
}
OpenPOWER on IntegriCloud