From 393aebf5c218c74cdad381610ed05bd6d048f532 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 30 Jun 2025 21:49:54 -0700 Subject: [PATCH] CodeView: Move MCCVDefRangeFragment storage to MCContext/MCFragment. NFC (#146462) so that ~MCCVInlineLineTableFragment will become trivial when we make ~MCEncodedFragment trivial (#146307). --- llvm/include/llvm/MC/MCCodeView.h | 5 +++++ llvm/include/llvm/MC/MCSection.h | 6 +++--- llvm/lib/MC/MCCodeView.cpp | 7 +++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/MC/MCCodeView.h b/llvm/include/llvm/MC/MCCodeView.h index 2a57e04b2c88..88f84a246284 100644 --- a/llvm/include/llvm/MC/MCCodeView.h +++ b/llvm/include/llvm/MC/MCCodeView.h @@ -18,6 +18,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" +#include #include #include @@ -268,6 +269,10 @@ private: /// Indicate whether we have already laid out the checksum table addresses or /// not. bool ChecksumOffsetsAssigned = false; + + /// Append-only storage of MCCVDefRangeFragment::Ranges. + std::deque, 0>> + DefRangeStorage; }; } // end namespace llvm diff --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h index d85a5893496f..7451ed603547 100644 --- a/llvm/include/llvm/MC/MCSection.h +++ b/llvm/include/llvm/MC/MCSection.h @@ -675,8 +675,8 @@ public: /// Fragment representing the .cv_def_range directive. class MCCVDefRangeFragment : public MCEncodedFragmentWithFixups<32, 4> { - SmallVector, 2> Ranges; - SmallString<32> FixedSizePortion; + ArrayRef> Ranges; + StringRef FixedSizePortion; /// CodeViewContext has the real knowledge about this format, so let it access /// our members. @@ -693,7 +693,7 @@ public: return Ranges; } - StringRef getFixedSizePortion() const { return FixedSizePortion.str(); } + StringRef getFixedSizePortion() const { return FixedSizePortion; } static bool classof(const MCFragment *F) { return F->getKind() == MCFragment::FT_CVDefRange; diff --git a/llvm/lib/MC/MCCodeView.cpp b/llvm/lib/MC/MCCodeView.cpp index 1407bc52e1c4..e8f04271e84c 100644 --- a/llvm/lib/MC/MCCodeView.cpp +++ b/llvm/lib/MC/MCCodeView.cpp @@ -442,10 +442,13 @@ MCFragment *CodeViewContext::emitDefRange( MCObjectStreamer &OS, ArrayRef> Ranges, StringRef FixedSizePortion) { + // Store `Ranges` and `FixedSizePortion` in the context, returning references, + // as MCCVDefRangeFragment does not own these objects. + FixedSizePortion = MCCtx->allocateString(FixedSizePortion); + auto &Saved = DefRangeStorage.emplace_back(Ranges.begin(), Ranges.end()); // Create and insert a fragment into the current section that will be encoded // later. - auto *F = - MCCtx->allocFragment(Ranges, FixedSizePortion); + auto *F = MCCtx->allocFragment(Saved, FixedSizePortion); OS.insert(F); return F; }