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:
Lang Hames
2013-02-27 04:14:49 +00:00
parent 2ce6b43f40
commit 1694e0d21d
2 changed files with 24 additions and 7 deletions

View File

@@ -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();