[Coverage] Fix the way we load "<unknown>:func" records
authorVedant Kumar <vsk@apple.com>
Mon, 28 Mar 2016 01:16:12 +0000 (01:16 +0000)
committerVedant Kumar <vsk@apple.com>
Mon, 28 Mar 2016 01:16:12 +0000 (01:16 +0000)
When emitting coverage mappings for functions with local linkage and an
unknown filename, we use "<unknown>:func" for the PGO function name. The
problem is that we don't strip "<unknown>" from the name when loading
coverage data, like we do for other file names. Fix that and add a test.

llvm-svn: 264559

llvm/lib/ProfileData/InstrProf.cpp
llvm/unittests/ProfileData/CoverageMappingTest.cpp

index 2446521..045ba1a 100644 (file)
@@ -90,7 +90,7 @@ std::string getPGOFuncName(const Function &F, uint64_t Version) {
 
 StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName) {
   if (FileName.empty())
-    return PGOFuncName;
+    FileName = "<unknown>";
   // Drop the file name including ':'. See also getPGOFuncName.
   if (PGOFuncName.startswith(FileName))
     PGOFuncName = PGOFuncName.drop_front(FileName.size() + 1);
index c85da9a..7f80384 100644 (file)
@@ -304,6 +304,21 @@ TEST_P(MaybeSparseCoverageMappingTest, strip_filename_prefix) {
   ASSERT_EQ("func", Names[0]);
 }
 
+TEST_P(MaybeSparseCoverageMappingTest, strip_unknown_filename_prefix) {
+  InstrProfRecord Record("<unknown>:func", 0x1234, {0});
+  ProfileWriter.addRecord(std::move(Record));
+  readProfCounts();
+
+  addCMR(Counter::getCounter(0), "", 1, 1, 9, 9);
+  loadCoverageMapping("<unknown>:func", 0x1234);
+
+  std::vector<std::string> Names;
+  for (const auto &Func : LoadedCoverage->getCoveredFunctions())
+    Names.push_back(Func.Name);
+  ASSERT_EQ(1U, Names.size());
+  ASSERT_EQ("func", Names[0]);
+}
+
 INSTANTIATE_TEST_CASE_P(MaybeSparse, MaybeSparseCoverageMappingTest,
                         ::testing::Bool());