Skip to content

CodeView: Move MCCVDefRangeFragment storage to MCContext/MCFragment. NFC #146462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2025

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented Jul 1, 2025

so that ~MCCVInlineLineTableFragment will become trivial when we
make ~MCEncodedFragment trivial (#146307).

so that ~MCCVInlineLineTableFragment will become trivial when we
make ~MCEncodedFragment trivial (llvm#146307).
@llvmbot llvmbot added the mc Machine (object) code label Jul 1, 2025
@MaskRay MaskRay added skip-precommit-approval PR for CI feedback, not intended for review and removed mc Machine (object) code labels Jul 1, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 1, 2025

@llvm/pr-subscribers-mc

Author: Fangrui Song (MaskRay)

Changes

so that ~MCCVInlineLineTableFragment will become trivial when we
make ~MCEncodedFragment trivial (#146307).


Full diff: https://github.com/llvm/llvm-project/pull/146462.diff

3 Files Affected:

  • (modified) llvm/include/llvm/MC/MCCodeView.h (+5)
  • (modified) llvm/include/llvm/MC/MCSection.h (+3-3)
  • (modified) llvm/lib/MC/MCCodeView.cpp (+5-2)
diff --git a/llvm/include/llvm/MC/MCCodeView.h b/llvm/include/llvm/MC/MCCodeView.h
index 2a57e04b2c88c..88f84a2462841 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 <deque>
 #include <map>
 #include <vector>
 
@@ -268,6 +269,10 @@ class CodeViewContext {
   /// Indicate whether we have already laid out the checksum table addresses or
   /// not.
   bool ChecksumOffsetsAssigned = false;
+
+  /// Append-only storage of MCCVDefRangeFragment::Ranges.
+  std::deque<SmallVector<std::pair<const MCSymbol *, const MCSymbol *>, 0>>
+      DefRangeStorage;
 };
 
 } // end namespace llvm
diff --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h
index d85a5893496f3..7451ed6035471 100644
--- a/llvm/include/llvm/MC/MCSection.h
+++ b/llvm/include/llvm/MC/MCSection.h
@@ -675,8 +675,8 @@ class MCCVInlineLineTableFragment : public MCFragment {
 
 /// Fragment representing the .cv_def_range directive.
 class MCCVDefRangeFragment : public MCEncodedFragmentWithFixups<32, 4> {
-  SmallVector<std::pair<const MCSymbol *, const MCSymbol *>, 2> Ranges;
-  SmallString<32> FixedSizePortion;
+  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges;
+  StringRef FixedSizePortion;
 
   /// CodeViewContext has the real knowledge about this format, so let it access
   /// our members.
@@ -693,7 +693,7 @@ class MCCVDefRangeFragment : public MCEncodedFragmentWithFixups<32, 4> {
     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 1407bc52e1c46..e8f04271e84ce 100644
--- a/llvm/lib/MC/MCCodeView.cpp
+++ b/llvm/lib/MC/MCCodeView.cpp
@@ -442,10 +442,13 @@ MCFragment *CodeViewContext::emitDefRange(
     MCObjectStreamer &OS,
     ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> 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<MCCVDefRangeFragment>(Ranges, FixedSizePortion);
+  auto *F = MCCtx->allocFragment<MCCVDefRangeFragment>(Saved, FixedSizePortion);
   OS.insert(F);
   return F;
 }

@MaskRay MaskRay merged commit 393aebf into llvm:main Jul 1, 2025
9 of 10 checks passed
@MaskRay MaskRay deleted the codeview branch July 1, 2025 04:50
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
…NFC (llvm#146462)

so that ~MCCVInlineLineTableFragment will become trivial when we
make ~MCEncodedFragment trivial (llvm#146307).
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
…NFC (llvm#146462)

so that ~MCCVInlineLineTableFragment will become trivial when we
make ~MCEncodedFragment trivial (llvm#146307).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip-precommit-approval PR for CI feedback, not intended for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants