Skip to content

Commit 393aebf

Browse files
authored
CodeView: Move MCCVDefRangeFragment storage to MCContext/MCFragment. NFC (#146462)
so that ~MCCVInlineLineTableFragment will become trivial when we make ~MCEncodedFragment trivial (#146307).
1 parent 67b740b commit 393aebf

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

llvm/include/llvm/MC/MCCodeView.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/ADT/SmallVector.h"
1919
#include "llvm/ADT/StringMap.h"
2020
#include "llvm/ADT/StringRef.h"
21+
#include <deque>
2122
#include <map>
2223
#include <vector>
2324

@@ -268,6 +269,10 @@ class CodeViewContext {
268269
/// Indicate whether we have already laid out the checksum table addresses or
269270
/// not.
270271
bool ChecksumOffsetsAssigned = false;
272+
273+
/// Append-only storage of MCCVDefRangeFragment::Ranges.
274+
std::deque<SmallVector<std::pair<const MCSymbol *, const MCSymbol *>, 0>>
275+
DefRangeStorage;
271276
};
272277

273278
} // end namespace llvm

llvm/include/llvm/MC/MCSection.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,8 @@ class MCCVInlineLineTableFragment : public MCFragment {
675675

676676
/// Fragment representing the .cv_def_range directive.
677677
class MCCVDefRangeFragment : public MCEncodedFragmentWithFixups<32, 4> {
678-
SmallVector<std::pair<const MCSymbol *, const MCSymbol *>, 2> Ranges;
679-
SmallString<32> FixedSizePortion;
678+
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges;
679+
StringRef FixedSizePortion;
680680

681681
/// CodeViewContext has the real knowledge about this format, so let it access
682682
/// our members.
@@ -693,7 +693,7 @@ class MCCVDefRangeFragment : public MCEncodedFragmentWithFixups<32, 4> {
693693
return Ranges;
694694
}
695695

696-
StringRef getFixedSizePortion() const { return FixedSizePortion.str(); }
696+
StringRef getFixedSizePortion() const { return FixedSizePortion; }
697697

698698
static bool classof(const MCFragment *F) {
699699
return F->getKind() == MCFragment::FT_CVDefRange;

llvm/lib/MC/MCCodeView.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,13 @@ MCFragment *CodeViewContext::emitDefRange(
442442
MCObjectStreamer &OS,
443443
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
444444
StringRef FixedSizePortion) {
445+
// Store `Ranges` and `FixedSizePortion` in the context, returning references,
446+
// as MCCVDefRangeFragment does not own these objects.
447+
FixedSizePortion = MCCtx->allocateString(FixedSizePortion);
448+
auto &Saved = DefRangeStorage.emplace_back(Ranges.begin(), Ranges.end());
445449
// Create and insert a fragment into the current section that will be encoded
446450
// later.
447-
auto *F =
448-
MCCtx->allocFragment<MCCVDefRangeFragment>(Ranges, FixedSizePortion);
451+
auto *F = MCCtx->allocFragment<MCCVDefRangeFragment>(Saved, FixedSizePortion);
449452
OS.insert(F);
450453
return F;
451454
}

0 commit comments

Comments
 (0)