File tree Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Original file line number Diff line number Diff line change 33
33
#include < cstdint>
34
34
#include < limits>
35
35
#include < memory>
36
+ #include < optional>
36
37
#include < system_error>
37
38
#include < utility>
38
39
#include < vector>
@@ -1506,13 +1507,11 @@ IndexedInstrProfReader::getMemProfRecord(const uint64_t FuncNameHash) {
1506
1507
1507
1508
// Setup a callback to convert from frame ids to frame using the on-disk
1508
1509
// FrameData hash table.
1509
- memprof::FrameId LastUnmappedFrameId = 0 ;
1510
- bool HasFrameMappingError = false ;
1510
+ std::optional<memprof::FrameId> LastUnmappedFrameId;
1511
1511
auto IdToFrameCallback = [&](const memprof::FrameId Id) {
1512
1512
auto FrIter = MemProfFrameTable->find (Id);
1513
1513
if (FrIter == MemProfFrameTable->end ()) {
1514
1514
LastUnmappedFrameId = Id;
1515
- HasFrameMappingError = true ;
1516
1515
return memprof::Frame (0 , 0 , 0 , false );
1517
1516
}
1518
1517
return *FrIter;
@@ -1521,10 +1520,10 @@ IndexedInstrProfReader::getMemProfRecord(const uint64_t FuncNameHash) {
1521
1520
memprof::MemProfRecord Record (*Iter, IdToFrameCallback);
1522
1521
1523
1522
// Check that all frame ids were successfully converted to frames.
1524
- if (HasFrameMappingError ) {
1523
+ if (LastUnmappedFrameId ) {
1525
1524
return make_error<InstrProfError>(instrprof_error::hash_mismatch,
1526
1525
" memprof frame not found for frame id " +
1527
- Twine (LastUnmappedFrameId));
1526
+ Twine (* LastUnmappedFrameId));
1528
1527
}
1529
1528
return Record;
1530
1529
}
Original file line number Diff line number Diff line change 19
19
#include " llvm/Testing/Support/Error.h"
20
20
#include " gtest/gtest.h"
21
21
#include < cstdarg>
22
+ #include < optional>
22
23
23
24
using namespace llvm ;
24
25
using ::testing::EndsWith;
@@ -433,21 +434,19 @@ TEST_F(InstrProfTest, test_memprof) {
433
434
ASSERT_THAT_ERROR (RecordOr.takeError (), Succeeded ());
434
435
const memprof::MemProfRecord &Record = RecordOr.get ();
435
436
436
- memprof::FrameId LastUnmappedFrameId = 0 ;
437
- bool HasFrameMappingError = false ;
437
+ std::optional<memprof::FrameId> LastUnmappedFrameId;
438
438
auto IdToFrameCallback = [&](const memprof::FrameId Id) {
439
439
auto Iter = IdToFrameMap.find (Id);
440
440
if (Iter == IdToFrameMap.end ()) {
441
441
LastUnmappedFrameId = Id;
442
- HasFrameMappingError = true ;
443
442
return memprof::Frame (0 , 0 , 0 , false );
444
443
}
445
444
return Iter->second ;
446
445
};
447
446
448
447
const memprof::MemProfRecord WantRecord (IndexedMR, IdToFrameCallback);
449
- ASSERT_FALSE (HasFrameMappingError )
450
- << " could not map frame id: " << LastUnmappedFrameId;
448
+ ASSERT_FALSE (LastUnmappedFrameId. has_value () )
449
+ << " could not map frame id: " << * LastUnmappedFrameId;
451
450
EXPECT_THAT (WantRecord, EqualsRecord (Record));
452
451
}
453
452
You can’t perform that action at this time.
0 commit comments