Fix a bug which caused us to miscompile a couple of Ada
tests.  Thanks for the beautiful reduced testcase Duncan!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63529 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
index 29970ec..0765e12 100644
--- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp
+++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
@@ -1166,12 +1166,17 @@
 static void MergeInType(const Type *In, uint64_t Offset, const Type *&Accum,
                         const TargetData &TD) {
   // If this is our first type, just use it.
-  if (Accum == 0 || In == Type::VoidTy ||
+  if ((Accum == 0 && Offset == 0) || In == Type::VoidTy ||
       // Or if this is a same type, keep it.
       (In == Accum && Offset == 0)) {
     Accum = In;
     return;
   }
+
+  // Merging something like i32 into offset 8 means that a "field" is merged in
+  // before the basic type is.  Make sure to consider the offset below.
+  if (Accum == 0)
+    Accum = Type::Int8Ty;
   
   if (const VectorType *VATy = dyn_cast<VectorType>(Accum)) {
     if (VATy->getElementType() == In &&