[server-llvm-21][MC] Fixing vector overflow · llvm/llvm-project@9ed1927 (original) (raw)
`@@ -298,8 +298,8 @@ class MCFragment {
`
298
298
`/// data.
`
299
299
`class MCEncodedFragment : public MCFragment {
`
300
300
`uint8_t BundlePadding = 0;
`
301
``
`-
uint32_t ContentStart = 0;
`
302
``
`-
uint32_t ContentEnd = 0;
`
``
301
`+
uint32_t ContentSize = 0;
`
``
302
`+
uint64_t ContentStart = 0;
`
303
303
`uint32_t FixupStart = 0;
`
304
304
`uint32_t FixupEnd = 0;
`
305
305
``
`@@ -360,22 +360,23 @@ class MCEncodedFragment : public MCFragment {
`
360
360
``
361
361
`// Content-related functions manage parent's storage using ContentStart and
`
362
362
`// ContentSize.
`
363
``
`-
void clearContents() { ContentEnd = ContentStart; }
`
``
363
`+
void clearContents() { ContentSize = 0; }
`
364
364
`// Get a SmallVector reference. The caller should call doneAppending to update
`
365
``
`` -
// ContentEnd.
``
``
365
`` +
// ContentSize.
``
366
366
` SmallVectorImpl &getContentsForAppending() {
`
367
367
` SmallVectorImpl &S = getParent()->ContentStorage;
`
368
``
`-
if (LLVM_UNLIKELY(ContentEnd != S.size())) {
`
``
368
`+
if (LLVM_UNLIKELY(ContentStart + ContentSize != S.size())) {
`
369
369
`// Move the elements to the end. Reserve space to avoid invalidating
`
370
370
`` // S.begin()+I for append.
``
371
``
`-
auto Size = ContentEnd - ContentStart;
`
372
371
`auto I = std::exchange(ContentStart, S.size());
`
373
``
`-
S.reserve(S.size() + Size);
`
374
``
`-
S.append(S.begin() + I, S.begin() + I + Size);
`
``
372
`+
S.reserve(S.size() + ContentSize);
`
``
373
`+
S.append(S.begin() + I, S.begin() + I + ContentSize);
`
375
374
` }
`
376
375
`return S;
`
377
376
` }
`
378
``
`-
void doneAppending() { ContentEnd = getParent()->ContentStorage.size(); }
`
``
377
`+
void doneAppending() {
`
``
378
`+
ContentSize = getParent()->ContentStorage.size() - ContentStart;
`
``
379
`+
}
`
379
380
`void appendContents(ArrayRef Contents) {
`
380
381
`getContentsForAppending().append(Contents.begin(), Contents.end());
`
381
382
`doneAppending();
`
`@@ -387,11 +388,11 @@ class MCEncodedFragment : public MCFragment {
`
387
388
` LLVM_ABI void setContents(ArrayRef Contents);
`
388
389
` MutableArrayRef getContents() {
`
389
390
`return MutableArrayRef(getParent()->ContentStorage)
`
390
``
`-
.slice(ContentStart, ContentEnd - ContentStart);
`
``
391
`+
.slice(ContentStart, ContentSize);
`
391
392
` }
`
392
393
` ArrayRef getContents() const {
`
393
394
`return ArrayRef(getParent()->ContentStorage)
`
394
``
`-
.slice(ContentStart, ContentEnd - ContentStart);
`
``
395
`+
.slice(ContentStart, ContentSize);
`
395
396
` }
`
396
397
``
397
398
`// Fixup-related functions manage parent's storage using FixupStart and
`
`@@ -409,7 +410,7 @@ class MCEncodedFragment : public MCFragment {
`
409
410
` .slice(FixupStart, FixupEnd - FixupStart);
`
410
411
` }
`
411
412
``
412
``
`-
size_t getSize() const { return ContentEnd - ContentStart; }
`
``
413
`+
size_t getSize() const { return ContentSize; }
`
413
414
`};
`
414
415
``
415
416
`/// Fragment for data and encoded instructions.
`