aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorMehdi Amini <mehdi.amini@apple.com>2015-01-14 05:38:48 +0000
committerMehdi Amini <mehdi.amini@apple.com>2015-01-14 05:38:48 +0000
commit7b068f6ba4d8d36fc55eef964af792f2665af513 (patch)
tree573767efedcdbffc7e14d26f6197c1f9d4b16feb /llvm/lib
parentaa32297fb85ddd9719e7729a3e76311536ffaf75 (diff)
downloadllvm-7b068f6ba4d8d36fc55eef964af792f2665af513.zip
llvm-7b068f6ba4d8d36fc55eef964af792f2665af513.tar.gz
llvm-7b068f6ba4d8d36fc55eef964af792f2665af513.tar.bz2
Add assertions for out of bound index in ComputeLinearIndex
llvm-svn: 225951
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/Analysis.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/Analysis.cpp b/llvm/lib/CodeGen/Analysis.cpp
index 06826b6..2e8af9e 100644
--- a/llvm/lib/CodeGen/Analysis.cpp
+++ b/llvm/lib/CodeGen/Analysis.cpp
@@ -51,6 +51,7 @@ unsigned llvm::ComputeLinearIndex(Type *Ty,
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 *Ty,
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;
}