[llvm] 446371f - [memprof] Use std::optional (NFC) (#89317)

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 18 14:56:36 PDT 2024


Author: Kazu Hirata
Date: 2024-04-18T14:56:33-07:00
New Revision: 446371f5ccbd81aa7707b4f1a1baa0ea0955dc67

URL: https://github.com/llvm/llvm-project/commit/446371f5ccbd81aa7707b4f1a1baa0ea0955dc67
DIFF: https://github.com/llvm/llvm-project/commit/446371f5ccbd81aa7707b4f1a1baa0ea0955dc67.diff

LOG: [memprof] Use std::optional (NFC) (#89317)

This is partly for readability and partly for consistency with other
id-to-frame callbacks.

Added: 
    

Modified: 
    llvm/unittests/ProfileData/InstrProfTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp
index 16b8b50914cc6b..73ba0a23ea5f45 100644
--- a/llvm/unittests/ProfileData/InstrProfTest.cpp
+++ b/llvm/unittests/ProfileData/InstrProfTest.cpp
@@ -471,7 +471,7 @@ TEST_F(InstrProfTest, test_memprof_v0) {
   };
 
   const memprof::MemProfRecord WantRecord(IndexedMR, IdToFrameCallback);
-  ASSERT_FALSE(LastUnmappedFrameId.has_value())
+  ASSERT_EQ(LastUnmappedFrameId, std::nullopt)
       << "could not map frame id: " << *LastUnmappedFrameId;
   EXPECT_THAT(WantRecord, EqualsRecord(Record));
 }
@@ -607,22 +607,20 @@ TEST_F(InstrProfTest, test_memprof_merge) {
   ASSERT_THAT_ERROR(RecordOr.takeError(), Succeeded());
   const memprof::MemProfRecord &Record = RecordOr.get();
 
-  memprof::FrameId LastUnmappedFrameId = 0;
-  bool HasFrameMappingError = false;
+  std::optional<memprof::FrameId> LastUnmappedFrameId;
 
   auto IdToFrameCallback = [&](const memprof::FrameId Id) {
     auto Iter = IdToFrameMap.find(Id);
     if (Iter == IdToFrameMap.end()) {
       LastUnmappedFrameId = Id;
-      HasFrameMappingError = true;
       return memprof::Frame(0, 0, 0, false);
     }
     return Iter->second;
   };
 
   const memprof::MemProfRecord WantRecord(IndexedMR, IdToFrameCallback);
-  ASSERT_FALSE(HasFrameMappingError)
-      << "could not map frame id: " << LastUnmappedFrameId;
+  ASSERT_EQ(LastUnmappedFrameId, std::nullopt)
+      << "could not map frame id: " << *LastUnmappedFrameId;
   EXPECT_THAT(WantRecord, EqualsRecord(Record));
 }
 


        


More information about the llvm-commits mailing list