Skip to content

Commit 4b25d67

Browse files
Keep copies of owned strings for cold symbol names
1 parent 6dd04e4 commit 4b25d67

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

llvm/lib/ProfileData/DataAccessProf.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ Error DataAccessProfData::addKnownSymbolWithoutSamples(
111111
auto CanonicalName = getCanonicalName(std::get<StringRef>(SymbolID));
112112
if (!CanonicalName)
113113
return CanonicalName.takeError();
114-
KnownColdSymbols.insert(*CanonicalName);
114+
KnownColdSymbols.insert(
115+
saveStringToMap(StrToIndexMap, Saver, *CanonicalName).first);
115116
return Error::success();
116117
}
117118

llvm/unittests/ProfileData/DataAccessProfTest.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ TEST(MemProf, DataAccessProfile) {
7878
// Test that symbol names and file names are stored in the input order.
7979
EXPECT_THAT(
8080
llvm::to_vector(llvm::make_first_range(Data.getStrToIndexMapRef())),
81-
ElementsAre("foo", "bar.__uniq.321", "file2", "file1"));
81+
ElementsAre("foo", "sym2", "bar.__uniq.321", "file2", "sym1", "file1"));
8282
EXPECT_THAT(Data.getKnownColdSymbols(), ElementsAre("sym2", "sym1"));
8383
EXPECT_THAT(Data.getKnownColdHashes(), ElementsAre(789, 678));
8484

@@ -134,9 +134,10 @@ TEST(MemProf, DataAccessProfile) {
134134
testing::IsEmpty());
135135
EXPECT_FALSE(deserializedData.deserialize(p));
136136

137-
EXPECT_THAT(llvm::to_vector(llvm::make_first_range(
138-
deserializedData.getStrToIndexMapRef())),
139-
ElementsAre("foo", "bar.__uniq.321", "file2", "file1"));
137+
EXPECT_THAT(
138+
llvm::to_vector(
139+
llvm::make_first_range(deserializedData.getStrToIndexMapRef())),
140+
ElementsAre("foo", "sym2", "bar.__uniq.321", "file2", "sym1", "file1"));
140141
EXPECT_THAT(deserializedData.getKnownColdSymbols(),
141142
ElementsAre("sym2", "sym1"));
142143
EXPECT_THAT(deserializedData.getKnownColdHashes(), ElementsAre(789, 678));
@@ -158,7 +159,7 @@ TEST(MemProf, DataAccessProfile) {
158159
Field(&DataAccessProfRecordRef::AccessCount, 100),
159160
Field(&DataAccessProfRecordRef::IsStringLiteral, false),
160161
Field(&DataAccessProfRecordRef::Locations, testing::IsEmpty())),
161-
AllOf(Field(&DataAccessProfRecordRef::SymbolID, 1),
162+
AllOf(Field(&DataAccessProfRecordRef::SymbolID, 2),
162163
Field(&DataAccessProfRecordRef::AccessCount, 123),
163164
Field(&DataAccessProfRecordRef::IsStringLiteral, false),
164165
Field(&DataAccessProfRecordRef::Locations,

0 commit comments

Comments
 (0)