summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ProfileData
diff options
context:
space:
mode:
authorIgor Kudrin <ikudrin.dev@gmail.com>2016-04-18 15:36:30 +0000
committerIgor Kudrin <ikudrin.dev@gmail.com>2016-04-18 15:36:30 +0000
commit1c14dc4c5a3b0f17672a121f026e96a15f93dd4a (patch)
tree61fbe534ca14cbd136c9af0006f6f381858f5344 /llvm/lib/ProfileData
parentd09f15ea6f17e51ec2ec59b8c3b0e5ba52dd8358 (diff)
downloadbcm5719-llvm-1c14dc4c5a3b0f17672a121f026e96a15f93dd4a.tar.gz
bcm5719-llvm-1c14dc4c5a3b0f17672a121f026e96a15f93dd4a.zip
Reapply "[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). This commit reapplies r266436, which was reverted by r266458, with the .covmapping file serialized in v1 format. Differential Revision: http://reviews.llvm.org/D18787 llvm-svn: 266620
Diffstat (limited to 'llvm/lib/ProfileData')
-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