diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp index 08a6536b78a..54acd08966e 100644 --- a/lib/Target/TargetData.cpp +++ b/lib/Target/TargetData.cpp @@ -159,15 +159,15 @@ uint64_t TargetData::getIndexedOffset(const Type *ptrTy, for (unsigned CurIDX = 0; CurIDX < Idx.size(); ++CurIDX) { if (Idx[CurIDX]->getType() == Type::UIntTy) { + // Update Ty to refer to current element + Ty = cast(Ty)->getElementType(); + // Get the array index and the size of each array element. // Both must be known constants, or this will fail. unsigned arrayIdx = cast(Idx[CurIDX])->getValue(); uint64_t elementSize = this->getTypeSize(Ty); Result += arrayIdx * elementSize; - // Update Ty to refer to current element - Ty = cast(Ty)->getElementType(); - } else if (const StructType *STy = dyn_cast(Ty)) { assert(Idx[CurIDX]->getType() == Type::UByteTy && "Illegal struct idx"); unsigned FieldNo = cast(Idx[CurIDX])->getValue();