Skip to content

Commit 446371f

Browse files
[memprof] Use std::optional (NFC) (#89317)
This is partly for readability and partly for consistency with other id-to-frame callbacks.
1 parent 8b24028 commit 446371f

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

llvm/unittests/ProfileData/InstrProfTest.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ TEST_F(InstrProfTest, test_memprof_v0) {
471471
};
472472

473473
const memprof::MemProfRecord WantRecord(IndexedMR, IdToFrameCallback);
474-
ASSERT_FALSE(LastUnmappedFrameId.has_value())
474+
ASSERT_EQ(LastUnmappedFrameId, std::nullopt)
475475
<< "could not map frame id: " << *LastUnmappedFrameId;
476476
EXPECT_THAT(WantRecord, EqualsRecord(Record));
477477
}
@@ -607,22 +607,20 @@ TEST_F(InstrProfTest, test_memprof_merge) {
607607
ASSERT_THAT_ERROR(RecordOr.takeError(), Succeeded());
608608
const memprof::MemProfRecord &Record = RecordOr.get();
609609

610-
memprof::FrameId LastUnmappedFrameId = 0;
611-
bool HasFrameMappingError = false;
610+
std::optional<memprof::FrameId> LastUnmappedFrameId;
612611

613612
auto IdToFrameCallback = [&](const memprof::FrameId Id) {
614613
auto Iter = IdToFrameMap.find(Id);
615614
if (Iter == IdToFrameMap.end()) {
616615
LastUnmappedFrameId = Id;
617-
HasFrameMappingError = true;
618616
return memprof::Frame(0, 0, 0, false);
619617
}
620618
return Iter->second;
621619
};
622620

623621
const memprof::MemProfRecord WantRecord(IndexedMR, IdToFrameCallback);
624-
ASSERT_FALSE(HasFrameMappingError)
625-
<< "could not map frame id: " << LastUnmappedFrameId;
622+
ASSERT_EQ(LastUnmappedFrameId, std::nullopt)
623+
<< "could not map frame id: " << *LastUnmappedFrameId;
626624
EXPECT_THAT(WantRecord, EqualsRecord(Record));
627625
}
628626

0 commit comments

Comments
 (0)