mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
Add assertions for out of bound index in ComputeLinearIndex
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225951 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -51,6 +51,7 @@ unsigned llvm::ComputeLinearIndex(Type *Ty,
|
|||||||
return ComputeLinearIndex(*EI, Indices+1, IndicesEnd, CurIndex);
|
return ComputeLinearIndex(*EI, Indices+1, IndicesEnd, CurIndex);
|
||||||
CurIndex = ComputeLinearIndex(*EI, nullptr, nullptr, CurIndex);
|
CurIndex = ComputeLinearIndex(*EI, nullptr, nullptr, CurIndex);
|
||||||
}
|
}
|
||||||
|
assert(!Indices && "Unexpected out of bound");
|
||||||
return CurIndex;
|
return CurIndex;
|
||||||
}
|
}
|
||||||
// Given an array type, recursively traverse the elements.
|
// Given an array type, recursively traverse the elements.
|
||||||
@@ -59,13 +60,13 @@ unsigned llvm::ComputeLinearIndex(Type *Ty,
|
|||||||
unsigned NumElts = ATy->getNumElements();
|
unsigned NumElts = ATy->getNumElements();
|
||||||
// Compute the Linear offset when jumping one element of the array
|
// Compute the Linear offset when jumping one element of the array
|
||||||
unsigned EltLinearOffset = ComputeLinearIndex(EltTy, nullptr, nullptr, 0);
|
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
|
// 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
|
// elt and recurse inside the element with the end of the indices list
|
||||||
CurIndex += EltLinearOffset* *Indices;
|
CurIndex += EltLinearOffset* *Indices;
|
||||||
return ComputeLinearIndex(EltTy, Indices+1, IndicesEnd, CurIndex);
|
return ComputeLinearIndex(EltTy, Indices+1, IndicesEnd, CurIndex);
|
||||||
}
|
}
|
||||||
// Out of bound? Assert instead?
|
|
||||||
CurIndex += EltLinearOffset*NumElts;
|
CurIndex += EltLinearOffset*NumElts;
|
||||||
return CurIndex;
|
return CurIndex;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user