diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2021-08-22 19:00:43 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2021-11-13 20:39:49 +0000 |
commit | fe6060f10f634930ff71b7c50291ddc610da2475 (patch) | |
tree | 1483580c790bd4d27b6500a7542b5ee00534d3cc /contrib/llvm-project/llvm/lib/Support/OptimizedStructLayout.cpp | |
parent | b61bce17f346d79cecfd8f195a64b10f77be43b1 (diff) | |
parent | 344a3780b2e33f6ca763666c380202b18aab72a3 (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/OptimizedStructLayout.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Support/OptimizedStructLayout.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/OptimizedStructLayout.cpp b/contrib/llvm-project/llvm/lib/Support/OptimizedStructLayout.cpp index 9bbd767c5ce9..19a93ed6776d 100644 --- a/contrib/llvm-project/llvm/lib/Support/OptimizedStructLayout.cpp +++ b/contrib/llvm-project/llvm/lib/Support/OptimizedStructLayout.cpp @@ -350,6 +350,7 @@ llvm::performOptimizedStructLayout(MutableArrayRef<Field> Fields) { Optional<uint64_t> EndOffset) -> bool { assert(Queue->Head); assert(StartOffset == alignTo(LastEnd, Queue->Alignment)); + assert(!EndOffset || StartOffset < *EndOffset); // Figure out the maximum size that a field can be, and ignore this // queue if there's nothing in it that small. @@ -372,6 +373,7 @@ llvm::performOptimizedStructLayout(MutableArrayRef<Field> Fields) { // Helper function to find the "best" flexible-offset field according // to the criteria described above. auto tryAddBestField = [&](Optional<uint64_t> BeforeOffset) -> bool { + assert(!BeforeOffset || LastEnd < *BeforeOffset); auto QueueB = FlexibleFieldsByAlignment.begin(); auto QueueE = FlexibleFieldsByAlignment.end(); @@ -403,9 +405,12 @@ llvm::performOptimizedStructLayout(MutableArrayRef<Field> Fields) { return false; // Otherwise, scan backwards to find the most-aligned queue that - // still has minimal leading padding after LastEnd. + // still has minimal leading padding after LastEnd. If that + // minimal padding is already at or past the end point, we're done. --FirstQueueToSearch; Offset = alignTo(LastEnd, FirstQueueToSearch->Alignment); + if (BeforeOffset && Offset >= *BeforeOffset) + return false; while (FirstQueueToSearch != QueueB && Offset == alignTo(LastEnd, FirstQueueToSearch[-1].Alignment)) --FirstQueueToSearch; @@ -415,6 +420,7 @@ llvm::performOptimizedStructLayout(MutableArrayRef<Field> Fields) { // Phase 1: fill the gaps between fixed-offset fields with the best // flexible-offset field that fits. for (auto I = Fields.begin(); I != FirstFlexible; ++I) { + assert(LastEnd <= I->Offset); while (LastEnd != I->Offset) { if (!tryAddBestField(I->Offset)) break; |