[Coverage] Fix the way we load "<unknown>:func" records

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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264559 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Vedant Kumar 2016-03-28 01:16:12 +00:00
parent e0157e2632
commit 9c51ac3626
2 changed files with 16 additions and 1 deletions

View File

@ -90,7 +90,7 @@ std::string getPGOFuncName(const Function &F, uint64_t Version) {
StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName) { StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName) {
if (FileName.empty()) if (FileName.empty())
return PGOFuncName; FileName = "<unknown>";
// Drop the file name including ':'. See also getPGOFuncName. // Drop the file name including ':'. See also getPGOFuncName.
if (PGOFuncName.startswith(FileName)) if (PGOFuncName.startswith(FileName))
PGOFuncName = PGOFuncName.drop_front(FileName.size() + 1); PGOFuncName = PGOFuncName.drop_front(FileName.size() + 1);

View File

@ -304,6 +304,21 @@ TEST_P(MaybeSparseCoverageMappingTest, strip_filename_prefix) {
ASSERT_EQ("func", Names[0]); 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, INSTANTIATE_TEST_CASE_P(MaybeSparse, MaybeSparseCoverageMappingTest,
::testing::Bool()); ::testing::Bool());