InstrProf: Treat functions with a coverage map but no profile as unreached
authorJustin Bogner <mail@justinbogner.com>
Wed, 13 May 2015 22:03:04 +0000 (22:03 +0000)
committerJustin Bogner <mail@justinbogner.com>
Wed, 13 May 2015 22:03:04 +0000 (22:03 +0000)
If we have a coverage mapping but no profile data for a function,
calling it mismatched is misleading. This can just as easily be
unreachable code that was stripped from the binary. Instead, treat
these the same as functions where we have an explicit "zero" coverage
map by setting the count to zero for each mapped region.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237298 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ProfileData/CoverageMapping.cpp
unittests/ProfileData/CoverageMappingTest.cpp

index db70ef219aa5d4792eef799e22ec7885c87d1ab6..bbac5c26b1ebd9569126c596fc1c5571be4624bd 100644 (file)
@@ -209,8 +209,9 @@ CoverageMapping::load(CoverageMappingReader &CoverageReader,
         continue;
       } else if (EC != instrprof_error::unknown_function)
         return EC;
-    } else
-      Ctx.setCounts(Counts);
+      Counts.assign(Record.MappingRegions.size(), 0);
+    }
+    Ctx.setCounts(Counts);
 
     assert(!Record.MappingRegions.empty() && "Function has no regions");
 
index c82ed66e53e2b61800d3b098d89f1887f2ca26f6..a0995fbbc0287d6a4f2d6b2c9a8276104ebade2b 100644 (file)
@@ -222,6 +222,21 @@ TEST_F(CoverageMappingTest, uncovered_function) {
   ASSERT_EQ(CoverageSegment(3, 4, false),   Segments[1]);
 }
 
+TEST_F(CoverageMappingTest, uncovered_function_with_mapping) {
+  readProfCounts();
+
+  addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
+  addCMR(Counter::getCounter(1), "file1", 1, 1, 4, 7);
+  loadCoverageMapping("func", 0x1234);
+
+  CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
+  std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
+  ASSERT_EQ(3U, Segments.size());
+  ASSERT_EQ(CoverageSegment(1, 1, 0, true),  Segments[0]);
+  ASSERT_EQ(CoverageSegment(4, 7, 0, false), Segments[1]);
+  ASSERT_EQ(CoverageSegment(9, 9, false),    Segments[2]);
+}
+
 TEST_F(CoverageMappingTest, combine_regions) {
   ProfileWriter.addFunctionCounts("func", 0x1234, {10, 20, 30});
   readProfCounts();