Skip to content

Commit 9e3215a

Browse files
[memprof] Add an assert to InstrProfWriter::addMemProfData (#117426)
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.
1 parent 87cc4b4 commit 9e3215a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

llvm/lib/ProfileData/InstrProfWriter.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,14 @@ bool InstrProfWriter::addMemProfCallStack(
351351

352352
bool InstrProfWriter::addMemProfData(memprof::IndexedMemProfData Incoming,
353353
function_ref<void(Error)> Warn) {
354-
// TODO: Once we remove support for MemProf format Version V1, assert that
355-
// the three components (frames, call stacks, and records) are either all
356-
// empty or populated.
354+
// Return immediately if everything is empty.
355+
if (Incoming.Frames.empty() && Incoming.CallStacks.empty() &&
356+
Incoming.Records.empty())
357+
return true;
358+
359+
// Otherwise, every component must be non-empty.
360+
assert(!Incoming.Frames.empty() && !Incoming.CallStacks.empty() &&
361+
!Incoming.Records.empty());
357362

358363
if (MemProfData.Frames.empty())
359364
MemProfData.Frames = std::move(Incoming.Frames);

0 commit comments

Comments
 (0)