From 9c51ac362675068c3d77138bcd6243e59069499c Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Mon, 28 Mar 2016 01:16:12 +0000 Subject: [PATCH] [Coverage] Fix the way we load ":func" records When emitting coverage mappings for functions with local linkage and an unknown filename, we use ":func" for the PGO function name. The problem is that we don't strip "" 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 --- lib/ProfileData/InstrProf.cpp | 2 +- unittests/ProfileData/CoverageMappingTest.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/ProfileData/InstrProf.cpp b/lib/ProfileData/InstrProf.cpp index 2446521a5bc..045ba1a7b34 100644 --- a/lib/ProfileData/InstrProf.cpp +++ b/lib/ProfileData/InstrProf.cpp @@ -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 = ""; // Drop the file name including ':'. See also getPGOFuncName. if (PGOFuncName.startswith(FileName)) PGOFuncName = PGOFuncName.drop_front(FileName.size() + 1); diff --git a/unittests/ProfileData/CoverageMappingTest.cpp b/unittests/ProfileData/CoverageMappingTest.cpp index c85da9a0f9c..7f80384c63a 100644 --- a/unittests/ProfileData/CoverageMappingTest.cpp +++ b/unittests/ProfileData/CoverageMappingTest.cpp @@ -304,6 +304,21 @@ TEST_P(MaybeSparseCoverageMappingTest, strip_filename_prefix) { ASSERT_EQ("func", Names[0]); } +TEST_P(MaybeSparseCoverageMappingTest, strip_unknown_filename_prefix) { + InstrProfRecord Record(":func", 0x1234, {0}); + ProfileWriter.addRecord(std::move(Record)); + readProfCounts(); + + addCMR(Counter::getCounter(0), "", 1, 1, 9, 9); + loadCoverageMapping(":func", 0x1234); + + std::vector 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());