Use the correct alignment for POD-member memcpys where the first field is a
bitfield. CGBitField::StorageAlignment holds the alignment in chars, but emitMemcpy had been treating it as if it were held in bits, leading to underaligned memcpys. Related to PR15348. Thanks very much to Chandler for the diagnosis. llvm-svn: 176163
This commit is contained in:
@@ -788,19 +788,22 @@ namespace {
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned FirstFieldAlign = ~0U; // Set to invalid.
|
||||
CharUnits Alignment;
|
||||
|
||||
if (FirstField->isBitField()) {
|
||||
const CGRecordLayout &RL =
|
||||
CGF.getTypes().getCGRecordLayout(FirstField->getParent());
|
||||
const CGBitFieldInfo &BFInfo = RL.getBitFieldInfo(FirstField);
|
||||
FirstFieldAlign = BFInfo.StorageAlignment;
|
||||
} else
|
||||
FirstFieldAlign = CGF.getContext().getTypeAlign(FirstField->getType());
|
||||
Alignment = CharUnits::fromQuantity(BFInfo.StorageAlignment);
|
||||
} else {
|
||||
unsigned AlignBits =
|
||||
CGF.getContext().getTypeAlign(FirstField->getType());
|
||||
Alignment = CGF.getContext().toCharUnitsFromBits(AlignBits);
|
||||
}
|
||||
|
||||
assert((CGF.getContext().toCharUnitsFromBits(FirstFieldOffset) %
|
||||
Alignment) == 0 && "Bad field alignment.");
|
||||
|
||||
assert(FirstFieldOffset % FirstFieldAlign == 0 && "Bad field alignment.");
|
||||
CharUnits Alignment =
|
||||
CGF.getContext().toCharUnitsFromBits(FirstFieldAlign);
|
||||
CharUnits MemcpySize = getMemcpySize();
|
||||
QualType RecordTy = CGF.getContext().getTypeDeclType(ClassDecl);
|
||||
llvm::Value *ThisPtr = CGF.LoadCXXThis();
|
||||
|
||||
Reference in New Issue
Block a user