Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions llvm/include/llvm/MC/MCSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ class MCFragment {
/// data.
class MCEncodedFragment : public MCFragment {
uint8_t BundlePadding = 0;
uint32_t ContentStart = 0;
uint32_t ContentEnd = 0;
uint32_t ContentSize = 0;
uint64_t ContentStart = 0;
uint32_t FixupStart = 0;
uint32_t FixupEnd = 0;

Expand Down Expand Up @@ -360,22 +360,23 @@ class MCEncodedFragment : public MCFragment {

// Content-related functions manage parent's storage using ContentStart and
// ContentSize.
void clearContents() { ContentEnd = ContentStart; }
void clearContents() { ContentSize = 0; }
// Get a SmallVector reference. The caller should call doneAppending to update
// `ContentEnd`.
// `ContentSize`.
SmallVectorImpl<char> &getContentsForAppending() {
SmallVectorImpl<char> &S = getParent()->ContentStorage;
if (LLVM_UNLIKELY(ContentEnd != S.size())) {
if (LLVM_UNLIKELY(ContentStart + ContentSize != S.size())) {
// Move the elements to the end. Reserve space to avoid invalidating
// S.begin()+I for `append`.
auto Size = ContentEnd - ContentStart;
auto I = std::exchange(ContentStart, S.size());
S.reserve(S.size() + Size);
S.append(S.begin() + I, S.begin() + I + Size);
S.reserve(S.size() + ContentSize);
S.append(S.begin() + I, S.begin() + I + ContentSize);
}
return S;
}
void doneAppending() { ContentEnd = getParent()->ContentStorage.size(); }
void doneAppending() {
ContentSize = getParent()->ContentStorage.size() - ContentStart;
}
void appendContents(ArrayRef<char> Contents) {
getContentsForAppending().append(Contents.begin(), Contents.end());
doneAppending();
Expand All @@ -387,11 +388,11 @@ class MCEncodedFragment : public MCFragment {
LLVM_ABI void setContents(ArrayRef<char> Contents);
MutableArrayRef<char> getContents() {
return MutableArrayRef(getParent()->ContentStorage)
.slice(ContentStart, ContentEnd - ContentStart);
.slice(ContentStart, ContentSize);
}
ArrayRef<char> getContents() const {
return ArrayRef(getParent()->ContentStorage)
.slice(ContentStart, ContentEnd - ContentStart);
.slice(ContentStart, ContentSize);
}

// Fixup-related functions manage parent's storage using FixupStart and
Expand All @@ -409,7 +410,7 @@ class MCEncodedFragment : public MCFragment {
.slice(FixupStart, FixupEnd - FixupStart);
}

size_t getSize() const { return ContentEnd - ContentStart; }
size_t getSize() const { return ContentSize; }
};

/// Fragment for data and encoded instructions.
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/MC/MCSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ LLVM_DUMP_METHOD void MCSection::dump(

void MCEncodedFragment::setContents(ArrayRef<char> Contents) {
auto &S = getParent()->ContentStorage;
if (ContentStart + Contents.size() > ContentEnd) {
if (Contents.size() > ContentSize) {
ContentStart = S.size();
S.resize_for_overwrite(S.size() + Contents.size());
}
ContentEnd = ContentStart + Contents.size();
ContentSize = Contents.size();
llvm::copy(Contents, S.begin() + ContentStart);
}

Expand Down
Loading