[llvm] r270492 - PrologEpilogInserter: Avoid an infinite loop when MinCSFrameIndex == 0

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Mon May 23 14:40:52 PDT 2016


Author: bogner
Date: Mon May 23 16:40:52 2016
New Revision: 270492

URL: http://llvm.org/viewvc/llvm-project?rev=270492&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp

Modified: llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp?rev=270492&r1=270491&r2=270492&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp (original)
+++ llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp Mon May 23 16:40:52 2016
@@ -654,9 +654,9 @@ void PEI::calculateFrameObjectOffsets(Ma
       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);




More information about the llvm-commits mailing list