[llvm] r225951 - Add assertions for out of bound index in ComputeLinearIndex

Mehdi Amini mehdi.amini at apple.com
Tue Jan 13 21:38:48 PST 2015


Author: mehdi_amini
Date: Tue Jan 13 23:38:48 2015
New Revision: 225951

URL: http://llvm.org/viewvc/llvm-project?rev=225951&view=rev
Log:
Add assertions for out of bound index in ComputeLinearIndex

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

Modified: llvm/trunk/lib/CodeGen/Analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/Analysis.cpp?rev=225951&r1=225950&r2=225951&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/Analysis.cpp (original)
+++ llvm/trunk/lib/CodeGen/Analysis.cpp Tue Jan 13 23:38:48 2015
@@ -51,6 +51,7 @@ unsigned llvm::ComputeLinearIndex(Type *
         return ComputeLinearIndex(*EI, Indices+1, IndicesEnd, CurIndex);
       CurIndex = ComputeLinearIndex(*EI, nullptr, nullptr, CurIndex);
     }
+    assert(!Indices && "Unexpected out of bound");
     return CurIndex;
   }
   // Given an array type, recursively traverse the elements.
@@ -59,13 +60,13 @@ unsigned llvm::ComputeLinearIndex(Type *
     unsigned NumElts = ATy->getNumElements();
     // Compute the Linear offset when jumping one element of the array
     unsigned EltLinearOffset = ComputeLinearIndex(EltTy, nullptr, nullptr, 0);
-    if (Indices && *Indices < NumElts) {
+    if (Indices) {
+      assert(*Indices < NumElts && "Unexpected out of bound");
       // If the indice is inside the array, compute the index to the requested
       // elt and recurse inside the element with the end of the indices list
       CurIndex += EltLinearOffset* *Indices;
       return ComputeLinearIndex(EltTy, Indices+1, IndicesEnd, CurIndex);
     }
-    // Out of bound? Assert instead?
     CurIndex += EltLinearOffset*NumElts;
     return CurIndex;
   }





More information about the llvm-commits mailing list