[cfe-commits] r126542 - /cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
John McCall
rjmccall at apple.com
Sat Feb 26 00:41:59 PST 2011
Author: rjmccall
Date: Sat Feb 26 02:41:59 2011
New Revision: 126542
URL: http://llvm.org/viewvc/llvm-project?rev=126542&view=rev
Log:
A much-delayed response to Ken Dyck's review: make this somewhat more
char-width agnostic.
Modified:
cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=126542&r1=126541&r2=126542&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Sat Feb 26 02:41:59 2011
@@ -207,8 +207,9 @@
uint64_t ContainingTypeSizeInBits,
unsigned ContainingTypeAlign) {
const llvm::Type *Ty = Types.ConvertTypeForMemRecursive(FD->getType());
- uint64_t TypeSizeInBytes = Types.getTargetData().getTypeAllocSize(Ty);
- uint64_t TypeSizeInBits = TypeSizeInBytes * 8;
+ CharUnits TypeSizeInBytes =
+ CharUnits::fromQuantity(Types.getTargetData().getTypeAllocSize(Ty));
+ uint64_t TypeSizeInBits = Types.getContext().toBits(TypeSizeInBytes);
bool IsSigned = FD->getType()->isSignedIntegerType();
@@ -249,7 +250,7 @@
uint64_t AccessStart = FieldOffset - (FieldOffset % AccessWidth);
// Adjust initial access size to fit within record.
- while (AccessWidth > 8 &&
+ while (AccessWidth > Types.getTarget().getCharWidth() &&
AccessStart + AccessWidth > ContainingTypeSizeInBits) {
AccessWidth >>= 1;
AccessStart = FieldOffset - (FieldOffset % AccessWidth);
@@ -262,7 +263,8 @@
if (AccessStart + AccessWidth > ContainingTypeSizeInBits) {
// If so, reduce access size to the next smaller power-of-two and retry.
AccessWidth >>= 1;
- assert(AccessWidth >= 8 && "Cannot access under byte size!");
+ assert(AccessWidth >= Types.getTarget().getCharWidth()
+ && "Cannot access under byte size!");
continue;
}
@@ -329,7 +331,7 @@
if (fieldSize == 0)
return;
- uint64_t nextFieldOffsetInBits = NextFieldOffset.getQuantity() * 8;
+ uint64_t nextFieldOffsetInBits = Types.getContext().toBits(NextFieldOffset);
unsigned numBytesToAppend;
if (fieldOffset < nextFieldOffsetInBits) {
@@ -378,8 +380,10 @@
CheckZeroInitializable(D->getType());
- assert(fieldOffset % 8 == 0 && "FieldOffset is not on a byte boundary!");
- CharUnits fieldOffsetInBytes = CharUnits::fromQuantity(fieldOffset / 8);
+ assert(fieldOffset % Types.getTarget().getCharWidth() == 0
+ && "field offset is not on a byte boundary!");
+ CharUnits fieldOffsetInBytes
+ = Types.getContext().toCharUnitsFromBits(fieldOffset);
const llvm::Type *Ty = Types.ConvertTypeForMemRecursive(D->getType());
CharUnits typeAlignment = getTypeAlignment(Ty);
@@ -396,7 +400,7 @@
const RecordDecl *RD = cast<RecordDecl>(RT->getDecl());
if (const MaxFieldAlignmentAttr *MFAA =
RD->getAttr<MaxFieldAlignmentAttr>()) {
- if (MFAA->getAlignment() != typeAlignment.getQuantity() * 8)
+ if (MFAA->getAlignment() != Types.getContext().toBits(typeAlignment))
return false;
}
}
@@ -728,7 +732,8 @@
void CGRecordLayoutBuilder::AppendTailPadding(uint64_t RecordSize) {
assert(RecordSize % 8 == 0 && "Invalid record size!");
- CharUnits RecordSizeInBytes = CharUnits::fromQuantity(RecordSize / 8);
+ CharUnits RecordSizeInBytes =
+ Types.getContext().toCharUnitsFromBits(RecordSize);
assert(NextFieldOffset <= RecordSizeInBytes && "Size mismatch!");
CharUnits AlignedNextFieldOffset =
@@ -920,7 +925,8 @@
// Verify that every component access is within the structure.
uint64_t FieldOffset = SL->getElementOffsetInBits(AI.FieldIndex);
- uint64_t AccessBitOffset = FieldOffset + AI.FieldByteOffset * 8;
+ uint64_t AccessBitOffset = FieldOffset +
+ getContext().toBits(CharUnits::fromQuantity(AI.FieldByteOffset));
assert(AccessBitOffset + AI.AccessWidth <= TypeSizeInBits &&
"Invalid bit-field access (out of range)!");
}
More information about the cfe-commits
mailing list