[llvm] r225069 - [SROA] Fix the loop exit placement to be prior to indexing the splits

Chandler Carruth chandlerc at gmail.com
Thu Jan 1 16:10:22 PST 2015


Author: chandlerc
Date: Thu Jan  1 18:10:22 2015
New Revision: 225069

URL: http://llvm.org/viewvc/llvm-project?rev=225069&view=rev
Log:
[SROA] Fix the loop exit placement to be prior to indexing the splits
array. This prevents it from walking out of bounds on the splits array.

Bug found with the existing tests by ASan and by the MSVC debug build.

Modified:
    llvm/trunk/lib/Transforms/Scalar/SROA.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/SROA.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=225069&r1=225068&r2=225069&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SROA.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SROA.cpp Thu Jan  1 18:10:22 2015
@@ -3706,11 +3706,13 @@ bool SROA::presplitLoadsAndStores(Alloca
                    << ", " << NewSlices.back().endOffset() << "): " << *PLoad
                    << "\n");
 
+      // See if we've handled all the splits.
+      if (Idx >= Size)
+        break;
+
       // Setup the next partition.
       PartOffset = Offsets.Splits[Idx];
       ++Idx;
-      if (Idx > Size)
-        break;
       PartSize = (Idx < Size ? Offsets.Splits[Idx] : LoadSize) - PartOffset;
     }
 
@@ -3845,11 +3847,13 @@ bool SROA::presplitLoadsAndStores(Alloca
         DEBUG(dbgs() << "      of split load: " << *PLoad << "\n");
       }
 
+      // See if we've finished all the splits.
+      if (Idx >= Size)
+        break;
+
       // Setup the next partition.
       PartOffset = Offsets.Splits[Idx];
       ++Idx;
-      if (Idx > Size)
-        break;
       PartSize = (Idx < Size ? Offsets.Splits[Idx] : StoreSize) - PartOffset;
     }
 





More information about the llvm-commits mailing list