Fix PR10104 by adding a bounds check on a vector element access check. It was
[oota-llvm.git] / lib / Transforms / Scalar / ScalarReplAggregates.cpp
index 9f286b564227bf2933e0c98184038f172d458115..09e597fe666250bd5ea926ed1291a1c2319bd1da 100644 (file)
@@ -342,7 +342,10 @@ void ConvertToScalarInfo::MergeInType(const Type *In, uint64_t Offset,
     // If we're accessing something that could be an element of a vector, see
     // if the implied vector agrees with what we already have and if Offset is
     // compatible with it.
-    if (Offset % EltSize == 0 && AllocaSize % EltSize == 0) {
+    if (Offset % EltSize == 0 && AllocaSize % EltSize == 0 &&
+        Offset * 8 <
+          (VectorTy ? VectorTy->getPrimitiveSizeInBits()
+                    : (AllocaSize / EltSize) * In->getPrimitiveSizeInBits())) {
       if (!VectorTy) {
         VectorTy = VectorType::get(In, AllocaSize/EltSize);
         return;