Fix PR14034, an infloop / heap corruption / crash bug in the new SROA.
[oota-llvm.git] / lib / Transforms / Scalar / SROA.cpp
index b2793893b46189727ed73ed4e8a59cefabd35f87..ca76251492918f27213c529c884399677d7044a8 100644 (file)
@@ -1786,6 +1786,8 @@ static Value *getNaturalGEPWithType(IRBuilder<> &IRB, const DataLayout &TD,
       ElementTy = SeqTy->getElementType();
       Indices.push_back(IRB.getInt(APInt(TD.getPointerSizeInBits(), 0)));
     } else if (StructType *STy = dyn_cast<StructType>(ElementTy)) {
+      if (STy->element_begin() == STy->element_end())
+        break; // Nothing left to descend into.
       ElementTy = *STy->element_begin();
       Indices.push_back(IRB.getInt32(0));
     } else {