summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2016-05-23 21:40:52 +0000
committerJustin Bogner <mail@justinbogner.com>2016-05-23 21:40:52 +0000
commitb10244d0923e7a70e4ac1a40eeaa06454d93e6e7 (patch)
tree4af827105f64c7e300a2aa6f46148537033bd2bf
parent866cdd590de5c5b172be2735a643d4c36a691193 (diff)
PrologEpilogInserter: Avoid an infinite loop when MinCSFrameIndex == 0
Before r269750 we did the comparisons in this loop in signed ints so that it DTRT when MinCSFrameIndex was 0. This was changed because it's now possible for MinCSFrameIndex to be UINT_MAX, but that introduced a bug when we were comparing `>= 0` - this is tautological in unsigned. Rework the comparisons here to avoid issues with unsigned wrapping. No test. I couldn't find a way to get any of the StackGrowsUp in-tree targets to reach the code that sets MinCSFrameIndex. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270492 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/PrologEpilogInserter.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/CodeGen/PrologEpilogInserter.cpp b/lib/CodeGen/PrologEpilogInserter.cpp
index a119b1c62eb..f61c0cb6da0 100644
--- a/lib/CodeGen/PrologEpilogInserter.cpp
+++ b/lib/CodeGen/PrologEpilogInserter.cpp
@@ -654,9 +654,9 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) {
DEBUG(dbgs() << "alloc FI(" << i << ") at SP[" << -Offset << "]\n");
MFI->setObjectOffset(i, -Offset); // Set the computed offset
}
- } else {
- unsigned MaxCSFI = MaxCSFrameIndex, MinCSFI = MinCSFrameIndex;
- for (unsigned i = MaxCSFI; i >= MinCSFI; --i) {
+ } else if (MaxCSFrameIndex >= MinCSFrameIndex) {
+ // Be careful about underflow in comparisons agains MinCSFrameIndex.
+ for (unsigned i = MaxCSFrameIndex; i != MinCSFrameIndex - 1; --i) {
unsigned Align = MFI->getObjectAlignment(i);
// Adjust to alignment boundary
Offset = alignTo(Offset, Align, Skew);