Hi,<div><br></div><div>SmallVector currently always has 16-byte alignment (on x86_64), no matter what type is contained with it, because SmallVectorBase has a long double member.  This causes problems: for instance, ExtractValueInst has 16 byte alignment due to its Indices member (of type SmallVector<unsigned, 4>), but is only allocated with 8 byte alignment.</div>


<div><br></div><div>The attached patch fixes this by removing the long double union hack from SmallVectorBase. Instead, SmallVector's inline storage is represented as a sequence of  llvm::AlignedCharArrayUnion<T> objects, with the first such object living in SmallVectorTemplateCommon<T> rather than in SmallVectorBase.</div>
<div><br></div><div>The downside of this is that SmallVector<T> now always requires T to be a complete type. However, it turns out that no code in LLVM or Clang was deliberately depending on SmallVector<T, 0>'s promise that T is not required to be complete. This did however expose a problem: ArrayRef<T> copy-construction was implicitly instantiating SmallVectorTemplateCommon<T> (and std::vector<T>) during overload resolution. To avoid this, I've added a dummy template parameter to SmallVectorTemplateCommon, so now the ArrayRef(SmallVector) constructor will only be considered if the argument is already of type SmallVector (and not merely if it converts to a SmallVector). I've applied the same change to the ArrayRef(std::vector) constructor, where the same problem exists, but our current standard library implementations happen to allow us to get away with it.</div>


<div><br></div><div>Thanks</div><div>Richard</div>