/// alignment.
void FinishLayout(const NamedDecl *D);
- void UpdateAlignment(unsigned NewAlignment, unsigned UnpackedNewAlignment);
- void UpdateAlignment(unsigned NewAlignment) {
+ void UpdateAlignment(CharUnits NewAlignment, CharUnits UnpackedNewAlignment);
+ void UpdateAlignment(CharUnits NewAlignment) {
UpdateAlignment(NewAlignment, NewAlignment);
}
Size += GetVirtualPointersSize(RD);
DataSize = Size;
- unsigned UnpackedBaseAlign = Context.Target.getPointerAlign(0);
- unsigned BaseAlign = (Packed) ? 8 : UnpackedBaseAlign;
+ CharUnits UnpackedBaseAlign =
+ Context.toCharUnitsFromBits(Context.Target.getPointerAlign(0));
+ CharUnits BaseAlign = (Packed) ? CharUnits::One() : UnpackedBaseAlign;
// The maximum field alignment overrides base align.
if (!MaxFieldAlignment.isZero()) {
- unsigned MaxFieldAlignmentInBits = Context.toBits(MaxFieldAlignment);
- BaseAlign = std::min(BaseAlign, MaxFieldAlignmentInBits);
- UnpackedBaseAlign = std::min(UnpackedBaseAlign, MaxFieldAlignmentInBits);
+ BaseAlign = std::min(BaseAlign, MaxFieldAlignment);
+ UnpackedBaseAlign = std::min(UnpackedBaseAlign, MaxFieldAlignment);
}
// Update the alignment.
return CharUnits::Zero();
}
- unsigned UnpackedBaseAlign = Context.toBits(Layout.getNonVirtualAlign());
- unsigned BaseAlign = (Packed) ? 8 : UnpackedBaseAlign;
+ CharUnits UnpackedBaseAlign = Layout.getNonVirtualAlign();
+ CharUnits BaseAlign = (Packed) ? CharUnits::One() : UnpackedBaseAlign;
// The maximum field alignment overrides base align.
if (!MaxFieldAlignment.isZero()) {
- unsigned MaxFieldAlignmentInBits = Context.toBits(MaxFieldAlignment);
- BaseAlign = std::min(BaseAlign, MaxFieldAlignmentInBits);
- UnpackedBaseAlign = std::min(UnpackedBaseAlign, MaxFieldAlignmentInBits);
+ BaseAlign = std::min(BaseAlign, MaxFieldAlignment);
+ UnpackedBaseAlign = std::min(UnpackedBaseAlign, MaxFieldAlignment);
}
// Round up the current record size to the base's alignment boundary.
- uint64_t Offset = llvm::RoundUpToAlignment(DataSize, BaseAlign);
+ uint64_t Offset =
+ llvm::RoundUpToAlignment(DataSize, Context.toBits(BaseAlign));
// Try to place the base.
while (!EmptySubobjects->CanPlaceBaseAtOffset(Base,
Context.toCharUnitsFromBits(Offset)))
- Offset += BaseAlign;
+ Offset += Context.toBits(BaseAlign);
if (!Base->Class->isEmpty()) {
// Update the data size.
MaxFieldAlignment = Context.toCharUnitsFromBits(MFAA->getAlignment());
if (unsigned MaxAlign = D->getMaxAlignment())
- UpdateAlignment(MaxAlign);
+ UpdateAlignment(Context.toCharUnitsFromBits(MaxAlign));
}
}
if (ObjCInterfaceDecl *SD = D->getSuperClass()) {
const ASTRecordLayout &SL = Context.getASTObjCInterfaceLayout(SD);
- UpdateAlignment(Context.toBits(SL.getAlignment()));
+ UpdateAlignment(SL.getAlignment());
// We start laying out ivars not at the end of the superclass
// structure, but at the next byte following the last field.
Size = std::max(Size, DataSize);
// Remember max struct/class alignment.
- UpdateAlignment(TypeAlign);
+ UpdateAlignment(Context.toCharUnitsFromBits(TypeAlign));
}
void RecordLayoutBuilder::LayoutBitField(const FieldDecl *D) {
Size = std::max(Size, DataSize);
// Remember max struct/class alignment.
- UpdateAlignment(FieldAlign, UnpackedFieldAlign);
+ UpdateAlignment(Context.toCharUnitsFromBits(FieldAlign),
+ Context.toCharUnitsFromBits(UnpackedFieldAlign));
}
void RecordLayoutBuilder::LayoutField(const FieldDecl *D) {
DataSize = Size;
// Remember max struct/class alignment.
- UpdateAlignment(FieldAlign, UnpackedFieldAlign);
+ UpdateAlignment(Context.toCharUnitsFromBits(FieldAlign),
+ Context.toCharUnitsFromBits(UnpackedFieldAlign));
}
void RecordLayoutBuilder::FinishLayout(const NamedDecl *D) {
}
}
-void RecordLayoutBuilder::UpdateAlignment(unsigned NewAlignment,
- unsigned UnpackedNewAlignment) {
+void RecordLayoutBuilder::UpdateAlignment(CharUnits NewAlignment,
+ CharUnits UnpackedNewAlignment) {
// The alignment is not modified when using 'mac68k' alignment.
if (IsMac68kAlign)
return;
- CharUnits NewAlignmentInChars = Context.toCharUnitsFromBits(NewAlignment);
- if (NewAlignmentInChars > Alignment) {
- assert(llvm::isPowerOf2_32(NewAlignment && "Alignment not a power of 2"));
- Alignment = NewAlignmentInChars;
+ if (NewAlignment > Alignment) {
+ assert(llvm::isPowerOf2_32(NewAlignment.getQuantity() &&
+ "Alignment not a power of 2"));
+ Alignment = NewAlignment;
}
- CharUnits UnpackedNewAlignmentInChars =
- Context.toCharUnitsFromBits(UnpackedNewAlignment);
- if (UnpackedNewAlignmentInChars > UnpackedAlignment) {
- assert(llvm::isPowerOf2_32(UnpackedNewAlignment &&
+ if (UnpackedNewAlignment > UnpackedAlignment) {
+ assert(llvm::isPowerOf2_32(UnpackedNewAlignment.getQuantity() &&
"Alignment not a power of 2"));
- UnpackedAlignment = UnpackedNewAlignmentInChars;
+ UnpackedAlignment = UnpackedNewAlignment;
}
}