diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1334,7 +1334,8 @@ void CodeGenFunction::EmitAggregateStore(llvm::Value *Val, Address Dest, bool DestIsVolatile) { // Prefer scalar stores to first-class aggregate stores. - if (llvm::StructType *STy = dyn_cast(Val->getType())) { + llvm::StructType *STy = dyn_cast(Val->getType()); + if (STy && STy->isLayoutIdentical(cast(Dest.getElementType()))) { for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { Address EltPtr = Builder.CreateStructGEP(Dest, i); llvm::Value *Elt = Builder.CreateExtractValue(Val, i);