Skip to content

Commit

Permalink
[memprof] Add an assert to InstrProfWriter::addMemProfData
Browse files Browse the repository at this point in the history
This patch adds a quick validity check to
InstrProfWriter::addMemProfData.  Specifically, we check to see if we
have all (or none) of the MemProf profile components (frames, call
stacks, records).

The credit goes to Teresa Johnson for suggesting this assert.
  • Loading branch information
kazutakahirata committed Nov 23, 2024
1 parent 19ddafa commit b277b85
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions llvm/lib/ProfileData/InstrProfWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,14 @@ bool InstrProfWriter::addMemProfCallStack(

bool InstrProfWriter::addMemProfData(memprof::IndexedMemProfData Incoming,
function_ref<void(Error)> Warn) {
// TODO: Once we remove support for MemProf format Version V1, assert that
// the three components (frames, call stacks, and records) are either all
// empty or populated.
// Return immediately if everything is empty.
if (Incoming.Frames.empty() && Incoming.CallStacks.empty() &&
Incoming.Records.empty())
return true;

// Otherwise, every component must be non-empty.
assert(!Incoming.Frames.empty() && !Incoming.CallStacks.empty() &&
!Incoming.Records.empty());

if (MemProfData.Frames.empty())
MemProfData.Frames = std::move(Incoming.Frames);
Expand Down

0 comments on commit b277b85

Please sign in to comment.