@@ -350,6 +350,7 @@ llvm::performOptimizedStructLayout(MutableArrayRef<Field> Fields) {
350
350
Optional<uint64_t > EndOffset) -> bool {
351
351
assert (Queue->Head );
352
352
assert (StartOffset == alignTo (LastEnd, Queue->Alignment ));
353
+ assert (!EndOffset || StartOffset < *EndOffset);
353
354
354
355
// Figure out the maximum size that a field can be, and ignore this
355
356
// queue if there's nothing in it that small.
@@ -372,6 +373,7 @@ llvm::performOptimizedStructLayout(MutableArrayRef<Field> Fields) {
372
373
// Helper function to find the "best" flexible-offset field according
373
374
// to the criteria described above.
374
375
auto tryAddBestField = [&](Optional<uint64_t > BeforeOffset) -> bool {
376
+ assert (!BeforeOffset || LastEnd < *BeforeOffset);
375
377
auto QueueB = FlexibleFieldsByAlignment.begin ();
376
378
auto QueueE = FlexibleFieldsByAlignment.end ();
377
379
@@ -403,9 +405,12 @@ llvm::performOptimizedStructLayout(MutableArrayRef<Field> Fields) {
403
405
return false ;
404
406
405
407
// Otherwise, scan backwards to find the most-aligned queue that
406
- // still has minimal leading padding after LastEnd.
408
+ // still has minimal leading padding after LastEnd. If that
409
+ // minimal padding is already at or past the end point, we're done.
407
410
--FirstQueueToSearch;
408
411
Offset = alignTo (LastEnd, FirstQueueToSearch->Alignment );
412
+ if (BeforeOffset && Offset >= *BeforeOffset)
413
+ return false ;
409
414
while (FirstQueueToSearch != QueueB &&
410
415
Offset == alignTo (LastEnd, FirstQueueToSearch[-1 ].Alignment ))
411
416
--FirstQueueToSearch;
@@ -415,6 +420,7 @@ llvm::performOptimizedStructLayout(MutableArrayRef<Field> Fields) {
415
420
// Phase 1: fill the gaps between fixed-offset fields with the best
416
421
// flexible-offset field that fits.
417
422
for (auto I = Fields.begin (); I != FirstFlexible; ++I) {
423
+ assert (LastEnd <= I->Offset );
418
424
while (LastEnd != I->Offset ) {
419
425
if (!tryAddBestField (I->Offset ))
420
426
break ;
0 commit comments