diff --git a/llvm/include/llvm/ProfileData/InstrProf.h b/llvm/include/llvm/ProfileData/InstrProf.h index c1db9b634047..4a445d230f99 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 &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 3615b0a43590..e2349f4fc574 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");