[cfe-commits] r130106 - /cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
Ken Dyck
kd at kendyck.com
Sun Apr 24 09:40:29 PDT 2011
Author: kjdyck
Date: Sun Apr 24 11:40:29 2011
New Revision: 130106
URL: http://llvm.org/viewvc/llvm-project?rev=130106&view=rev
Log:
Eliminate literal 8s from LayoutBitField(), converting variables to
CharUnits or replacing the 8s with char align. No change in functionality
intended.
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=130106&r1=130105&r2=130106&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Sun Apr 24 11:40:29 2011
@@ -351,10 +351,12 @@
return;
uint64_t nextFieldOffsetInBits = Types.getContext().toBits(NextFieldOffset);
- unsigned numBytesToAppend;
+ CharUnits numBytesToAppend;
+ unsigned charAlign = Types.getContext().Target.getCharAlign();
if (fieldOffset < nextFieldOffsetInBits && !BitsAvailableInLastField) {
- assert(fieldOffset % 8 == 0 && "Field offset not aligned correctly");
+ assert(fieldOffset % charAlign == 0 &&
+ "Field offset not aligned correctly");
CharUnits fieldOffsetInCharUnits =
Types.getContext().toCharUnitsFromBits(fieldOffset);
@@ -369,27 +371,31 @@
assert(!NextFieldOffset.isZero() && "Must have laid out at least one byte");
// The bitfield begins in the previous bit-field.
- numBytesToAppend =
- llvm::RoundUpToAlignment(fieldSize - BitsAvailableInLastField, 8) / 8;
+ numBytesToAppend = Types.getContext().toCharUnitsFromBits(
+ llvm::RoundUpToAlignment(fieldSize - BitsAvailableInLastField,
+ charAlign));
} else {
- assert(fieldOffset % 8 == 0 && "Field offset not aligned correctly");
+ assert(fieldOffset % charAlign == 0 &&
+ "Field offset not aligned correctly");
// Append padding if necessary.
- AppendPadding(CharUnits::fromQuantity(fieldOffset / 8), CharUnits::One());
+ AppendPadding(Types.getContext().toCharUnitsFromBits(fieldOffset),
+ CharUnits::One());
- numBytesToAppend = llvm::RoundUpToAlignment(fieldSize, 8) / 8;
+ numBytesToAppend = Types.getContext().toCharUnitsFromBits(
+ llvm::RoundUpToAlignment(fieldSize, charAlign));
- assert(numBytesToAppend && "No bytes to append!");
+ assert(!numBytesToAppend.isZero() && "No bytes to append!");
}
// Add the bit field info.
BitFields.insert(std::make_pair(D,
CGBitFieldInfo::MakeInfo(Types, D, fieldOffset, fieldSize)));
- AppendBytes(CharUnits::fromQuantity(numBytesToAppend));
+ AppendBytes(numBytesToAppend);
BitsAvailableInLastField =
- NextFieldOffset.getQuantity() * 8 - (fieldOffset + fieldSize);
+ Types.getContext().toBits(NextFieldOffset) - (fieldOffset + fieldSize);
}
bool CGRecordLayoutBuilder::LayoutField(const FieldDecl *D,
More information about the cfe-commits
mailing list