diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp --- a/llvm/lib/Transforms/Scalar/SROA.cpp +++ b/llvm/lib/Transforms/Scalar/SROA.cpp @@ -1549,9 +1549,13 @@ const Twine &NamePrefix) { // Create i8 GEP for opaque pointers. if (Ptr->getType()->isOpaquePointerTy()) { - if (Offset != 0) - Ptr = IRB.CreateInBoundsGEP(IRB.getInt8Ty(), Ptr, IRB.getInt(Offset), + if (Offset != 0) { + Type *Int8Ty = IRB.getInt8Ty(); + // This may fail due to alignment + assert(DL.getTypeAllocSize(Int8Ty) == 1 && "Unexpected I8 size!"); + Ptr = IRB.CreateInBoundsGEP(Int8Ty, Ptr, IRB.getInt(Offset), NamePrefix + "sroa_idx"); + } return IRB.CreatePointerBitCastOrAddrSpaceCast(Ptr, PointerTy, NamePrefix + "sroa_cast"); } @@ -1640,11 +1644,14 @@ Int8PtrOffset = Offset; } - OffsetPtr = Int8PtrOffset == 0 - ? Int8Ptr - : IRB.CreateInBoundsGEP(IRB.getInt8Ty(), Int8Ptr, - IRB.getInt(Int8PtrOffset), - NamePrefix + "sroa_raw_idx"); + Type *Int8Ty = IRB.getInt8Ty(); + // This may fail due to alignment + assert(DL.getTypeAllocSize(Int8Ty) == 1 && "Unexpected I8 size!"); + OffsetPtr = + Int8PtrOffset == 0 + ? Int8Ptr + : IRB.CreateInBoundsGEP(Int8Ty, Int8Ptr, IRB.getInt(Int8PtrOffset), + NamePrefix + "sroa_raw_idx"); } Ptr = OffsetPtr;