summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/ProfileData/InstrProf.h2
-rw-r--r--llvm/unittests/ProfileData/InstrProfTest.cpp6
2 files changed, 7 insertions, 1 deletions
diff --git a/llvm/include/llvm/ProfileData/InstrProf.h b/llvm/include/llvm/ProfileData/InstrProf.h
index c1db9b63404..4a445d230f9 100644
--- a/llvm/include/llvm/ProfileData/InstrProf.h
+++ b/llvm/include/llvm/ProfileData/InstrProf.h
@@ -379,7 +379,7 @@ StringRef InstrProfSymtab::getFuncName(uint64_t FuncMD5Hash) {
std::lower_bound(MD5NameMap.begin(), MD5NameMap.end(), FuncMD5Hash,
[](const std::pair<uint64_t, std::string> &LHS,
uint64_t RHS) { return LHS.first < RHS; });
- if (Result != MD5NameMap.end())
+ if (Result != MD5NameMap.end() && Result->first == FuncMD5Hash)
return Result->second;
return StringRef();
}
diff --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp
index 3615b0a4359..e2349f4fc57 100644
--- a/llvm/unittests/ProfileData/InstrProfTest.cpp
+++ b/llvm/unittests/ProfileData/InstrProfTest.cpp
@@ -746,6 +746,12 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_test) {
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("bar3"));
ASSERT_EQ(StringRef("bar3"), R);
+ // negative tests
+ R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("bar4"));
+ ASSERT_EQ(StringRef(), R);
+ R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("foo4"));
+ ASSERT_EQ(StringRef(), R);
+
// Now incrementally update the symtab
Symtab.addFuncName("blah_1");
Symtab.addFuncName("blah_2");
OpenPOWER on IntegriCloud